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

Add Multiprocessing example #28

Open
WilliamIX opened this issue Apr 28, 2020 · 3 comments
Open

Add Multiprocessing example #28

WilliamIX opened this issue Apr 28, 2020 · 3 comments
Assignees
Labels
Bioscrape Core Issues pertaining to core bioscrape functionality

Comments

@WilliamIX
Copy link
Collaborator

To do a parameter sweet and to run many stochastic simulations and average the results to get a distribution.

@WilliamIX WilliamIX added the Bioscrape Core Issues pertaining to core bioscrape functionality label Apr 28, 2020
@WilliamIX WilliamIX self-assigned this Apr 28, 2020
@sclamons
Copy link
Collaborator

sclamons commented Apr 3, 2021

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.

@WilliamIX
Copy link
Collaborator Author

@sclamons what tweaks do you know about for Mac OSX? I've only done this on Windows and Linux which function the same.

@sclamons
Copy link
Collaborator

sclamons commented Apr 3, 2021

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```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bioscrape Core Issues pertaining to core bioscrape functionality
Projects
None yet
Development

No branches or pull requests

2 participants