From 6cc581ee7932970fd674db7f3d1721c7435c8c73 Mon Sep 17 00:00:00 2001 From: Alex Lubbock Date: Sun, 27 Mar 2016 13:09:58 -0500 Subject: [PATCH] Unit tests (closes #28) and standardize cupsoda `run` signature (fixes #26) Note that cupsoda unit tests are not run on travis due to lack of GPU/CUDA infrastructure. Developers should run the tests locally before committing to github. --- pysb/cupsoda.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/pysb/cupsoda.py b/pysb/cupsoda.py index 5e1e85ad9..85a22f4dc 100644 --- a/pysb/cupsoda.py +++ b/pysb/cupsoda.py @@ -235,7 +235,7 @@ def __init__(self, model, tspan=None, cleanup=True, verbose=False, # overwrite default integrator options self.options.update(integrator_options) - def run(self, param_values, y0, tspan=None, outdir=None, + def run(self, tspan=None, param_values=None, y0=None, outdir=None, prefix=None, **integrator_options): """Perform a set of integrations. @@ -274,6 +274,29 @@ def run(self, param_values, y0, tspan=None, outdir=None, """ start_time = time.time() + + if y0 is None and param_values is None: + warnings.warn("Neither 'y0' nor 'param_values' were supplied. " + "Running a single simulation with model defaults.") + + if y0 is None: + # Run simulation using same parameters, varying initial conditions + species_names = [str(s) for s in self.model.species] + y0 = np.zeros(len(species_names)) + for ic in self.model.initial_conditions: + y0[species_names.index(str(ic[0]))] = ic[1].value + y0 = np.repeat([y0], + 1 if param_values is None else + param_values.shape[0], + axis=0) + + if param_values is None: + # Run simulation using same initial conditions, varying parameters + param_values = np.repeat(np.array([[p.value for p in + self.model.parameters]]), + y0.shape[0], + axis=0) + # make sure tspan is defined somewhere if tspan is not None: self.tspan = tspan