fixes #11393 sampled_expectation_value returning incorrect results for complex coefficients (gave 0.0 rather than 1j)#16443
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:
|
|
Fixes #11393 |
☑️ Command disallowed due to command restrictions in the Mergify configuration.Details
|
|
@Yosef-Bunick - Thank you for your contribution to Qiskit! |
|
@ShellyGarion |
If possible, you can add them by a git commit co-authored-by. |
31aa117 to
e23b663
Compare
@ShellyGarion |
|
it seems that there are formatting errors and tests failures. please check this. |
|
@ShellyGarion @ihincks changed to arr->np.real_if_close(arr) and I got All passing on tests localy |
sampled_expval_complex and sampled_expval_sparse_observable computed
the full Complex64 result but returned only Ok(.re). Complex coefficients
(e.g. SparsePauliOp with -1j) produced 0.0 instead of 1j.
- crates/accelerate: return Complex64, not f64 (2 functions)
- sampled_expval.py: return float | complex, updated docstring
- bit_array.py: dtype=complex128, removed misleading note
- test: 5 regression tests across both modules
- releasenotes: release note
Co-authored-by: zeb33n <zeb33n@users.noreply.github.com>
Fixes Qiskit#11393
969fc65 to
664ded1
Compare
6b8612c to
664ded1
Compare
Cryoris
left a comment
There was a problem hiding this comment.
I'm wondering if we want to expose a tolerance to cutoff the imaginary part, np.real_if_close does support this. We can leave this as a follow up though.
If the test concerns I left are addressed this LGTM.
…and ammended one test verify real comes back real, and complex comes back complex.
4c32409 to
90a12ed
Compare
changes to complex or float here, instead of waiting for the return Co-authored-by: Julien Gacon <gaconju@gmail.com>
shorten release notes Co-authored-by: Julien Gacon <gaconju@gmail.com>
@Cryoris fixed the docstrings that didn't match what was actually being tested, should be ready to push, passed the lint, black, and tests localy. |
reference for separate pull |
|
@Yosef-Bunick The PR title is getting out of hand, please just use a short descriptive title of what this is fixing. |
complex->complex-valued for clarity Co-authored-by: Julien Gacon <gaconju@gmail.com>
Updated the fix description for sampled expectation value functions to clarify the change in return types.
Update expectation_values method to always return float64 dtype. internal complex because gate blocks it anyway in ObservablesArray.coerce(observables)
09d4507 to
46335a6
Compare
|
Now, this pull only fixes sampled_expectation_value returning incorrect results for complex coefficients. |
fixes #11393
partially fixes #16443
Root cause: two Rust functions computed Complex64 but returned Ok(.re).
PR #11471 got half of it,
they got sampled_expval_complex (.re → Ok)
but missed the sampled_expval_sparse_observable (.re → Ok)
also changed the "bit_array.py dtype + note" and added a few tests
AI/LLM disclosure