Open WilliamIX opened 4 years ago
One gotcha to watch out for -- I've found that using multiprocessing correctly usually requires OS-specific tweaks. Make sure any multiprocessing examples work on, at minimum, Windows 10 and some reasonable OSX.
@sclamons what tweaks do you know about for Mac OSX? I've only done this on Windows and Linux which function the same.
I have to do
if not multiprocessing.get_start_method() == "spawn":
multiprocessing.set_start_method('spawn')
or the new processes hang. The guard is there because if you try to set_start_method when the start method is already safe, multiprocessing throws an exception. This is a known bug in Linux, too.
Another problem, this one specific to IPython notebooks: IPython can't pass functions defined in a notebook to a function like Pool.map, for reasons I really don't understand. If you want to wrap your lineage simulation in anything more complex than the built-in bioscrape simulation methods, you have to write that function in a separate file and import it. I've used the following code to write a notebook-defined function simulate_single_lineage
into a temporary file and import it.
file.write(inspect.getsource(simulate_single_lineage))
try:
importlib.reload(tmp_func)
except:
import tmp_func```
To do a parameter sweet and to run many stochastic simulations and average the results to get a distribution.