Skip to content

Commit

Permalink
Merge pull request #674 from StochSS/ode_solver_vol_issue
Browse files Browse the repository at this point in the history
Ode solver vol issue
  • Loading branch information
BryanRumsey authored Jan 11, 2022
2 parents 33153ae + 58fe061 commit cfa3de3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 2 additions & 0 deletions gillespy2/solvers/numpy/ode_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
22 changes: 21 additions & 1 deletion test/test_ode_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
"""

import unittest
import sys
sys.path.append("..")
import numpy as np
import gillespy2
from example_models import Example, ExampleNoTspan
Expand Down Expand Up @@ -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()

0 comments on commit cfa3de3

Please sign in to comment.