Skip to content

Commit

Permalink
make merging of algorithmically-like submodels optional and keep scal…
Browse files Browse the repository at this point in the history
…ing performance test working
  • Loading branch information
artgoldberg committed Jan 4, 2021
1 parent 428c8be commit c1d2fce
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 8 deletions.
12 changes: 12 additions & 0 deletions tests/perf_results/wc_sim_performance_log.txt
Original file line number Diff line number Diff line change
Expand Up @@ -346,3 +346,15 @@ Performance summary for Next Reaction Method on 2020-12-02:
8 2681 7.780 344.611
32 10538 33.464 314.910

Performance summary for Stochastic Simulation Algorithm on 2021-01-03:
# SSA submodels # events run time (s) reactions/s
2 641 1.482 432.595
8 2722 6.109 445.578
32 10930 26.547 411.725

Performance summary for Next Reaction Method on 2021-01-03:
# NRM submodels # events run time (s) reactions/s
2 744 1.336 556.855
8 2918 4.775 611.161
32 10501 19.984 525.481

17 changes: 11 additions & 6 deletions tests/test_multialgorithm_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,8 @@ class TestRunSSASimulation(unittest.TestCase):

def setUp(self):
self.results_dir = tempfile.mkdtemp()
de_simulation_config = SimulationConfig(max_time=10, output_dir=self.results_dir)
self.wc_sim_config = WCSimulationConfig(de_simulation_config, dfba_time_step=1, checkpoint_period=10)
self.de_simulation_config = SimulationConfig(max_time=10, output_dir=self.results_dir)
self.wc_sim_config = WCSimulationConfig(self.de_simulation_config, dfba_time_step=1, checkpoint_period=10)
self.out_dir = tempfile.mkdtemp()

def tearDown(self):
Expand All @@ -405,17 +405,20 @@ def tearDown(self):

def make_model_and_simulation(self, model_type, num_submodels, species_copy_numbers=None,
species_stds=None, init_vols=None,
submodel_framework='WC:stochastic_simulation_algorithm'):
submodel_framework='WC:stochastic_simulation_algorithm',
wc_sim_config=None):
# make simple model
if init_vols is not None:
if not isinstance(init_vols, list):
init_vols = [init_vols]*num_submodels
if wc_sim_config is None:
wc_sim_config = self.wc_sim_config
model = MakeModel.make_test_model(model_type, num_submodels=num_submodels,
species_copy_numbers=species_copy_numbers,
species_stds=species_stds,
init_vols=init_vols,
submodel_framework=submodel_framework)
multialgorithm_simulation = MultialgorithmSimulation(model, self.wc_sim_config)
multialgorithm_simulation = MultialgorithmSimulation(model, wc_sim_config)
simulator, _ = multialgorithm_simulation.build_simulation()
return (model, multialgorithm_simulation, simulator)

Expand Down Expand Up @@ -540,16 +543,18 @@ def test_run_multiple_ssa_submodels(self):
init_vols=1E-22)

def prep_simulation(self, num_ssa_submodels, submodel_framework='WC:stochastic_simulation_algorithm'):
wc_sim_config = WCSimulationConfig(self.de_simulation_config, dfba_time_step=1, checkpoint_period=10,
merge_like_submodels=False)
model, multialgorithm_simulation, simulator = self.make_model_and_simulation(
'2 species, a pair of symmetrical reactions, and rates given by reactant population',
num_ssa_submodels,
init_vols=1E-18,
submodel_framework=submodel_framework)
submodel_framework=submodel_framework,
wc_sim_config=wc_sim_config)
local_species_pop = multialgorithm_simulation.local_species_population
simulator.initialize()
return simulator

# @unittest.skip("performance scaling test; runs slowly")
def test_performance(self):
end_sim_time = 100
min_num_ssa_submodels = 2
Expand Down
3 changes: 2 additions & 1 deletion wc_sim/multialgorithm_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ def prepare(self):
# execute PrepForWcSimTransform on the model only once
if not hasattr(self.model, '_transformed') or not self.model._transformed:
PrepForWcSimTransform().run(self.model)
MergeAlgorithmicallyLikeSubmodelsTransform().run(self.model)
if self.wc_sim_config.merge_like_submodels:
MergeAlgorithmicallyLikeSubmodelsTransform().run(self.model)
self.model._transformed = True
errors = Validator().run(self.model)
if errors:
Expand Down
7 changes: 6 additions & 1 deletion wc_sim/sim_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class WCSimulationConfig(EnhancedDataClass):
- Checkpoint period
- Submodels to skip
- Whether to produce verbose output
- Whether to merge algorithmically-like submodels into individual submodels
- Model changes: Instructions to change parameter values and add or remove model
components. These instructions are executed before the initial conditions are
calculated
Expand All @@ -52,6 +53,8 @@ class WCSimulationConfig(EnhancedDataClass):
submodels_to_skip (:obj:`list` of :obj:`str`, optional): submodels that should not be run,
identified by their ids
verbose (:obj:`bool`, optional): whether to produce verbose output
merge_like_submodels (:obj:`bool`, optional): whether to merge algorithmically-like submodels
into individual submodels
changes (:obj:`list`, optional): list of desired model changes (e.g. modified parameter values,
additional species/reactions, removed species/reactions)
perturbations (:obj:`list`, optional): list of desired simulated perturbations (e.g. set state
Expand All @@ -65,6 +68,7 @@ class WCSimulationConfig(EnhancedDataClass):
checkpoint_period: float = None
submodels_to_skip: list = None
verbose: bool = False
merge_like_submodels: bool = True
changes: list = None
perturbations: list = None

Expand Down Expand Up @@ -199,7 +203,8 @@ def semantically_equal(self, other):
self.ode_time_step == other.ode_time_step and \
self.dfba_time_step == other.dfba_time_step and \
self.checkpoint_period == other.checkpoint_period and \
self.submodels_to_skip == other.submodels_to_skip
self.submodels_to_skip == other.submodels_to_skip and \
self.merge_like_submodels == other.merge_like_submodels


Change = wc_lang.transform.ChangeValueTransform
Expand Down

0 comments on commit c1d2fce

Please sign in to comment.