Skip to content

Use seeded np.random.default_rng() random number generator in tests - #662

Merged
adrn merged 4 commits into
mainfrom
tests/seed-rng
Oct 24, 2026
Merged

adrn merged 4 commits into
mainfrom
tests/seed-rng

Conversation

@adrn

@adrn adrn commented Oct 24, 2026 •

Copy link
Copy Markdown
Owner

Describe your changes

Many tests used np.random without seeding, or set the global seed. This brings the tests in line with modern numpy.random recommendations.

Checklist

  • Did you add tests?
  • Did you add documentation for your changes?
  • Did you reference any relevant issues?
  • Did you add a changelog entry? (see CHANGES.rst)
  • Are the CI tests passing?
  • Is the milestone set?

adrn and others added 3 commits October 24, 2026 14:29
The Cython DOP853 Lyapunov routines drew offset vectors from numpy's
global RNG, so callers (and tests) could not seed them.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Unseeded draws made tests nondeterministic; e.g. the chaotic forced
pendulum Lyapunov test occasionally fell below its threshold in CI.

- Replace legacy global np.random.* calls with local
  np.random.default_rng(42) generators.
- Pass seeded rng/random_state to lyapunov_max, fast_lyapunov_max, and
  mockstream DFs, which otherwise draw from fresh entropy.
- isotropic_w0 now takes an explicit RNG; TestActions passes
  RandomState(42) to keep the sample the Sanders reference is validated on.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
np.random.seed and RandomState are legacy APIs. All test randomness now
comes from np.random.default_rng:

- Add a seeded `rng` fixture in conftest.py and use it in test functions
  instead of constructing generators inline; remove identical local copies.
- setup_method/setup_class, helpers, and the Cython _coord test helpers
  (which can't take fixtures) use a local default_rng(42). This also seeds
  _test_cyl_to_car_roundtrip, whose seed was commented out.
- TestActions overrides rng with seed 5: the vendored Sanders reference
  code crashes (IndexError / leastsq size errors) on most other samples.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@adrn adrn added this to the v1.13 milestone Oct 24, 2026
random_state now goes through np.random.default_rng, so it defaults to a
Generator and also accepts an int seed. A legacy RandomState is still used
as-is but raises GalaDeprecationWarning.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@adrn
adrn merged commit 88fb11d into main Oct 24, 2026
27 checks passed
@adrn
adrn deleted the tests/seed-rng branch October 24, 2026 19:55
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