You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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
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 globalRandomState
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 legacyRandomState
rather than the more modern (and performant)Generator
.Adding an optional argument to functions which currently make calls to
numpy.random
corresponding to aRandomState
to be used in place ofnumpy.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 tonumpy.random
if this argument is not specified. Whilenumpy.random
does include aseed
function which allows setting a seed for the globalRandomState
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 toRandomState
.The text was updated successfully, but these errors were encountered: