Skip to content

Use local RNG in MultiTensor tests - #1439

Open
fzlzjerry wants to merge 1 commit into
quantumlib:mainfrom
fzlzjerry:fix/1060-local-multitensor-rng
Open

Use local RNG in MultiTensor tests#1439
fzlzjerry wants to merge 1 commit into
quantumlib:mainfrom
fzlzjerry:fix/1060-local-multitensor-rng

Conversation

@fzlzjerry

Copy link
Copy Markdown

Summary

  • give every randomized MultiTensor test a fresh, deterministically seeded numpy.random.Generator
  • pass that generator into the tests explicitly and replace all 29 legacy global RNG calls in the module
  • keep the suite-wide seed in place for modules that have not yet been migrated

Rationale

This is an incremental part of #1060. It makes the ten randomized tests in _multitensor_test.py isolated and reproducible without changing random behavior elsewhere in the suite.

Validation

  • check/all --only-changed-files origin/main (2287 passed; formatting, Pylint, mypy, incremental coverage, ShellCheck, and notebook formatting all passed)
  • representability suite (44 passed)
  • MultiTensor tests with pytest-randomly seeds 1, 42, and 4294967295 (10 passed for each seed)
  • MultiTensor tests with legacy np.random.random patched to raise on use (10 passed)

Give each randomized MultiTensor test a fresh, reproducible NumPy Generator instead of consuming the legacy global random state. This is an incremental step toward removing the suite-wide seed without destabilizing unrelated tests.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the test suite in _multitensor_test.py to use a deterministic random number generator. It introduces a pytest fixture rng utilizing np.random.default_rng(0) and updates all test functions to use this fixture instead of calling np.random.random directly. There are no review comments to process, and I have no additional feedback to provide.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant