Skip to content
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 process-based non-determinism in SparsePauliOp.to_matrix (backport #13439) #13440

Merged
merged 1 commit into from
Nov 14, 2024

Conversation

mergify[bot]
Copy link
Contributor

@mergify mergify bot commented Nov 14, 2024

Summary

The simplification step of the summed Pauli terms in SparsePauliOp.to_matrix had introduced a non-determinism via hash-map iteration. In practice, the base hash seed was set per initialisation of the extension module, then stayed the same. This is hard to detect from within tests, but caused unexpected numerical behaviour on different invocations of the same script.

Details and comments

This fixes the bug part of #13413, but doesn't address the feature request. It should be eligible for backport to either 1.3.0 or 1.3.1, depending on whether there's time to make 1.3.0.

Writing a test that would exercise this would be pretty complex, so I haven't done it. I can if we feel strongly about it - we'd likely embed a little script into a test and spawn some sys.executable instances to run it and check the outputs all matched bit-for-bit.


This is an automatic backport of pull request #13439 done by Mergify.

* Fix process-based non-determinism in `SparsePauliOp.to_matrix`

The simplification step of the summed Pauli terms in
`SparsePauliOp.to_matrix` had introduced a non-determinism via hash-map
iteration.  In practice, the base hash seed was set per initialisation
of the extension module, then stayed the same.  This is hard to detect
from within tests, but caused unexpected numerical behaviour on
different invocations of the same script.

* Use ahash::RandomState

---------

Co-authored-by: Kevin Hartman <[email protected]>
(cherry picked from commit 74b32c9)
@mergify mergify bot requested a review from a team as a code owner November 14, 2024 17:18
@qiskit-bot
Copy link
Collaborator

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:

  • @Qiskit/terra-core

@github-actions github-actions bot added the Changelog: Bugfix Include in the "Fixed" section of the changelog label Nov 14, 2024
@github-actions github-actions bot added this to the 1.3.0 milestone Nov 14, 2024
@coveralls
Copy link

Pull Request Test Coverage Report for Build 11842219577

Details

  • 5 of 5 (100.0%) changed or added relevant lines in 1 file are covered.
  • 8 unchanged lines in 4 files lost coverage.
  • Overall coverage increased (+0.02%) to 88.932%

Files with Coverage Reduction New Missed Lines %
crates/accelerate/src/two_qubit_decompose.rs 1 92.12%
crates/accelerate/src/unitary_synthesis.rs 1 92.2%
crates/qasm2/src/expr.rs 1 94.02%
crates/qasm2/src/lex.rs 5 92.48%
Totals Coverage Status
Change from base Build 11820794097: 0.02%
Covered Lines: 79066
Relevant Lines: 88906

💛 - Coveralls

@jakelishman jakelishman added this pull request to the merge queue Nov 14, 2024
Merged via the queue into stable/1.3 with commit 6d5a230 Nov 14, 2024
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: Bugfix Include in the "Fixed" section of the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants