From 2e4ecabf705049a37b1f47b8490ebb9eeddfe8df Mon Sep 17 00:00:00 2001 From: Alex Lubbock Date: Sun, 7 Oct 2018 13:57:14 -0500 Subject: [PATCH] Validate init kwargs to ScipyOdeSimulator Previously, unrecognised kwargs would be silently ignored. Now a ValueError is raised if they are not recognised. --- pysb/simulator/scipyode.py | 15 ++++++++++----- pysb/tests/test_simulator_scipy.py | 4 ++++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/pysb/simulator/scipyode.py b/pysb/simulator/scipyode.py index e4d29efe4..189da2d10 100644 --- a/pysb/simulator/scipyode.py +++ b/pysb/simulator/scipyode.py @@ -147,11 +147,16 @@ def __init__(self, model, tspan=None, initials=None, param_values=None, verbose=verbose, **kwargs) # We'll need to know if we're using the Jacobian when we get to run() - self._use_analytic_jacobian = kwargs.get('use_analytic_jacobian', + self._use_analytic_jacobian = kwargs.pop('use_analytic_jacobian', False) - self.cleanup = kwargs.get('cleanup', True) - integrator = kwargs.get('integrator', 'vode') - compiler_mode = kwargs.get('compiler', None) + self.cleanup = kwargs.pop('cleanup', True) + integrator = kwargs.pop('integrator', 'vode') + compiler_mode = kwargs.pop('compiler', None) + integrator_options = kwargs.pop('integrator_options', {}) + if kwargs: + raise ValueError('Unknown keyword argument(s): {}'.format( + ', '.join(kwargs.keys()) + )) # Generate the equations for the model pysb.bng.generate_equations(self._model, self.cleanup, self.verbose) @@ -339,7 +344,7 @@ def jacobian(t, y, p): options.update( self.default_integrator_options[integrator]) # default options - options.update(kwargs.get('integrator_options', {})) # overwrite + options.update(integrator_options) # overwrite # defaults self.opts = options diff --git a/pysb/tests/test_simulator_scipy.py b/pysb/tests/test_simulator_scipy.py index 73545a4e5..758a695f5 100644 --- a/pysb/tests/test_simulator_scipy.py +++ b/pysb/tests/test_simulator_scipy.py @@ -55,6 +55,10 @@ def test_vode_solver_run(self): simres = self.sim.run() assert simres._nsims == 1 + @raises(ValueError) + def test_invalid_init_kwarg(self): + ScipyOdeSimulator(self.model, tspan=self.time, spam='eggs') + def test_lsoda_solver_run(self): """Test lsoda.""" solver_lsoda = ScipyOdeSimulator(self.model, tspan=self.time,