-
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
Fix the calculation for identity operator's expectation value #13345
Conversation
Thank you for opening a new pull request. Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient. While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone. One or more of the following people are relevant to this code:
|
Pull Request Test Coverage Report for Build 11826979058Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
Thanks for opening a PR to fix this! Could you add a release note and a test, to verify it now works as expected? (See e.g. this PR for an example on how a bugfix PR should look like 🙂) |
Sure, I just added a release note and a test. |
@@ -1152,6 +1152,37 @@ def test_expval_pauli_qargs(self, qubits): | |||
expval = state.expectation_value(op, qubits) | |||
self.assertAlmostEqual(expval, target) | |||
|
|||
|
|||
def test_expval_identity(self): |
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.
It seems like you need to run the formatter here, you can do that e.g. by calling make black
(you might want to make sure the right version is installed before doing so, by running pip install -r requirements-dev.txt -c constraints.txt
before)
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.
Got it. Thanks for the instruction.
Co-authored-by: Julien Gacon <gaconju@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 for this fix!
* Fix the calculation for identity operator's expectation value * Add release note and test * reformatted `test_statevector.py` with black * Update releasenotes/notes/fix_identity_operator_9e2ec9770ac046a6.yaml Co-authored-by: Julien Gacon <gaconju@gmail.com> * add a docstring to pass the pylint test * Fix leading `.` --------- Co-authored-by: Julien Gacon <gaconju@gmail.com> (cherry picked from commit edad499)
#13436) * Fix the calculation for identity operator's expectation value * Add release note and test * reformatted `test_statevector.py` with black * Update releasenotes/notes/fix_identity_operator_9e2ec9770ac046a6.yaml Co-authored-by: Julien Gacon <gaconju@gmail.com> * add a docstring to pass the pylint test * Fix leading `.` --------- Co-authored-by: Julien Gacon <gaconju@gmail.com> (cherry picked from commit edad499) Co-authored-by: Jinghong Yang <66985891+yjh-bill@users.noreply.github.com>
Summary
Fix a bug in
qiskit.quantum_info
in the calculation of expectation value of the identity operator.Fixes #13029
Details and comments
Currently,
qiskit.quantum_info
yields incorrect results for the expectation value of an identity operator for a given state vector. It returns the norm of the state vector; however, it ought to return the square of the norm.Therefore, I am changing the following line
qiskit/qiskit/quantum_info/states/statevector.py
Lines 478 to 479 in 1be2c5a
to