def general_sim(erad_path, ep4_scripts): """ This function is designed to be a parameterized version of the sequence of things we do every time we run an emod experiment. """ print_params() # Create a platform # Show how to dynamically set priority and node_group platform = Platform("SLURM") pl = RequirementsToAssetCollection(platform, requirements_path=manifest.requirements) # create EMODTask print("Creating EMODTask (from files)...") camp_path = build_camp() params.base_infectivity = 0.2 task = EMODTask.from_default2(config_path="my_config.json", eradication_path=manifest.eradication_path, campaign_path=camp_path, schema_path=manifest.schema_file, param_custom_cb=set_param_fn, ep4_custom_cb=None, demog_builder=build_demog) print("Adding asset dir...") task.common_assets.add_directory( assets_directory=manifest.assets_input_dir) # Set task.campaign to None to not send any campaign to comps since we are going to override it later with # dtk-pre-process. print("Adding local assets (py scripts mainly)...") if ep4_scripts is not None: for asset in ep4_scripts: pathed_asset = Asset(pathlib.PurePath.joinpath( manifest.ep4_path, asset), relative_path="python") task.common_assets.add_asset(pathed_asset) # Create simulation sweep with builder builder = SimulationBuilder() builder.add_sweep_definition(update_sim_random_seed, range(params.nSims)) # create experiment from builder experiment = Experiment.from_builder(builder, task, name=params.exp_name) # The last step is to call run() on the ExperimentManager to run the simulations. experiment.run(wait_until_done=True, platform=platform) #other_assets = AssetCollection.from_id(pl.run()) #experiment.assets.add_assets(other_assets) # Check result if not experiment.succeeded: print(f"Experiment {experiment.uid} failed.\n") exit() print(f"Experiment {experiment.uid} succeeded.") # Save experiment id to file with open("COMPS_ID", "w") as fd: fd.write(experiment.uid.hex) print() print(experiment.uid.hex)
from emodpy.bamboo import get_model_files from emodpy.emod_task import EMODTask from emodpy.utils import EradicationBambooBuilds from idmtools.builders import SimulationBuilder from idmtools.core.platform_factory import Platform import manifest import params from idmtools.entities.experiment import Experiment from interventions import build_campaign_with_standard_events from setup_sim import build_project_config from sweeps import update_sim_bic, update_sim_random_seed platform = Platform("SLURM") #, num_cores=params.num_cores) print("Creating EMODTask (from files)...") def build_demographics(): import emod_api.demographics.Demographics as Demographics demo = Demographics.from_file(manifest.demographics_file_path) return demo def create_and_submit_experiment(): task = EMODTask.from_default2( config_path="config.json", eradication_path=manifest.eradication_path, campaign_builder=build_campaign_with_standard_events,
import os from COMPS import Client, AuthManager from idmtools.assets import Asset from idmtools.core.platform_factory import Platform from idmtools.managers import ExperimentManager from idmtools_models.python.python_experiment import PythonExperiment # This provisions a script runs a pip install on a requirements.txt file to a temp direcorty on COMPS and then creates # an asset collection from the output. This helps avoid target the COMPS python binary that is currently available and # also avoid the need for the user to upload a large set of files to COMPS experiment = PythonExperiment( name="fractals asset bootstrap", model_path=os.path.join("requirements_to_asset_collection.py")) experiment.add_asset(Asset('model_requirements.txt')) platform = Platform('COMPS2') am = AuthManager(platform.endpoint) with open('token.txt', 'w') as of: of.write(am.get_auth_token()[1]) experiment.base_simulation.add_asset(Asset("token.txt")) em = ExperimentManager(experiment=experiment, platform=platform) em.run() em.wait_till_done()
def general_sim( erad_path ): # Function specially set parameter Run_Number set_Run_Number = partial(param_update, param="Run_Number") # Get experiment parameters from json file with open(manifest.PARAM_PATH) as f: param_dict = json.load(f) exp_name = param_dict['expName'] nSims = param_dict['nSims'] # Display exp_name and nSims print('exp_name: ', exp_name) print('nSims: ', nSims) # Create a platform # Show how to dynamically set priority and node_group platform = Platform('SLURM') pl = RequirementsToAssetCollection( platform, requirements_path=manifest.requirements ) # create EMODTask from default #task = EMODTask.from_default( default=EMODSir(), eradication_path=erad_path ) #task = EMODTask.from_default2(config_path="ignore_my_config.json", eradication_path=manifest.eradication_path, campaign_path=None, param_custom_cb=None, ep4_custom_cb=manifest.ep4_path) task = EMODTask.from_files(config_path=None, eradication_path=manifest.eradication_path, ep4_path=manifest.ep4_path, demographics_paths=None) # Add the parameters dictionary as an asset param_asset = Asset(absolute_path=manifest.PARAM_PATH) task.common_assets.add_asset(param_asset) # Add more asset from a directory assets_dir = 'measles_kurt/Assets' task.common_assets.add_directory(assets_directory=assets_dir) #task.is_linux = True # set campaign to None to not sending any campaign to comps since we are going to override it later with # dtk-pre-process, This is import step in COMPS2 task.campaign = None # Load campaign_template.json to simulation which used by dtk_pre_process.py campaign_template_asset = Asset(os.path.join(manifest.assets_input_dir, "campaign_template.json")) task.transient_assets.add_asset(campaign_template_asset) # Create simulation sweep with builder builder = SimulationBuilder() builder.add_sweep_definition(set_Run_Number, range(nSims)) # Create an experiment from builder experiment = Experiment.from_builder(builder, task, name=exp_name) other_assets = AssetCollection.from_id(pl.run()) experiment.assets.add_assets(other_assets) # Run experiment platform.run_items(experiment) # Wait experiment to finish platform.wait_till_done(experiment) # Check result if not experiment.succeeded: print(f"Experiment {experiment.uid} failed.\n") exit() print(f"Experiment {experiment.uid} succeeded.") # Save experiment id to file with open('COMPS_ID', 'w') as fd: fd.write(experiment.uid.hex) print() print(experiment.uid.hex)
covid_config_filename = emodpy_covid.build_covid_config(schema_filename) covid_demographics_filename = emodpy_covid.covid.get_demographics_json() seed_campaign_filename = emodpy_covid.covid.get_seed_campaign() dtk_pre_process_filename = emodpy_covid.write_pre_process_py() dtk_in_process_filename = emodpy_covid.write_in_process_py() local_assets_dict = { 'config': covid_config_filename, 'demog': covid_demographics_filename, 'campaign': seed_campaign_filename, 'pre_proc': dtk_pre_process_filename, 'in_proc': dtk_in_process_filename } if __name__ == "__main__": local_assets = build_emod_assets(schema_filename) platform = Platform('COMPS2') contact_tracing_task = EMODTask.from_files( eradication_path=Eradication_filename, config_path=local_assets['config'], campaign_path=local_assets['campaign'], demographics_paths=[ local_assets['demog'] ] ) dtk_in_process_asset = Asset(local_assets['in_proc'], relative_path='python') contact_tracing_task.common_assets.add_asset(dtk_in_process_asset) dtk_pre_process_asset = Asset(local_assets['pre_proc'],