Bug in tut_intro.ipynb when calling cv.MultiSim
TristanFauvel opened this issue · 2 comments
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
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.
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
.