Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow specifying the random number generator state for reproducibility #8

Open
matt-graham opened this issue Oct 8, 2021 · 0 comments

Comments

@matt-graham
Copy link

Submitting as part of JOSS review openjournals/joss-reviews/issues/3651

Currently random variates are generated throughout the package by calls to the functions in numpy.random which uses a global RandomState instance which is automatically seeded with entropy from the local device. As the linked documentation notes this is discouraged both because it uses global state and uses the legacy RandomState rather than the more modern (and performant) Generator.

Adding an optional argument to functions which currently make calls to numpy.random corresponding to a RandomState to be used in place of numpy.random would make it simpler to ensure reproducibility of the outputs produced, for example when writing unit tests. Compatibility with the current interface could still be maintained by defaulting to numpy.random if this argument is not specified. While numpy.random does include a seed function which allows setting a seed for the global RandomState instance, even when fixing the seed the output from a function which uses this global state can differ from run to run if the other related code run before or afterwards which also uses the global state is changed.

Even better would be to use the updated Generator class however this would involve a bit more effort to update as the naming and interface of some methods has changed compared to RandomState.

@matt-graham matt-graham changed the title Allow using fixing the initial random number generator state for reproducibility Allow specifying the random number generator state for reproducibility Oct 8, 2021
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

No branches or pull requests

1 participant