Hi,
I’m trying to implement the QNGOptimizer in a QAOA circuit, but the following error arises when I start the optimization
QuantumFunctionError: Can't generate metric tensor, operation MultiRZ: 1 params, wires [0, 1]has no defined generator
The circuit I’m implementing has the following form
def circuit(params, **kwargs):
Initial_state(n_qubits)
qml.layer(qaoa_layer, p, params[0], params[1])
where Initial_state()
generates our initial state implementing the corresponding Hadamard gates, and qaoa_layer
is defined as
def qaoa_layer(gamma, alpha):
qaoa.cost_layer(gamma, cost_h)
qaoa.mixer_layer(alpha, mixer_h)
where cost_h
and mixer_h
come from
cost_h, mixer_h = qaoa.maxcut(G)
And I do the optimization as
opt = qml.QNGOptimizer(stepsize = 0.1)
steps = 50
params = 0.01*np.random.rand(2, p)
for i in range(steps):
params = opt.step(cost_function, params)
print("Objective after step {:5d}: {: .7f}".format(i + 1, cost_function(params))
I’ve tried with other optimization methods like Adam or vanilla gradient descent and the optimization works nicely (it might get stucked in a local minima, but no errors appear). However, I don’t know exactly what is going on in this case when calculating the metric tensor. I’ve tried in other similar QAOA circuits where I directly define a function that implements the gates instead of loading them through the qaoa
package, and the optimization works.
Thank you very much in advance!
P.D.: This is how I import the different packages
import pennylane as qml
from pennylane import qaoa