-
Notifications
You must be signed in to change notification settings - Fork 643
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
[Terms1] Add Prod.terms()
method
#5132
Conversation
Hello. You may have forgotten to update the changelog!
|
[sc-55894] |
…into prodterms
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #5132 +/- ##
==========================================
- Coverage 99.69% 99.68% -0.01%
==========================================
Files 394 394
Lines 36118 35860 -258
==========================================
- Hits 36007 35748 -259
- Misses 111 112 +1 ☔ View full report in Codecov by Sentry. |
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 good! I left a couple of comments, but mostly looking pretty approve-ready
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 good to me! Thanks Korbinian
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! Much appreciated to have this change :)
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #5132 +/- ##
==========================================
- Coverage 99.68% 99.67% -0.01%
==========================================
Files 394 394
Lines 36298 36040 -258
==========================================
- Hits 36183 35924 -259
- Misses 115 116 +1 ☔ View full report in Codecov by Sentry. |
Are there similar performance questions here as in #5133? |
Yep same same |
Builds on top of #5132 and adds a meaningul `Sum.terms()` method that returns a tuple of coefficients and ops to be at feature parity with `qml.Hamiltonian` - [x] Basic functionality - [x] Tests with Paulis - [x] Tests without Paulis - [x] Docs - [x] changelog - [x] handle empty pauli words --------- Co-authored-by: albi3ro <chrissie.c.l@gmail.com> Co-authored-by: Christina Lee <christina@xanadu.ai> Co-authored-by: Mudit Pandey <mudit.pandey@xanadu.ai>
…5164) Following #5132 and #5133, the overarching goal is to achieve feature parity with `qml.Hamiltonian`, which on the other hand is part of the overarching goal of activating new opmath by default. While for `qml.Hamiltonian` it made sense to access `coeffs` and `ops` directly, in `Sum` and `Prod` it requires some processing so it makes more sense (and costs less) to directly call the `terms()` method to obtain both. [sc-56284] [sc-53963] --------- Co-authored-by: albi3ro <chrissie.c.l@gmail.com> Co-authored-by: Christina Lee <christina@xanadu.ai>
The overall goal is to have
Sum.terms()
give meaningful results. This is necessary to achieve feature parity withqml.Hamiltonian
to be able to soon switch to new opmath be the default. We realized that a necessity forSum.terms()
to work properly we also need aProd.terms()
method that is compatible with that.In particular with this PR you can do:
You can think of it like this: When the operator has a
pauli_rep
its just taking all values as coeffs and all keys as operators. This PR additionally handles all cases where no pauli rep is available. In essence, it is doing the same steps assimplify
modulo some small differences (like not discerning cases of just one single term as that still yields[factor], [op]
).