Fix process-based non-determinism in SparsePauliOp.to_matrix
(backport #13439)
#13440
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.