Closed yitchen-tim closed 1 year ago
Turns out that when you supply the custom_decomps
argument to the device, tape.get_parameters()
and tape.trainable_params
become empty; interesting behavior from PennyLane.
So I can't find the correct branch to try this out with, but I can recommend a temporary user-fix:
@qml.qnode(dev_local, expansion_strategy="device")
def my_pl_circuit(a, b):
qml.RX(a, wires=0)
qml.IsingXX(b, wires=[0,1])
return [qml.expval(qml.PauliZ(i)) for i in range(2)]
This way the device expansion will happen earlier on when the parameters are still autograd.
The device expansion is probably wiping out any information we have about trainability. Normally this doesn't matter. If a gradient transform is using the trainability information, then the conversion to numpy and the device expansion happens after teh gradient transform is done with it. If a device gradient is using the trainability information, then device expansion happens before we hit the ml framework boundary, set the correct trainable parameters, and convert to numpy.
We can look into better fixes, but I'm not sure they would be particularly easy to figure out.
Thanks for the suggesion @albi3ro! As for the correct branch to try this out, you can just use main
!
I just ran the above code locally and got:
T : | 0 |1| 2 |3| Result Types |
q0 : -Rx(p_0)-C-Rx(p_1)-C-Expectation(Z)-
| |
q1 : ---------X---------X-Expectation(Z)-
T : | 0 |1| 2 |3| Result Types |
Unassigned parameters: [p_0, p_1].
What should I be seeing once this is fixed?
Hi @albi3ro , the one you have is the expected output. Looks like it's fixed with Pennylane v0.33. We can close this issue, if @speller26 you don't see other issue.
Perfect, looks like the problem's solved! Thanks @albi3ro!
Describe the bug pennylane circuits are un-parametrized if there the qnode has
custom_decomps
keyword argument.To reproduce
Expected behavior The underlying Braket circuit is a circuit parametrized by free parameters
a
andb
.Screenshots or logs The circuit is not parametrized. Even though
custom_decomps
only applies on the XX gate, the RX gate also loses parametrization and has the value of parametera
bound to it.If I remove the
custom_decomps
kwarg from qnode, the circuit become parametrized again.System information A description of your system. Please provide:
Additional context Add any other context about the problem here.