Skip to content

Conversation

mdhaber
Copy link
Contributor

@mdhaber mdhaber commented Nov 23, 2024

Reference issue

Toward gh-21833

What does this implement/fix?

To prepare for the deprecation and removal of seed and its legacy behavior from stats.qmc classes., this allows for use of the new keyword rng alongside seed.

Additional information

Note that when the _transition_to_rng decorator receives an integer as the rng argument, it normalizes it using default_rng before passing it to the wrapped function. Also, if a QMCEngine is passed a np.random.default_rng directly, it doesn't use it; rather, it spawns a new RNG from it. Therefore, with the decorator in place, both of the following happen in sequence: the rng argument is always normalized, and a new Generator is spawned from it.

So as-written, if we want to preserve the stream of numbers when the _transition_to_rng decorator is removed, we would always need to normalize the argument rng argument with default_rng AND spawn a new Generator from that; we would not keep the current logic that "if the argument is an instance of Generator, spawn; otherwise, normalize".

There is no problem with this; it's just a bit peculiar. A motivated individual is welcome to adjust the current implementation after this PR merges if this is not the desired long-term behavior.

@mdhaber mdhaber added scipy.stats maintenance Items related to regular maintenance tasks labels Nov 23, 2024
@mdhaber mdhaber requested a review from tupui as a code owner November 23, 2024 19:18
@mdhaber mdhaber mentioned this pull request Nov 23, 2024
50 tasks
As part of the `SPEC-007 <https://scientific-python.org/specs/spec-0007/>`_
transition from use of `numpy.random.RandomState` to
`numpy.random.Generator`, this keyword was changed from `seed` to
`rng`. For an interim period, both keywords will continue to work, although
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the source of the lint failure. I'll fix it when we have a reviewer for this. Reviewer: mind if I dedent this whole docstring? The whole thing one level higher than necessary.

Copy link
Member

@tupui tupui left a comment

Choose a reason for hiding this comment

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

Thanks Matt, I am fine with the custom initialise if that helps. That's an implementation details which is easy to cleanup once we come back to remove all these.

Approving and will come back once green. Go ahead with the dedent.

@tupui tupui added this to the 1.15.0 milestone Nov 23, 2024
@lucascolley lucascolley merged commit 3b84b53 into scipy:main Nov 25, 2024
34 checks passed
@lucascolley
Copy link
Member

thanks both!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance Items related to regular maintenance tasks scipy.stats
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants