def _run(self, points, resample_step): """ This run method is for running simulations, which is the in-common part of resampling. :param points: The points to run simulations at. :return: The Experiment object for these simulations """ # create a sweep where each point is a separate sim if not self.calib_manager: raise Exception( 'calibration manager has not set for resampler. Cannot generate simulations.' ) point_dicts = [point.to_value_dict() for point in points] # ck4, the number of replicates must be 1 for HIV for now; the general solution should allow a user-selected # replicate count, so long as their likelihood analyzer can handle > 1 replicates. exp_builder = self.calib_manager.exp_builder_func(point_dicts, n_replicates=1) # Create an experiment manager manager = ExperimentManagerFactory.from_cb( self.calib_manager.config_builder) exp_name = self.calib_manager.name + '_resample_step_%d' % resample_step manager.run_simulations(exp_name=exp_name, blocking=True, exp_builder=exp_builder) return manager
def test_verify_asset_collection_id_and_tags_added_to_experiment(self): """ Makes sure the individual asset collection ids are stored as tags on an experiment and that the 'master' asset collection id (id for all asset files together in one collection) is stored properly on the simulations as well. """ expected_asset_collection = 'e05d3535-dab8-e711-80c3-f0921c167860' # master collection run_sim_args = {'exp_name': 'AssetCollectionTestSim'} exp_manager = ExperimentManagerFactory.from_cb( config_builder=self.config_builder) exp_manager.run_simulations(**run_sim_args) # now query COMPS for this experiment and retrieve/verify tags sim = exp_manager.comps_experiment.get_simulations( query_criteria=COMPSQueryCriteria().select_children( children=['tags', 'configuration']))[0] tags = sim.tags for asset_type in SimulationAssets.COLLECTION_TYPES: if asset_type == SimulationAssets.PYTHON: continue tag = "%s_collection_id" % asset_type self.assertTrue( exp_manager.assets.collections.get(asset_type, None) is not None) self.assertTrue(tags.get(tag, None) is not None) # verify the asset_collection_id was added properly asset_collection_id = sim.configuration.asset_collection_id self.assertEqual(str(asset_collection_id), expected_asset_collection)
else: values = [ 0.4 + 0.59 * math.sqrt(random.uniform(0, 1)), 0.4 + 0.59 * math.sqrt(random.uniform(0, 1)), SIACov[ind], random.randint(1, 1e6), Migration[ind], RuralMultiplier[ind], UrbanMultiplier[ind], MCV1Days[ind], mAbProfile[ind], Dropout[ind], MCV2Days[ind], BirthRateScale[ind], basePop, 3.0 ] mod_fns.append(ModFn(sample_point_fn, names, values)) builder = ModBuilder.from_combos(mod_fns) # Name the experiment exp_name = 'Measles RI targets' exp_manager = ExperimentManagerFactory.from_cb(cb) # suite_id = exp_manager.create_suite("My experiment - Iteration 0") run_sim_args = { 'config_builder': cb, 'exp_name': exp_name, 'exp_builder': builder } exp_manager.experiment_tags = {} for name, value in zip(names, values): if name not in [ 'META_Vaccination_Threshold', 'META_Fraction_Meeting', 'Run_Number' ]: exp_manager.experiment_tags[name] = value
######################## # other configurations ######################## # If the base collection containing CMS exists, use it # If not, use the local if SetupParser.default_block == "HPC": try: cb.set_collection_id('CMS 0.82 Pre-release') except SimulationAssets.InvalidCollection: cb.set_experiment_executable('inputs/compartments/compartments.exe') cb.set_dll_root('inputs/compartments') else: cb.set_experiment_executable('inputs/compartments/compartments.exe') cb.set_dll_root('inputs/compartments') run_sim_args = {"config_builder": cb, "exp_name": "First Default CMS run"} if __name__ == "__main__": SetupParser.init() em = ExperimentManagerFactory.from_cb(run_sim_args["config_builder"]) em.run_simulations(exp_name=run_sim_args["exp_name"]) # Wait for the simulation to complete em.wait_for_finished(verbose=True) # Analyze am = AnalyzeManager(exp_list='latest') am.add_analyzer(SimpleCMSAnalyzer()) am.analyze()
from dtk.utils.core.DTKConfigBuilder import DTKConfigBuilder from dtk.vector.study_sites import configure_site from simtools.ExperimentManager.ExperimentManagerFactory import ExperimentManagerFactory from simtools.SetupParser import SetupParser from dtk.interventions.outbreakindividualdengue import add_OutbreakIndividualDengue # This block will be used unless overridden on the command-line SetupParser.default_block = 'HPC' cb = DTKConfigBuilder.from_defaults('DENGUE_SIM') configure_site(cb, 'Puerto_Rico') cb.campaign["Campaign_Name"] = "Campaign - Outbreak" add_OutbreakIndividualDengue(cb, 100, {'max': 1.725, 'min': 0}, 'Strain_1', []) add_OutbreakIndividualDengue(cb, 5000, {}, 'Strain_2', []) add_OutbreakIndividualDengue(cb, 5000, {}, 'Strain_3', []) add_OutbreakIndividualDengue(cb, 5000, {}, 'Strain_4', []) # cb.set_param('Simulation_Duration', 30*365) run_sim_args = { 'exp_name': 'ExampleSim', 'config_builder': cb } if __name__ == "__main__": SetupParser.init() exp_manager = ExperimentManagerFactory.from_cb(config_builder=cb) exp_manager.run_simulations(**run_sim_args)
ModFn( DTKConfigBuilder.update_params, { "Run_Number": run_num, "x_Temporary_Larval_Habitat": 10**hab_exp }), ] for run_num in range(10) for hab_exp in np.concatenate((np.arange(-3.75, -2, 0.25), np.arange(-2, 2.25, 0.1)))]) run_sim_args = { "config_builder": cb, "exp_name": sweep_name, "exp_builder": builder } em = ExperimentManagerFactory.from_cb(cb) em.run_simulations(**run_sim_args) em.wait_for_finished(verbose=True) assert (em.succeeded()) analyzer = PfPRAnalyzer(expt_name=sweep_name, report_names=sites["name"].tolist(), sweep_variables=[ "Run_Number", "x_Temporary_Larval_Habitat", "intervention", "intervention_coverage" ]) am = AnalyzeManager(em.experiment, analyzers=analyzer) am.analyze()