-
Notifications
You must be signed in to change notification settings - Fork 61
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
Fix SymbolicHamiltonian.expectation
for different nqubits
#951
Conversation
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## master #951 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 49 49
Lines 6905 6906 +1
=========================================
+ Hits 6905 6906 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
☔ View full report in Codecov by Sentry. |
Co-authored-by: Sergi Ramos <[email protected]>
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 @stavros11 for adding the example. The tests are not passing because expectation_from_samples()
only works when the observable is diagonal in the z basis as you mentioned, and XXZ()
is not. I have pending to generalize this function #852 and I will do it at some point in August.
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. Just a few more comments. When adding the three CNOTs, you have to replace c
--> circuit
To use expectation_from_samples()
we have to add measurement gates because the expected value is calculated from frequencies.
Thanks for the fixes @AlejandroSopena. I had them locally in my computer but forgot to push. I hope it is okay now. |
Fixes #935. Specifically:
nqubits
attribute was added toSymbolicHamiltonian
as suggested in Wrong results usingSymbolicHamiltonian
#935 (comment). Note that the effect of this is still equivalent to padding, for exampleSymbolicHamiltonian(Z(0) * Z(1), nqubits=4)
is equivalent toSymbolicHamiltonian(Z(0) * Z(1) * I(2) * I(3))
.ValueError
is raised if there is a mismatch between the number of qubits in the state and the Hamiltonian in expectation value calculations.expectation_from_samples
was added (@AlejandroSopena let me know if that is okay).Checklist: