-
Notifications
You must be signed in to change notification settings - Fork 18
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
Using multiprocessing->map on Lineage simulations produces duplicate simulations #32
Comments
Are you using the py_simulate... methods? there are many places we could reset the seed but I think inside one of those wrappers is best, with an optional keyword to not reset. Any thoughts? |
I haven't tried replicating this exactly, but I don't see it happening anymore when using |
I think the answer is to reseed the simulation as part of the multiprocessing function. I have not added any reseed functionality to any py_simulate_X functions. This seems like a reasonable addition - a keyword like seed = None. If None reseeds using numpy or can set to a specific seed. |
When a new process is spawned by multiprocessing's map function, Numpy's random number generator is copied exactly into all of the children, including its seed. A description of the problem here: numpy/numpy#9650
A suggested fix, here (https://stackoverflow.com/questions/24345637/why-doesnt-numpy-random-and-multiprocessing-play-nice) is to reset numpy's random number seed at the beginning of the simulation, using OS-generated random numbers. Something like
np.random.seed(int.from_bytes(os.urandom(4), byteorder='little'))
.The text was updated successfully, but these errors were encountered: