OpenFermion icon indicating copy to clipboard operation
OpenFermion copied to clipboard

Remove global random seed used for testing

Open mhucka opened this issue 7 months ago • 0 comments

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.

mhucka avatar Jun 02 '25 22:06 mhucka