-
Notifications
You must be signed in to change notification settings - Fork 586
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
Add functions to support a sparse matrix observable #1398
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1398 +/- ##
=======================================
Coverage 98.23% 98.24%
=======================================
Files 160 160
Lines 11966 11991 +25
=======================================
+ Hits 11755 11780 +25
Misses 211 211
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.
Looks really good! It's crazy that some much work went into understanding how to speed up simulations, and in the end the change is so simple.
My main suggestions are to improve the documentation and to make the tests more compact when specifying the Hamiltonians
Co-authored-by: ixfoduap <40441298+ixfoduap@users.noreply.github.com>
Co-authored-by: Josh Izaac <josh146@gmail.com>
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 @soranjh! Main comment here is mostly about having qml.SparseHamiltonian
match qml.Hermitian
in behaviour when it comes to wires.
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.
Nice, thanks @soranjh! I think it's very ready for merging, I just noticed a few very small things to change.
Co-authored-by: Josh Izaac <josh146@gmail.com>
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.
Good to go from my side, but please address the remaining suggestions from @josh146
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 @soranjh! I'm happy to now approve this PR, however, I recommend updating the gradient test to test a case where the gradient is not zero. There have been cases in the past where our gradient tests have been using test circuits that were too trivial, leading to bug not being uncovered.
Thanks @josh146. The gradient test is updated for a hydrogen Hamiltonian. Have you observed the codefactor issue "Complex Code" before? I computed the cyclomatic complexity with radon and everything seems normal in pennylane/ops/qubit.py, specially in my additions. Not sure which part of the code raises that issu. |
@soranjh I have overridden the complex code warning :) |
Thanks Josh! |
Context:
This PR adds a new observable class for supporting sparse matrix objects and adds the functionality to compute the expectation value of the observable via direct matrix-vector multiplication.
Description of the Change:
The observable class
SparseHamiltonian
is added to theqml.ops.qubit
module and the new functionexpval
is created inqml.devices.default_qubit
.Benefits:
The computation of a Hamiltonian expectation value is faster and more memory-efficient with the new functionality.