[BUG] Derivatives of `qml.CommutingEvolution`
See original GitHub issueIn cleaning warnings from the test suite, I found this warning:
templates/test_subroutines/test_commuting_evolution.py::TestGradients::test_differentiable_hamiltonian
/Users/christina/Prog/pl/lib/python3.8/site-packages/autograd/tracer.py:14: UserWarning: Output seems independent of input.
warnings.warn("Output seems independent of input.")
The effect of CommutingEvolution on the state did not change with the time.
This problems seems to stem from commuting_evolution.py Line 160:
return qml.templates.ApproxTimeEvolution(hamiltonian, time_and_coeffs[1], 1).decomposition()
This line incorrectly indexes into time_and_coeffs to try and extract the time. It should instead use time_and_coeffs[0].
Upon fixing that bug, we now find that parameter shift no longer works for CommutingEvolution.
These two tests start to fail:
==================================================================================== short test summary info ====================================================================================
FAILED templates/test_subroutines/test_commuting_evolution.py::TestGradients::test_two_term_case - assert False
FAILED templates/test_subroutines/test_commuting_evolution.py::TestGradients::test_four_term_case - assert False
The tests that fail manually specify the frequencies. If the frequencies are specified, the operation sets its own grad_recipe. This grad_recipe gives incorrect results. I have yet to track down the problem with the grad_recipe property.
In summary, fixing the bug in the creation of the ApproxTimeEvolution operation allows finite difference derivatives and derivatives for operations without specified frequencies to work correctly. Since the finite-difference derivatives are now correct, we can see that the parameter-shift gradients never worked correctly.
Issue Analytics
- State:
- Created a year ago
- Comments:10 (9 by maintainers)

Top Related StackOverflow Question
In fact the evaluation of
qml.CommutingEvolutionis now incorrect. Running the example code in the comment at https://github.com/PennyLaneAI/pennylane/blob/master/pennylane/templates/subroutines/commuting_evolution.py#L103Gives
0.14550003instead.Oof, really nice find @albi3ro. Since
qml.CommutingEvolutionis really integral to QAOA workflows, I would say that this is a very high priority bug.