Repository navigation
Conversation
Every function that seeds NumPy, scikit-learn, pynndescent or the standard library takes `rng: SeedLike | RNGLike | None` instead of `random_state`, `seed` or `rng_key`. `SeedLike` and `RNGLike` are SPEC 7's public aliases and replace `RandomStateLike`. The defaults stay the same, so tools seeded by default remain seeded. The old names stay accepted as keyword aliases through `_transition_to_rng`, silently as in SPEC 7's first phase. Unlike the SPEC's reference decorator, it only renames and does not pass an explicit `rng` through `np.random.default_rng`. Integer seeds therefore keep their random streams: `f()`, `f(rng=<default>)` and `f(<old name>=<default>)` give the results of main, and the public methods that call each other by keyword (Augur, Distance, scCODA) keep their legacy semantics. Generators and other seeds go through `np.random.default_rng`, and `_int_seed` turns them into the integer that scikit-learn, pynndescent and JAX need. `None` at those sites now draws fresh entropy instead of following `np.random.seed`. Milo's `make_nhoods` and Augur's subsampling no longer call `random.seed`, which reseeded the global standard library generator; they sample from a local `random.Random` with the same seed and draw the same cells and features. Augur keeps `None` as "seed every subsample by its index", which matches R Augur, and a generator passed to `predict` now gives each subsample its own seed rather than one draw per joblib worker copy. Dialogue records `rng` instead of `random_state` in its params. Seeds that only reach JAX (`assign_mixture_model`, scGen's latent sampling) keep `seed`, since SPEC 7 covers NumPy random number generation. Functions with an unseeded generator and no seed argument (DistanceTest, Scgen.predict, the classifier distances, Mixscape's plot jitter) and constructor kwargs forwarded to scikit-learn or pynndescent are unchanged.
`_transition_to_rng` now behaves like SPEC 7's reference decorator and scanpy 1.13. An `rng` passed by keyword is normalized with `np.random.default_rng` and drawn from, so an integer gives a new random stream where it used to seed scikit-learn, pynndescent, JAX or the standard library directly. An omitted `rng`, the former keyword and a positional value keep their former meaning as a `_LegacySeed`, with the former default (0, 42, 1234, 2024, or None) passed to the decorator, so existing code and default calls reproduce main. Signatures show `rng=None`, and the docstrings name the seed an omitted `rng` falls back to. Legacy seeds pass through the public methods that call each other by keyword (Augur, Distance, scCODA) unchanged, so a chain stays on one path. At scikit-learn and pynndescent sites a legacy seed, `None` included, is passed as before, so `np.random.seed` keeps working until the former names are removed. Augur's omitted `rng` keeps seeding every subsample by its index like R Augur, while an explicit `rng` draws the subsamples, features, label permutations and folds from the generator. Milo's explicit `rng` samples neighbourhood vertices with `Generator.choice`. JAX seeds move to `rng` as well: `assign_mixture_model`, `Scgen.get_latent_representation` and `Scgen.get_decoded_expression` (former name `seed`), with keys drawn from the generator on the new path. Functions that drew from an unseeded generator take `rng=None`: `DistanceTest` and its `test_xy` and `test_precomputed`, `Scgen.predict`, the `classifier_proba` distance and `Mixscape.plot_perturbscore`. `KMeansSpace.compute` and `Mixscape.perturbation_signature` take `rng` too, with the `random_state` they forwarded to KMeans and NNDescent as the former name.
Zethson
added a commit
to scverse/pertpy-tutorials
that referenced
this pull request
Dec 4, 2026
Needs scverse/pertpy#1237 merged first, since the scCODA/tascCODA case study now seeds `run_nuts` with `rng` instead of `rng_key`. An explicit `rng=1234` draws from a NumPy generator, so re-executing the case study gives different MCMC samples than the stored outputs, while the Augur tutorial only drops `random_state=None`, which `predict` uses when `rng` is omitted.
Points at scverse/pertpy-tutorials#87, which seeds the scCODA/tascCODA case study with rng and drops the redundant random_state=None from the Augur tutorial.
The guide assignment mixture (2024), MLPClassifierSpace (42) and Dialogue (1234) now seed with 0 when rng is omitted, like every other seeded tool, so their default results change; the former keywords with an explicit value keep theirs. The docstrings drop the note on the omitted seed.
They exist only for the SPEC 7 deprecation period and go once the former names are removed, while _types keeps the public SeedLike and RNGLike aliases.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
LLM usage
Every pertpy function that draws random numbers takes an
rngargument following SPEC 7, replacingrandom_state,seedandrng_keyand adding it where draws were unseeded, including the JAX-based tools.As in scanpy 1.13, an explicit
rnggoes throughnp.random.default_rng, while an omittedrngand the former names keep their previous results.