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

Bug in tut_intro.ipynb when calling cv.MultiSim #399

Open
TristanFauvel opened this issue Jun 26, 2023 · 2 comments
Open

Bug in tut_intro.ipynb when calling cv.MultiSim #399

TristanFauvel opened this issue Jun 26, 2023 · 2 comments

Comments

@TristanFauvel
Copy link

Describe the bug

In the last cell of the tutorial tut_intro.ipynb , when running msim = cv.MultiSim([s1, s2]), I get the following error message:

BrokenProcessPool: A process in the process pool was terminated abruptly while the future was running or pending.

The full output is:

---------------------------------------------------------------------------
BrokenProcessPool                         Traceback (most recent call last)
Cell In[17], line 22
     20 s2 = cv.Sim(pars, interventions=protect_elderly, label='Protect the elderly')
     21 msim = cv.MultiSim([s1, s2])
---> 22 msim.run()
     23 fig = msim.plot(['cum_deaths', 'cum_infections'])

File c:\users\tfauvel\documents\covasim\covasim\run.py:172, in MultiSim.run(self, reduce, combine, **kwargs)
    170 # Run
    171 kwargs = sc.mergedicts(self.run_args, kwargs)
--> 172 self.sims = multi_run(sims, **kwargs)
    174 # Reduce or combine
    175 if reduce:

File c:\users\tfauvel\documents\covasim\covasim\run.py:1496, in multi_run(sim, n_runs, reseed, noise, noisepar, iterpars, combine, keep_people, run_args, sim_args, par_args, do_run, parallel, n_cpus, verbose, retry, **kwargs)
   1494         raise RuntimeError(errormsg) from E
   1495     else: # For all other runtime errors, raise the original exception
-> 1496         raise E
   1497 except pkl.PicklingError as E:
   1498     parallelizer = par_args.get('parallelizer')

File c:\users\tfauvel\documents\covasim\covasim\run.py:1477, in multi_run(sim, n_runs, reseed, noise, noisepar, iterpars, combine, keep_people, run_args, sim_args, par_args, do_run, parallel, n_cpus, verbose, retry, **kwargs)
   1475 kw = dict(iterkwargs=iterkwargs, kwargs=kwargs, **par_args)
   1476 try:
...
    392     finally:
    393         # Break a reference cycle with the exception in self._exception
    394         self = None

BrokenProcessPool: A process in the process pool was terminated abruptly while the future was running or pending.

Note that the following works fine:

s1 = cv.Sim(pars, label='Default')
s2 = cv.Sim(pars, interventions=protect_elderly, label='Protect the elderly')

Platform (please complete the following information):

  • Covasim version: 3.1.4
  • OS: Windows 10
  • Other platform information: using Anaconda Python
@cliffckerr
Copy link
Member

Hi @TristanFauvel , sorry you're encountering an issue! In general, on Windows, any calls to multiprocess need to happen within the __main__ block; see the answer here:
https://docs.idmod.org/projects/covasim/en/latest/faq.html#why-do-parallel-simulations-fail-on-windows-or-in-jupyter-notebooks

However, this doesn't usually happen from within a Jupyter notebook, so I'm surprised you encountered that here. While adding the __main__ block should fix it, it's possible that upgrading your Jupyter/IPython kernel might as well. Let us know if that works, and if not then we can investigate further and potentially update the FAQ.

@TristanFauvel
Copy link
Author

Hi @cliffckerr,
thanks for the quick reply, and for the great package. Actually when running the example in the FAQ I don't get an error, even when not using a __main__ block. By contrast, adding a __main__ block does not solve the issue in tut_intro.ipynb.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants