DiODeProject / MuMoT

Multiscale Modelling Tool - mathematical modelling without the maths
https://mumot.readthedocs.io/
GNU General Public License v3.0
21 stars 4 forks source link

Incompat with Python 3.8: changing dictionary keys during iteration now results in a RuntimeError #379

Closed willfurnass closed 4 years ago

willfurnass commented 4 years ago

A change introduced in Python 3.8 (https://github.com/python/cpython/pull/12596) results in RuntimeErrors being generated if dictionary keys are changed during iteration.

This causes failures for us in views.py and possibly elsewhere.

This will need addressing as Python 3.6-3.8 are the currently-supported versions of Python.

A stack trace produced from a tox run:

$ tox
...
____________________________________________________________________________ docs/MuMoTuserManual.ipynb::Cell 19 _____________________________________________________________________________
Notebook cell execution failed
Cell 19: Cell execution caused an exception

Input:
bifurcation1 = model4.bifurcation('s','A-B', 
                                  initWidgets={'mu':[3, 1, 5, 0.5], 'Delta':[0, 0, 2, 0.1], 
                                               'initBifParam':[4.5, 4, 6, 0.1]},
                                 choose_xrange=[0, 5])

Traceback:

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-20-8ac2ee7146fa> in <module>
----> 1 bifurcation1 = model4.bifurcation('s','A-B', 
      2                                   initWidgets={'mu':[3, 1, 5, 0.5], 'Delta':[0, 0, 2, 0.1], 
      3                                                'initBifParam':[4.5, 4, 6, 0.1]},
      4                                  choose_xrange=[0, 5])

~/rse/code/mumot/mumot.git/.tox/py38/lib/python3.8/site-packages/mumot/models.py in bifurcation(self, bifurcationParameter, stateVariable1, stateVariable2, initWidgets, **kwargs)
   1402         #     showStateVars = [r'' + showStateVars[kk] for kk in range(len(showStateVars))]
   1403 
-> 1404         modelView = views.MuMoTbifurcationView(self, viewController, BfcParams, bifurcationParameter, stateVariable1, stateVariable2, **kwargs)
   1405         viewController._setView(modelView)
   1406 

~/rse/code/mumot/mumot.git/.tox/py38/lib/python3.8/site-packages/mumot/views.py in __init__(self, model, controller, BfcParams, bifurcationParameter, stateVarExpr1, stateVarExpr2, figure, params, **kwargs)
   2738 
   2739         if not self._silent:
-> 2740             self._plot_bifurcation()
   2741 
   2742     def _plot_bifurcation(self, _=None):

~/rse/code/mumot/mumot.git/.tox/py38/lib/python3.8/site-packages/mumot/views.py in _plot_bifurcation(self, _)
   2826 
   2827             for nn in range(len(initDictList)):
-> 2828                 for key in initDictList[nn]:
   2829                     Exception(f"{type(initDictList)}, {type(initDictList[nn])}, {nn}")
   2830                     old_key = key

RuntimeError: dictionary keys changed during iteration