Remove global random seed used for testing

Open
#1,060 6 comments 0 reactions 0 assignees View on GitHub

@SripriyaDevarapalli is already working on this.

Since Oct 12, 2026.

  • #1458 by @SripriyaDevarapalli — open

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
52/100
Issue type
Refactor
Clarity
Mostly clear
Activity status
Active
Tech stack
numpy, python

Research direction

Start by reading the pytest configuration changed in PR #1056 and locate tests that rely on random numbers in their scenarios. Review how those tests seed and use randomness, then identify which need independent generators passed explicitly. Done means the global seed is removed and affected tests retain reliable, independent random state.

Written by the indexing model from the issue text.

Description

a: performance a: python e: experienced no QC knowledge needed

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.

Dominant language
Python
Stars
1.7k
Forks
438
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from quantumlib/OpenFermion

All issues in quantumlib/OpenFermion

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.