def test_file_with_directory_name_exists(self): with self.assertRaises(DirectoryError): temp = tempfile.NamedTemporaryFile() model = create_decay() solverSSAC = SSACSolver(model, temp.name) solverODEC = ODECSolver(model, temp.name) solverTAUC = TauLeapingCSolver(model, temp.name) solverHYBC = TauHybridCSolver(model, temp.name)
def old_check_cpp_support(self): try: model = create_decay() solver = SSACSolver(model=model) results = model.run(solver=solver, cpp_support=True) return True except Exception as e: from gillespy2.core import log log.warn('Unable to use C++ optimized SSA: {0}. The performance of ' \ 'this package can be significantly increased if you install/configure GCC on ' \ 'this machine.'.format(e)) return False
class TestVariableSolvers(unittest.TestCase): model = create_decay() solverSSAC = SSACSolver(model, variable=True) solverODEC = ODECSolver(model, variable=True) solverTAUC = TauLeapingCSolver(model, variable=True) solverHYBC = TauHybridCSolver(model, variable=True) solverlist = [solverSSAC, solverODEC, solverTAUC, solverHYBC] def test_create(self): model = create_decay() solverSSAC = SSACSolver(model) solverODEC = ODECSolver(model) solverTAUC = TauLeapingCSolver(model) solverHYBC = TauHybridCSolver(model) def test_file_with_directory_name_exists(self): with self.assertRaises(DirectoryError): temp = tempfile.NamedTemporaryFile() model = create_decay() solverSSAC = SSACSolver(model, temp.name) solverODEC = ODECSolver(model, temp.name) solverTAUC = TauLeapingCSolver(model, temp.name) solverHYBC = TauHybridCSolver(model, temp.name) def test_run_example_precompiled(self): for solver in self.solverlist: results = self.model.run(solver=solver) def test_change_species(self): initial_value = self.model.listOfSpecies['Sp'].initial_value for solver in self.solverlist: results = self.model.run(solver=solver, variables={'Sp': 3}) with self.subTest(msg='Test changed species simulation'): self.assertEqual(results['Sp'][0], 3) with self.subTest(msg='Test changed species model integrity'): self.assertEqual(self.model.listOfSpecies['Sp'].initial_value, initial_value) def test_change_parameter(self): initial_expression = self.model.listOfParameters['k1'].expression for solver in self.solverlist: results = self.model.run(solver=solver, variables={'k1': 0}) with self.subTest(msg='Test changed parameter simulation'): self.assertEqual(results['Sp'][-1], results['Sp'][0]) with self.subTest(msg='Test changed parameter model integrity'): self.assertEqual(self.model.listOfParameters['k1'].expression, initial_expression) def test_invalid_variable(self): with self.assertRaises(SimulationError): for solver in self.solverlist: results = self.model.run(solver=solver, variables={'foobar': 0})
def ssaSolver(model, data, run_timeout): ''' Run the model with the best GillesPy2 SSASolver. Attributes ---------- model : GillesPy2 Model Model to be run. data : dict Simulation settings to use for the run. run_timeout : int Number of seconds until the simulation times out. ''' solver = SSACSolver(model=model) seed = data['seed'] if (seed == -1): seed = None results = model.run(solver=solver, timeout=run_timeout, number_of_trajectories=data['realizations'], seed=seed) return results
def test_create(self): model = create_decay() solverSSAC = SSACSolver(model) solverODEC = ODECSolver(model) solverTAUC = TauLeapingCSolver(model) solverHYBC = TauHybridCSolver(model)
reactants={Y: 1}, products={}, rate=kd) # nonlinear Y term: rxn5 = gillespy2.Reaction( name='Y nonlin', reactants={Y: 1}, products={}, propensity_function='Y/(a0 + a1*(Y/vol)+a2*Y*Y/(vol*vol))') model.add_reaction([rxn1, rxn2, rxn3, rxn4, rxn5]) return model # Model simulation. # ............................................................................. if __name__ == '__main__': # A simulation in GillesPy2 is performed by first instantiating the model # to be simulated, and then invoking the "run" method on that object. # The results of the simulation are the output of "run". import time from gillespy2 import SSACSolver tic = time.time() for _ in range(10): tyson_model = create_tyson_2_state() solver = SSACSolver(model=tyson_model) trajectories = tyson_model.run(solver=solver) print((time.time() - tic) / 10)
def test_run_example_precompiled(self): model = Example() solver = SSACSolver(model) results = model.run(solver=solver)
def test_file_with_directory_name_exists(self): with self.assertRaises(DirectoryError): temp = tempfile.NamedTemporaryFile() model = Example() solver = SSACSolver(model, temp.name)
def test_create(self): model = Example() solver = SSACSolver(model)