Could you point me in the right direction on how I could do that?
Regarding the suggestion of using
PauliRot, the idea would be just to swap out the lines
U = np.array([[m.cos(phi), m.sin(phi)], [-m.sin(phi), m.cos(phi)]]) qml.ControlledQubitUnitary(U, control_wires=range(num_con),
with something like
qml.MultiControlledX(wires=targ_wire, control_wires=range(num_con)) qml.RY(phi, wires=targ_wire) qml.MultiControlledX(wires=targ_wire, control_wires=range(num_con))
This approach may not be exactly what you have above, but is similar.
I make this suggestion because it seems like your issues involve trying to manually make a unitary and then using
qml.DiagonalQubitUnitary. Although this is something we’re improving on, it’s a use case that can quite often break differentiability. Instead, it’s better to use gates that have a well defined input parameter, such as
qml.Rot. Finding the derivatives with respect to parametrized gates is much more of an established use case in PennyLane.
Also, another piece of advice when debugging errors in your model is to try to break it down into the elementary nodes/layers and see if the gradient is accessible for each. For example, instead of training the whole
hybrid_model, it’s easier to focus on differentiating