Closed glassnotes closed 3 years ago
Thanks @glassnotes! This should be fixed in #1142, could you try running this code in that branch and see if it works?
It does! (My bad, searched issues but not PRs). Shall we close this then, or leave it open as a reminder / searchability?
Since this isn't fixed in master, best to keep it open :)
It might also be worth porting just the bugfix out of #1142 to a separate PR so that we can fix this now, without waiting for that PR to be complete.
Issue description
Expected behavior: Creating a Hamiltonian within the context of a QNode should not affect the outcome of the QNode as a whole. (Example use case when this might occur is when creating a Hamiltonian in a QNode based on the QNode input parameters and using it to perform something like
ApproxTimeEvolution
).Actual behavior: Terms in Hamiltonians created within a QNode are added to the queue and executed as operations.
Reproduces how often: Always
System information: (post the output of
import pennylane as qml; qml.about()
)Source code and tracebacks
Code to reproduce:
Running this gives:
You can see the expectation value is incorrect, and the Pauli X and Pauli Z from the Hamiltonian are tacked on to the beginning of the second circuit.