Proposal to endorse SPEC 7 - Seeding PRNGs

Hi everyone,

This is a proposal to endorse Scientific Python - SPEC 7 — Seeding Pseudo-Random Number Generation as the core project SciPy. The SPEC proposes a standardised API for seeding pseudo-random number generation, and sets out a deprecation strategy for how a project like SciPy could adopt the standardised API.

The SPEC was co-authored by three SciPy maintainers (@stefanv, @mdhaber, @tupui) and NumPy maintainer @seberg . @rkern and @rgommers were involved in the discussion on the PR for the SPEC document, and various other SciPy maintainers were involved in prior discussion on this SciPy issue.

Endorsing the SPEC means that:

a project considers the standardization and interpretation of the rng keyword, as well as avoiding use of global state and legacy bitstream generators, good ideas that are worth [being] implemented widely.

Perhaps crucially, endorsing the SPEC is not a commitment to adopting it:

A SPEC is recommended for wide-spread adoption once it is endorsed by two (or more) Core Projects. … Individual projects choose to adopt the SPEC according to their own decision-making processes. … Ecosystem projects are welcome to adopt a SPEC at any point in the process, however, it may make sense to wait until a SPEC is endorsed by several Core Projects to ensure that the SPEC has been vetted and is deemed stable enough for widespread adoption.

For example, @rgommers mentioned that he would like to see scikit-learn adopt the SPEC alongside us, to ensure that our adoption would help improve API uniformity.

Please share any thoughts / react accordingly if you are happy for us to endorse the SPEC!


A natural next step after the SPEC is recommended for adoption would be us adopting it. See @seberg’s draft PR API: Add `rng=` as suggested in SPEC 7 and use it for RatioUniforms by seberg · Pull Request #20899 · scipy/scipy · GitHub and the decorator @mdhaber wrote in the SPEC document. Specifically, to adopt the SPEC we would:

  • deprecate the use of random_state/seed arguments in favor of an rng argument in all functions where users need to control pseudo-random number generation,
  • use numpy.random.default_rng to validate the rng argument and instantiate a Generator, and
  • deprecate the use of numpy.random.seed to control the random state.

But this is a separate decision which can be made after we (/and other projects) have endorsed the SPEC.


We don’t have a formal process yet for how we should go about endorsing a SPEC as a project. If anybody objects to the decision being made via consensus on Discourse in the normal way (perhaps believing that there should be a vote or some other more formal process), please open a proposal for how you think this should work as a separate Discourse thread. If nobody does that, we should add a note to the core dev docs to state that SPEC endorsements are decided by the same process as new features, deprecations, etc.


Cheers,
Lucas

4 Likes

+1 from me. I think it’s well written.

I think a Discourse post is perfectly fine. This decision is less consequential that the actual adoption within SciPy, so there shouldn’t be a need for elaborate process here. For new projects/code I certainly think it’s a good idea to follow this SPEC (much better than everyone reinventing the wheel by themselves), so :+1: for endorsing it.

1 Like

All positive noises so far - I’ve opened SciPy endorsement of SPEC 7 by lucascolley · Pull Request #351 · scientific-python/specs · GitHub. Let’s leave it open for a week for the discussion to settle.

<another positive noise>