-
Notifications
You must be signed in to change notification settings - Fork 575
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes a bug where the CV param-shift would error with more than one 2nd order observable #1197
Conversation
…r if attempting to compute the gradient of a QNode with more than one second-order observable.
grad = np.zeros_like(res) | ||
grad[transformed_obs_idx] = res |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The previous implementation assumed that res
was always a scalar. This is only the case if the QNode has only one observable.
Codecov Report
@@ Coverage Diff @@
## master #1197 +/- ##
=======================================
Coverage 98.12% 98.12%
=======================================
Files 145 145
Lines 10980 10980
=======================================
Hits 10774 10774
Misses 206 206
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @josh146!
Context:
The CV parameter-shift rule will raise an exception if attempting to differentiate a QNode with more than one second order observable. For example, running the following script:
gives the error:
Description of the Change:
Fixes the bug; the above example now prints
Benefits: Bug fixed.
Possible Drawbacks: n/a
Related GitHub Issues: https://discuss.pennylane.ai/t/typeerror-while-using-qml-gradientdescentoptimizer/956/3