def test_prepare_skipped_submodels(self): multialgorithm_simulation = MultialgorithmSimulation(self.model, self.wc_sim_config) self.assertEqual(multialgorithm_simulation.skipped_submodels(), set()) submodels_to_skip = ['submodel_1'] self.wc_sim_config.submodels_to_skip = submodels_to_skip multialgorithm_simulation = MultialgorithmSimulation(self.model, self.wc_sim_config) self.assertEqual(multialgorithm_simulation.skipped_submodels(), set(submodels_to_skip)) submodels_to_skip = ['no_such_submodel'] self.wc_sim_config.submodels_to_skip = submodels_to_skip with self.assertRaisesRegex(MultialgorithmError, "'submodels_to_skip' contains submodels that aren't in the model:"): MultialgorithmSimulation(self.model, self.wc_sim_config)
def test_build_simulation(self): de_simulation_config = SimulationConfig(time_max=10, output_dir=self.results_dir) wc_sim_config = WCSimulationConfig(de_simulation_config, dfba_time_step=1, checkpoint_period=10) multialgorithm_simulation = MultialgorithmSimulation(self.model, wc_sim_config) simulation_engine, _ = multialgorithm_simulation.build_simulation() # 3 objects: 2 submodels, and the checkpointing obj: expected_sim_objs = set(['CHECKPOINTING_SIM_OBJ', 'submodel_1', 'submodel_2']) self.assertEqual(expected_sim_objs, set(list(simulation_engine.simulation_objects))) self.assertEqual(type(multialgorithm_simulation.checkpointing_sim_obj), MultialgorithmicCheckpointingSimObj) self.assertEqual(multialgorithm_simulation.dynamic_model.get_num_submodels(), 2) # check that submodels receive options dfba_options = dict(dfba='fast but inaccurate') ssa_options = dict(ssa='accurate but slow') options = {'DfbaSubmodel': dict(options=dfba_options), 'SsaSubmodel': dict(options=ssa_options) } multialgorithm_simulation = MultialgorithmSimulation(self.model, wc_sim_config, options) multialgorithm_simulation.build_simulation() dfba_submodel = multialgorithm_simulation.dynamic_model.dynamic_submodels['submodel_1'] ssa_submodel = multialgorithm_simulation.dynamic_model.dynamic_submodels['submodel_2'] self.assertEqual(dfba_submodel.options, dfba_options) self.assertEqual(ssa_submodel.options, ssa_options) # test skipped submodel submodels_to_skip = ['submodel_2'] self.wc_sim_config.submodels_to_skip = submodels_to_skip ma_sim = MultialgorithmSimulation(self.model, self.wc_sim_config) _, dynamic_model = ma_sim.build_simulation() expected_dynamic_submodels = set([sm.id for sm in self.model.get_submodels()]) - ma_sim.skipped_submodels() self.assertEqual(expected_dynamic_submodels, set(dynamic_model.dynamic_submodels)) submodel_1 = self.model.submodels.get(id='submodel_1')[0] # WC:modeling_framework is not an instance of a modeling framework submodel_1.framework = onto['WC:modeling_framework'] ma_sim = MultialgorithmSimulation(self.model, self.wc_sim_config) with self.assertRaisesRegex(MultialgorithmError, 'Unsupported lang_submodel framework'): ma_sim.build_simulation()