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

Use a default_rng() instance instead of random.normal #33

Closed
andreas-wolf opened this issue May 9, 2021 · 2 comments · Fixed by #35
Closed

Use a default_rng() instance instead of random.normal #33

andreas-wolf opened this issue May 9, 2021 · 2 comments · Fixed by #35

Comments

@andreas-wolf
Copy link

Feature request:
wiener source is using np.random.normal and np.random.multivariate_normal.

Both need np.random.seed(SEED) to be set for tests or repeatable experiments.
random.seed is known to not work as expected in multithreaded environments (some test frameworks, REST-Implementations).
Numpy strongly recommends to use an instance of a random number generator instead:
https://numpy.org/doc/stable/reference/random/generated/numpy.random.normal.html?highlight=random%20normal#numpy.random.normal

I'd like to have the opportunity to pass a random generator as optional parameter to the class which is then used as random source.

@andreas-wolf
Copy link
Author

I forgot to mention (from the numpy docs):
By default, Generator uses bits provided by PCG64 which has better statistical properties than the legacy MT19937 used in RandomState.

So this feature request may affect numerical reproducibility with previous versions of the code. As a workaround one could pass the older MT19937 bit generator as rng (which is not recommended):

from numpy.random import Generator, MT19937
rng = Generator(MT19937(12345))

@m-cip
Copy link
Collaborator

m-cip commented May 19, 2021

Thanks for pointing this out, indeed an update to the new numpy BitGnerator/Generator framework is long overdue... Do expect to have it soon in the master branch, and as part of the next release in a couple of months

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

Successfully merging a pull request may close this issue.

2 participants