You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
PR #1056 modified the pytest configuration to set a global random number seed, to deal with flaky tests that failed sporadically because some numerical comparisons exceeded tolerances undpredictably. Setting a global seed is not good practice. The seeds for test scenarios should be revised:
Avoid global seeds. It's generally better to avoid setting a global seed for all tests. Global seeds can cause unexpected behavior when different parts of the code rely on random numbers.
Use numpy.random.default_rng. It's considered better to create a Generator instance with a seed at the beginning of each test or test suite. This ensures that each test has its own independent random state.
Pass Generator objects. Pass the Generator object around as an argument. This makes the random number generation explicit and avoids relying on global state.
I'll take the first incremental slice in _multitensor_test.py: replace its uses of the legacy np.random global state with a fresh, deterministically seeded numpy.random.Generator fixture passed into each randomized test. I'll leave the global fixture in place so unrelated modules are not destabilized, and run this module repeatedly with varied pytest-randomly seeds.
Hi @mhucka! I'm a student looking to contribute to OpenFermion for a class project. I'd love to take an incremental slice of this issue by updating one of the test files. Could I be assigned to work on a test file?
Hi! I've addressed this issue by removing the autouse test fixture that reset Python's and NumPy's global random seeds before every test.
The collection-time seeds have been retained to preserve deterministic test parameterization. I ran the RNG-related tests, with all 190 passing. The full test suite reported 2,223 passed, 66 skipped, and one failure related to the unsupported forkserver multiprocessing context on Windows with Python 3.14.
I've submitted the changes in PR #1458. I'd appreciate any feedback or suggestions for improvement. Thank you!
Activity
Remove global random seed used for testing.
matti-sarjala commentedon May 14, 2026
A safe way to split this might be to avoid removing the global seed in the first PR.
Possible incremental path:
numpy.random.default_rng(seed)instances.Generatorexplicitly where helper functions need randomness.This would reduce the risk of turning one global-seed cleanup into many unrelated flaky-test investigations.
A minimal first PR could target just one test file and follow the invariant:
“randomness used by a test should be local, explicit, and reproducible from the test itself.”
fzlzjerry commentedon Aug 12, 2026
I'll take the first incremental slice in
_multitensor_test.py: replace its uses of the legacynp.randomglobal state with a fresh, deterministically seedednumpy.random.Generatorfixture passed into each randomized test. I'll leave the global fixture in place so unrelated modules are not destabilized, and run this module repeatedly with variedpytest-randomlyseeds.Use local RNG in MultiTensor tests (quantumlib#1439)
dhanvanthbalaji commentedon Sep 29, 2026
Hi @mhucka! I'm a student looking to contribute to OpenFermion for a class project. I'd love to take an incremental slice of this issue by updating one of the test files. Could I be assigned to work on a test file?
SripriyaDevarapalli commentedon Oct 4, 2026
Hi! I've addressed this issue by removing the autouse test fixture that reset Python's and NumPy's global random seeds before every test.
The collection-time seeds have been retained to preserve deterministic test parameterization. I ran the RNG-related tests, with all 190 passing. The full test suite reported 2,223 passed, 66 skipped, and one failure related to the unsupported
forkservermultiprocessing context on Windows with Python 3.14.I've submitted the changes in PR #1458. I'd appreciate any feedback or suggestions for improvement. Thank you!
SripriyaDevarapalli commentedon Oct 12, 2026
@mhucka can you please review my work and assign me this issue to work on it .
Thank you !
SripriyaDevarapalli commentedon Oct 13, 2026
@mhucka hey is there any update on my PR #1458 review , can you please let me know .