diff --git a/gillespy2/solvers/numpy/ode_solver.py b/gillespy2/solvers/numpy/ode_solver.py index 61e53a528..acd5efc58 100644 --- a/gillespy2/solvers/numpy/ode_solver.py +++ b/gillespy2/solvers/numpy/ode_solver.py @@ -257,6 +257,8 @@ def __run(self, curr_state, curr_time, timeline, trajectory_base, tmpSpecies, li for p_name, param in self.model.listOfParameters.items(): curr_state[0][p_name] = param.value + if 'vol' not in curr_state[0]: + curr_state[0]['vol'] = 1.0 rhs = ode(ODESolver.__f).set_integrator(integrator, **integrator_options) rhs.set_initial_value(y0, curr_time[0]).set_f_params(curr_state, self.model, c_prop) diff --git a/test/test_ode_solver.py b/test/test_ode_solver.py index 1c04f93df..b99e2a61d 100644 --- a/test/test_ode_solver.py +++ b/test/test_ode_solver.py @@ -17,6 +17,8 @@ """ import unittest +import sys +sys.path.append("..") import numpy as np import gillespy2 from example_models import Example, ExampleNoTspan @@ -77,6 +79,24 @@ def test_run_example__with_tspan_and_increment(self): results = ODESolver.run(model=model, increment=0.2) + def test_stoch3(self): + class StochTestModel(gillespy2.Model): + def __init__(self, parameter_values=None): + gillespy2.Model.__init__(self, name='StochTest1') + A = gillespy2.Species(name='A', initial_value=10) + B = gillespy2.Species(name='B', initial_value=0) + self.add_species([A, B]) + k = gillespy2.Parameter(name='k', expression=10) + self.add_parameter([k]) + r = gillespy2.Reaction(name='r', reactants={A: 1}, products={B:1}, + propensity_function="k*A/vol") # testing if 'vol' is a pre-set variable + self.add_reaction([r]) + self.timespan(np.linspace(0, 100, 101)) + model = StochTestModel() + result = model.run(solver=ODESolver) + sys.stderr.write(f"\ntest_shoch3(): B={result['B'][-1]}\n\n") + self.assertGreater(result['B'][-1], 5) if __name__ == '__main__': - unittest.main() + #unittest.main() + TestBasicODESolver().test_stoch3()