Skip to content

Commit

Permalink
replace end of simulation time end_time with time_max; revise Simulat…
Browse files Browse the repository at this point in the history
…ionConfig in sim_config.py: rename it WCSimulationConfig, and separate configuration information in DE-Sim and WC-Sim into two simulation config classes
  • Loading branch information
artgoldberg committed Mar 20, 2020
1 parent 80900b6 commit d77c286
Show file tree
Hide file tree
Showing 18 changed files with 310 additions and 334 deletions.
2 changes: 1 addition & 1 deletion examples/simulation_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

# create and run simulation
simulation = Simulation(model_filename)
num_events, results_dir = simulation.run(end_time=30, results_dir=results_dir, checkpoint_period=10)
num_events, results_dir = simulation.run(time_max=30, results_dir=results_dir, checkpoint_period=10)
run_results = RunResults(results_dir)

# view results
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
model_filename = 'model.xlsx'
results_parent_dirname = 'results'
checkpoint_period = 100.
end_time = 3600. * 8.
time_max = 3600. * 8.

# read model
model = wc_lang.io.Reader().run(model_filename)[wc_lang.Model][0]

# run simulation
sim = Simulation(model)
_, results_dirname = sim.run(end_time=end_time,
_, results_dirname = sim.run(time_max=time_max,
results_dir=results_parent_dirname,
checkpoint_period=checkpoint_period)
results = RunResults(results_dirname)
Expand Down
4 changes: 2 additions & 2 deletions examples/translation_metabolism_hybrid_model/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
model_filename = 'model.xlsx'
results_parent_dirname = 'results'
checkpoint_period = 100.
end_time = 3600. * 8.
time_max = 3600. * 8.

# read model
model = wc_lang.io.Reader().run(model_filename)[wc_lang.Model][0]

# run simulation
seed = 100
sim = Simulation(model)
_, results_dirname = sim.run(end_time=end_time,
_, results_dirname = sim.run(time_max=time_max,
seed=seed,
results_dir=results_parent_dirname,
checkpoint_period=checkpoint_period)
Expand Down
14 changes: 7 additions & 7 deletions tests/submodels/test_submodels.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,19 +206,19 @@ def test_skeleton_submodel(self):
for conc in self.model.distribution_init_concentrations:
conc.std = 0

end_time = 100
time_max = 100
skeleton_submodel = self.make_sim_w_skeleton_submodel(lang_submodel, behavior)
self.assertEqual(self.simulator.simulate(end_time),
end_time / behavior[SkeletonSubmodel.INTER_REACTION_TIME])
self.assertEqual(self.simulator.simulate(time_max),
time_max / behavior[SkeletonSubmodel.INTER_REACTION_TIME])

behavior = {SkeletonSubmodel.INTER_REACTION_TIME: 2,
SkeletonSubmodel.REACTION_TO_EXECUTE: 0} # reaction #0 makes one more 'species_1[c]'
skeleton_submodel = self.make_sim_w_skeleton_submodel(lang_submodel, behavior)
interval = 10
pop_before = skeleton_submodel.local_species_population.read_one(0, 'species_1[c]')
for end_time in range(interval, 5 * interval, interval):
self.simulator.simulate(end_time)
pop_after = skeleton_submodel.local_species_population.read_one(end_time, 'species_1[c]')
for time_max in range(interval, 5 * interval, interval):
self.simulator.simulate(time_max)
pop_after = skeleton_submodel.local_species_population.read_one(time_max, 'species_1[c]')
delta = pop_after - pop_before
self.assertEqual(delta, interval / behavior[SkeletonSubmodel.INTER_REACTION_TIME])
pop_before = pop_after
Expand Down Expand Up @@ -317,5 +317,5 @@ def test_simulate_deterministic_simulation_algorithm_submodel(self):
model = MakeModel.make_test_model('1 species, 1 reaction')
self.transform_model_for_dsa_simulation(model)
simulation = Simulation(model)
num_events, _ = simulation.run(end_time=100)
num_events, _ = simulation.run(time_max=100)
self.assertGreater(num_events, 0)
22 changes: 11 additions & 11 deletions tests/test_dynamic_mass.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,13 @@ def gen_model(self):

return model

def simulate(self, model, end_time=100.):
def simulate(self, model, time_max=100.):
# simulate
env = EnvironmentVarGuard()
env.set('CONFIG__DOT__wc_lang__DOT__validation__DOT__validate_element_charge_balance', '0')
with env:
simulation = Simulation(model)
_, results_dirname = simulation.run(end_time=end_time,
_, results_dirname = simulation.run(time_max=time_max,
ode_time_step=1.,
checkpoint_period=1.,
results_dir=self.tempdir)
Expand Down Expand Up @@ -216,7 +216,7 @@ def test_exponentially_increase_to_steady_state_count_with_constant_mass(self):
self.k_deg_dynamic.value = 2e-2

# simulate
time, pop_constant, pop_dynamic, comp_mass, comp_vol = self.simulate(self.model, end_time=200.)
time, pop_constant, pop_dynamic, comp_mass, comp_vol = self.simulate(self.model, time_max=200.)

# verify results
numpy.testing.assert_equal(pop_constant, numpy.full((201,),
Expand Down Expand Up @@ -247,7 +247,7 @@ def test_exponentially_increase_to_steady_state_count_and_mass(self):
self.k_deg_dynamic.value = 5e-2

# simulate
time, pop_constant, pop_dynamic, comp_mass, comp_vol = self.simulate(self.model, end_time=200.)
time, pop_constant, pop_dynamic, comp_mass, comp_vol = self.simulate(self.model, time_max=200.)

# verify results
numpy.testing.assert_equal(pop_constant, numpy.full((201,),
Expand Down Expand Up @@ -292,7 +292,7 @@ def test_exponentially_descend_to_steady_state_count_and_mass(self):
self.k_deg_dynamic.value = 5e-2

# simulate
time, pop_constant, pop_dynamic, comp_mass, comp_vol = self.simulate(self.model, end_time=200.)
time, pop_constant, pop_dynamic, comp_mass, comp_vol = self.simulate(self.model, time_max=200.)

# verify results
numpy.testing.assert_equal(pop_constant,
Expand Down Expand Up @@ -388,16 +388,16 @@ def test_exponentially_increase_to_steady_state_mass_and_descend_to_concentratio
std_spec_dynamic_ss_conc = std_spec_dynamic_ss_pop / (vol_ss * NA)

# simulate
end_time = 1000.
time, pop_constant, pop_dynamic, comp_mass, comp_vol = self.simulate(self.model, end_time=end_time)
time_max = 1000.
time, pop_constant, pop_dynamic, comp_mass, comp_vol = self.simulate(self.model, time_max=time_max)
conc_dynamic = pop_dynamic / comp_vol / NA

# verify results
numpy.testing.assert_equal(comp_mass[0], init_mass)
self.assertEqual(self.density.value, init_density)
# confirm that density remains constant
comp_density = comp_mass / comp_vol
numpy.testing.assert_allclose(list(comp_density.to_numpy()), [self.density.value]*int(end_time + 1))
numpy.testing.assert_allclose(list(comp_density.to_numpy()), [self.density.value]*int(time_max + 1))

fig, axes = pyplot.subplots(nrows=2, ncols=3)

Expand Down Expand Up @@ -434,7 +434,7 @@ def test_exponentially_increase_to_steady_state_mass_and_descend_to_concentratio
fig.savefig(filename)
pyplot.close(fig)

mid_point = (end_time / 2) + 1
mid_point = (time_max / 2) + 1
self.assertGreater(numpy.mean(comp_mass[mid_point:]), mass_ss - 3 * std_mass_ss)
self.assertLess(numpy.mean(comp_mass[mid_point:]), mass_ss + 3 * std_mass_ss)

Expand All @@ -446,7 +446,7 @@ def test_exponentially_increase_to_steady_state_mass_and_descend_to_concentratio
self.assertLess(numpy.mean(conc_dynamic[mid_point:]),
spec_dynamic_ss_conc + 3 * std_spec_dynamic_ss_conc)

third_quarter = int((3 * end_time / 4) + 1)
third_quarter = int((3 * time_max / 4) + 1)
self.assertGreater(numpy.mean(pop_dynamic[third_quarter:]),
spec_dynamic_ss_pop - 3 * std_spec_dynamic_ss_pop)
self.assertLess(numpy.mean(pop_dynamic[third_quarter:]),
Expand All @@ -465,7 +465,7 @@ def test(self):
model = wc_lang.io.Reader().run(model_filename)[wc_lang.Model][0]

simulation = Simulation(model)
_, results_dirname = simulation.run(end_time=8 * 3600,
_, results_dirname = simulation.run(time_max=8 * 3600,
ode_time_step=1.,
checkpoint_period=100.,
results_dir=self.tempdir)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_multialgorithm_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def setUp(self):
self.checkpoints_dir = tempfile.mkdtemp()
self.args = Namespace(
model_file=self.MODEL_FILENAME,
end_time=100,
time_max=100,
checkpoint_period=4,
checkpoints_dir=self.checkpoints_dir,
dfba_time_step=5
Expand Down
2 changes: 1 addition & 1 deletion tests/test_multialgorithm_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ def test_one_reaction_constant_species_pop(self):

# test dynamics
simulation = Simulation(model)
_, results_dir = simulation.run(end_time=20, **self.args)
_, results_dir = simulation.run(time_max=20, **self.args)


class TestRunSSASimulation(unittest.TestCase):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_run_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def setUpClass(cls):
cls.max_time = 30

with CaptureOutput(relay=False):
_, cls.results_dir_1_cmpt = simulation.run(end_time=cls.max_time,
_, cls.results_dir_1_cmpt = simulation.run(time_max=cls.max_time,
results_dir=tempfile.mkdtemp(dir=cls.temp_dir),
checkpoint_period=cls.checkpoint_period)

Expand All @@ -51,7 +51,7 @@ def setUpClass(cls):
comp_e.biological_type = comp_c.biological_type
simulation = Simulation(model)
with CaptureOutput(relay=False):
_, cls.results_dir_dyn_aggr = simulation.run(end_time=cls.max_time,
_, cls.results_dir_dyn_aggr = simulation.run(time_max=cls.max_time,
results_dir=tempfile.mkdtemp(dir=cls.temp_dir),
checkpoint_period=cls.checkpoint_period)

Expand Down
Loading

0 comments on commit d77c286

Please sign in to comment.