-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Statevector._expectation_value_pauli returns incorrect result in certain cases #13029
Comments
Please can you show a reproducing code block following the bug report template, and the output you expected? |
Sure. Here it is from qiskit.quantum_info import Statevector, SparsePauliOp, Pauli
state_normed = Statevector.from_label("0")
state_not_normed = 2 * state_normed
identity_op = SparsePauliOp.from_list([("I", 1)])
# using the public interface (expectation_value)
print(state_not_normed.expectation_value(identity_op))
# using _expectation_value_pauli (the backend)
print(state_not_normed._expectation_value_pauli(Pauli('I'))) EnvironmentPython 3.11.6 Judging from the source code on github, the issue should be platform-independent and exists across different versions. What is the expected resultThe two print statement should give What is the actual resultThe two print statement gave |
Nice catch, that seems to be unique only to the Pauli-I operator. Would you like to open a PR to fix the issue? 🙂 |
Sure, I have created one PR. |
The calculation for the expectation value of the identity operator seems incorrect when the statevector is not normalized to 1.
I think the reason is that one should use the norm squared rather than the norm in the following lines.
qiskit/qiskit/quantum_info/states/statevector.py
Lines 478 to 479 in 1be2c5a
The whole function is attached below to provide context.
qiskit/qiskit/quantum_info/states/statevector.py
Lines 458 to 491 in 1be2c5a
The text was updated successfully, but these errors were encountered: