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

Using multiprocessing->map on Lineage simulations produces duplicate simulations #32

Open
sclamons opened this issue May 22, 2020 · 3 comments
Labels
bug Something isn't working Lineages Issues pertaining to bioscrape lineages

Comments

@sclamons
Copy link
Collaborator

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')).

@sclamons sclamons added bug Something isn't working Lineages Issues pertaining to bioscrape lineages labels May 22, 2020
@WilliamIX
Copy link
Collaborator

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?

@sclamons
Copy link
Collaborator Author

sclamons commented Apr 3, 2021

I haven't tried replicating this exactly, but I don't see it happening anymore when using py_SingleCellLineage with multiprocessing.Pool.map. Did someone fix this? Or is it specific to certain map functions or certain lineage simulation functions?

@WilliamIX
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Lineages Issues pertaining to bioscrape lineages
Projects
None yet
Development

No branches or pull requests

2 participants