-
Notifications
You must be signed in to change notification settings - Fork 28
/
run_example.py
112 lines (75 loc) · 2.98 KB
/
run_example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import pathlib
import os
from functools import \
partial
#idmtools
from idmtools.assets import Asset, AssetCollection
from idmtools.builders import SimulationBuilder
from idmtools.core.platform_factory import Platform
from idmtools.entities.experiment import Experiment
#emodpy
from emodpy.emod_task import EMODTask
from emodpy.utils import EradicationBambooBuilds
from emodpy.bamboo import get_model_files
import emod_api.config.default_from_schema_no_validation as dfs
import emod_api.campaign as camp
#emodpy-malaria
import emodpy_malaria.demographics.MalariaDemographics as Demographics
import manifest
def set_param_fn(config):
"""
This function is a callback that is passed to emod-api.config to set config parameters, including the malaria defaults.
"""
import emodpy_malaria.malaria_config as conf
config = conf.set_team_defaults(config, manifest)
return config
def build_camp():
"""
This function builds a campaign input file for the DTK using emod_api.
"""
camp.set_schema(manifest.schema_file)
return camp
def build_demog():
"""
This function builds a demographics input file for the DTK using emod_api.
"""
demog = Demographics.from_template_node(lat=1, lon=2, pop=10, name="Example_Site")
return demog
def general_sim(selected_platform):
"""
This function is designed to be a parameterized version of the sequence of things we do
every time we run an emod experiment.
"""
# Set platform and associated values, such as the maximum number of jobs to run at one time
platform = Platform(selected_platform, job_directory=manifest.job_directory, partition='b1139testnode', time='2:00:00',
account='b1139', modules=['singularity'], max_running_jobs=10)
# create EMODTask
print("Creating EMODTask (from files)...")
task = EMODTask.from_default2(
config_path="config.json",
eradication_path=manifest.eradication_path,
campaign_builder=build_camp,
schema_path=manifest.schema_file,
param_custom_cb=set_param_fn,
ep4_custom_cb=None,
demog_builder=build_demog,
plugin_report=None
)
# set the singularity image to be used when running this experiment
task.set_sif(manifest.SIF_PATH, platform)
# create experiment from builder
user = os.getlogin()
experiment = Experiment.from_task(task, name= f'{user}_FE_example_basic')
# The last step is to call run() on the ExperimentManager to run the simulations.
experiment.run(wait_until_done=True, platform=platform)
# Check result
if not experiment.succeeded:
print(f"Experiment {experiment.uid} failed.\n")
exit()
print(f"Experiment {experiment.uid} succeeded.")
if __name__ == "__main__":
import emod_malaria.bootstrap as dtk
import pathlib
dtk.setup(pathlib.Path(manifest.eradication_path).parent)
selected_platform = "SLURM_LOCAL"
general_sim(selected_platform)