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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion crates/accelerate/src/sparse_pauli_op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
// copyright notice, and modified files need to carry a notice indicating
// that they have been altered from the originals.

use ahash::RandomState;
use pyo3::exceptions::{PyRuntimeError, PyValueError};
use pyo3::prelude::*;
use pyo3::types::PyTuple;
Expand All @@ -20,6 +21,7 @@ use numpy::prelude::*;
use numpy::{PyArray1, PyArray2, PyReadonlyArray1, PyReadonlyArray2, PyUntypedArrayMethods};

use hashbrown::HashMap;
use indexmap::IndexMap;
use ndarray::{s, ArrayView1, ArrayView2, Axis};
use num_complex::Complex64;
use num_traits::Zero;
Expand Down Expand Up @@ -298,7 +300,11 @@ impl MatrixCompressedPaulis {
/// explicitly stored operations, if there are duplicates. After the summation, any terms that
/// have become zero are dropped.
pub fn combine(&mut self) {
let mut hash_table = HashMap::<(u64, u64), Complex64>::with_capacity(self.coeffs.len());
let mut hash_table =
IndexMap::<(u64, u64), Complex64, RandomState>::with_capacity_and_hasher(
self.coeffs.len(),
RandomState::new(),
);
for (key, coeff) in self
.x_like
.drain(..)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
fixes:
- |
Fixed a per-process based non-determinism in `SparsePauliOp.to_matrix`. The exact order of the
floating-point operations in the summation would previously vary per process, but will now be
identical between different invocations of the same script. See `#13413 <https://github.com/Qiskit/qiskit/issues/13413>`__.