@a.rozgonyi96 I think I found a workaround to the problem
If you use a for
loop you could iterate over the number of Trotter steps that you want.
I’m not sure if there’s any nuance or practical reason not to do this, but for now it looks like it works!
Make sure to check the output against something you know, just to verify that it’s correct.
import pennylane as qml
from pennylane import numpy as pnp
dev = qml.device("default.qubit", wires=3)
# Parameter values
theta = pnp.array([pnp.pi / 4], requires_grad=True)
@qml.qnode(dev)
def circuit(theta):
"""
Quantum circuit to encode Theta by a time evolution according to a Hamiltonian.
"""
# Construct Hamiltonian
coeffs = [1, 1]
obs = [qml.X(0), qml.X(1)]
H_Z = qml.Hamiltonian(coeffs, obs)
# Encoding dynamics
n = 2 # number of Trotter steps
for _ in range(n):
qml.ApproxTimeEvolution(H_Z, theta, 1)
# Return an expval
return qml.expval(qml.PauliZ(0))
print(circuit(theta))
QFIM = 4*qml.gradients.metric_tensor(circuit)(theta)
print(QFIM)
I hope this helps!
Let me know if it works for you too.
I’ve still opened issue 7717 to report the problem.