From 1b5971d12469cde5394f610c854ffb2f92181a3a Mon Sep 17 00:00:00 2001 From: Ciaran Ryan-Anderson Date: Fri, 7 Aug 2026 00:22:44 -0600 Subject: [PATCH 1/2] Seed the simulator RNG in test_multiple_shots to make it deterministic --- exp/pecos-neo/src/lib.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/exp/pecos-neo/src/lib.rs b/exp/pecos-neo/src/lib.rs index 085555c22..9d6f8aeea 100644 --- a/exp/pecos-neo/src/lib.rs +++ b/exp/pecos-neo/src/lib.rs @@ -333,7 +333,9 @@ mod tests { fn test_prelude_usage() { let commands = CommandBuilder::new().pz(&[0]).h(&[0]).mz(&[0]).build(); - let mut state = SparseStab::new(1); + // Measurement outcomes draw from the simulator's RNG, so the simulator + // must be seeded for determinism; the runner seed does not govern them. + let mut state = SparseStab::with_seed(1, 42); let mut runner = CircuitRunner::::new().with_seed(42); let outcomes = runner.apply_circuit(&mut state, &commands).unwrap(); @@ -400,7 +402,9 @@ mod tests { fn test_multiple_shots() { let commands = CommandBuilder::new().pz(&[0]).h(&[0]).mz(&[0]).build(); - let mut state = SparseStab::new(1); + // Measurement outcomes draw from the simulator's RNG, so the simulator + // must be seeded for determinism; the runner seed does not govern them. + let mut state = SparseStab::with_seed(1, 42); let mut runner = CircuitRunner::::new().with_seed(42); let mut count_0 = 0; From bdf47c6dd82936807524a658b5d031647b2b25cf Mon Sep 17 00:00:00 2001 From: Ciaran Ryan-Anderson Date: Fri, 7 Aug 2026 00:25:08 -0600 Subject: [PATCH 2/2] Correct the noiseless doc example and with_seed docs that invited the misuse --- exp/pecos-neo/src/lib.rs | 8 +++++--- exp/pecos-neo/src/runner.rs | 4 ++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/exp/pecos-neo/src/lib.rs b/exp/pecos-neo/src/lib.rs index 9d6f8aeea..f3089ed34 100644 --- a/exp/pecos-neo/src/lib.rs +++ b/exp/pecos-neo/src/lib.rs @@ -83,9 +83,11 @@ //! .mz(&[1]) //! .build(); //! -//! // Run without noise -//! let mut state = SparseStab::new(2); -//! let mut runner = CircuitRunner::::new().with_seed(42); +//! // Run without noise. Measurement randomness comes from the simulator's +//! // RNG, so seed the simulator for reproducible outcomes; the runner seed +//! // only governs noise sampling. +//! let mut state = SparseStab::with_seed(2, 42); +//! let mut runner = CircuitRunner::::new(); //! let outcomes = runner.apply_circuit(&mut state, &commands).unwrap(); //! //! // Outcomes are correlated (Bell state) diff --git a/exp/pecos-neo/src/runner.rs b/exp/pecos-neo/src/runner.rs index e16b73b30..a583131c6 100644 --- a/exp/pecos-neo/src/runner.rs +++ b/exp/pecos-neo/src/runner.rs @@ -802,6 +802,10 @@ impl CircuitRunner { } /// Set the RNG seed for noise operations. + /// + /// This does not affect measurement randomness, which comes from the + /// simulator's own RNG (e.g. `SparseStab::with_seed`); use + /// `set_full_seed` on a program for whole-run determinism. #[must_use] pub fn with_seed(mut self, seed: u64) -> Self { self.rng = PecosRng::seed_from_u64(seed);