-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
BUG: bit generator spawns different child generators despite having the same random state #27882
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
Comments
Spawning is covered here. Please note that the state that is spawned is the We can still talk about solving your problem, but we'd need more details, and the Discourse forum would probably be a better venue. In short, my advice would probably be to avoid resetting the states of |
Okay, I see. I have to admit, that I was not aware of how the I thought it must be a bug since the state should be the only important datum to determine the behavior of a About my use case, I have a main script that is starting several independent jobs on a server. Each of those jobs is running processes in parallel. Since the jobs are running independently on different machines, I needed a way to save and load the random generators to a file. Also, I want to be able to reproduce any of the jobs without rerunning the entire script. I was switching from generating a list of seeds to pass down to spawning child rngs, and thought if I pass along the initial state, it would amount to the same. But apparently, it's the |
Spawning I suspect what led you down the wrong path was trying to manually reach into the PRNG state and saving that instead of using |
Yes, I suppose using |
Uh oh!
There was an error while loading. Please reload this page.
Describe the issue:
When using the
default_rng
to spawn child rngs, the random states of the children are different, even if I reset the state of the parent generator.If the random states are the same, all the generators' functions should produce the same result given the same input. I think this should include spawning children.
Reproduce the code example:
Error message:
No response
Python and NumPy Versions:
Python 3.12.7
numpy 1.26.4
Also in numpy 2.1.3
Runtime Environment:
No response
Context for the issue:
I am not completely sure if this is a bug or intentional behavior, but it is confusing at least. I could not find any explanation of this behavior in the documentation and it seems counterintuitive.
If the seed is set for the first rng, it still produces different child states, but they are always the same.
I was trying to spawn child and grandchild rngs to be able to reproduce only parts of my simulation without having to rerun everything. But when I tried to recreate it from a child rng, I got different results. If I set the seed in the beginning, I can still recreate the whole simulation and I could create a list of new seeds instead of spawning children, but I would prefer not to do it that way.
The text was updated successfully, but these errors were encountered: