def submit_run_EMOD(exp, scen_df):
"""
Submit and run an EMOD experiment, parameterizing various steps involved in the simulation.
This function sets up the experiment, configures input files, manages reporting, and submits the experiment.
This function handles the creation and configuration of the EMOD task based on the provided
experiment parameters, including setting up entomology, serialized input data, and specifying
how to handle different simulation steps (e.g., 'pickup', 'burnin'). It also schedules necessary
reports for analysis and prepares the experiment for execution. The experiment is then submitted
for execution on the provided platform, and the experiment analysis is scheduled.
Args:
exp (ExperimentConfig): An instance of the `ExperimentConfig` class that contains all the parameters
necessary to configure and run the EMOD simulation. This includes simulation
duration, entomology mode, burn-in period, platform configuration, and more.
scen_df (pandas.DataFrame): A DataFrame containing the scenario data to be used for the experiment.
The dataframe should include the scenario IDs and relevant parameters
that define the experiment conditions.
Returns:
experiment (Experiment): The configured and submitted `Experiment` object that represents the
EMOD experiment that was created and submitted for execution.
Raises:
ValueError: If the experiment configuration or scenario data is incomplete or invalid.
"""
emod_serialized_id = exp.emod_serialized_id
sim_dur_years = exp.sim_dur_years
entomology_mode = exp.entomology_mode
emod_step = exp.emod_step
burnin = exp.emod_burnin
platform = exp.platform
agebins = exp.agebins
sim_start_year_emod = exp.sim_start_year_emod
# create EMODTask
print("Creating EMODTask (from files)...")
task = config_task(platform, exp)
task = build_demog(task,exp)
if entomology_mode == 'dynamic':
task.common_assets.add_directory(os.path.join(manifest.input_dir, "climate"), relative_path="climate")
if emod_step == 'pickup':
serialized_df = build_burnin_df(emod_serialized_id, platform, burnin * 365)
serialized_df = serialized_df.drop(columns=['x_Temporary_Larval_Habitat'], errors='ignore')
scen_df_pickup = scen_df.merge(serialized_df, on=['scen_id'],
how='inner') ## FIXME when running expanded pickup from burnin
builder = config_sweep_builder_pickup(exp, scen_df_pickup)
else:
builder = config_sweep_builder(exp, scen_df)
#add_report_vector_stats(task, manifest, species_list=["gambiae"], stratify_by_species =True)
add_annual_reports(task, manifest, age_bins=agebins, sim_start_year=sim_start_year_emod,
num_year=sim_dur_years, detection_threshold=exp.detectionLimit)
if emod_step != 'burnin': # do not generate monthly reports for burnin
if 'daily' in exp.analyzer_list:
add_daily_reports(task, manifest, age_bins=agebins, sim_start_year=sim_start_year_emod, num_year=sim_dur_years,
detection_threshold=exp.detectionLimit) #We shouldn't generate daily reports unless specified
add_monthly_reports(task, manifest, age_bins=agebins, sim_start_year=sim_start_year_emod, num_year=sim_dur_years,
detection_threshold=exp.detectionLimit)
if '5day' in exp.analyzer_list or 'cc_step' in exp.analyzer_list: # Note, we will not want to always run 5 days using the analyzer_list as a flag to include this reporter or not
add_5daily_reports(task, manifest, age_bins=agebins, sim_start_year=sim_start_year_emod, num_year=sim_dur_years,
detection_threshold=exp.detectionLimit)
# Create experiment from builder and run
experiment = Experiment.from_builder(builder, task, name="")
experiment.run(wait_until_done=False, platform=platform)
# Additional step to schedule analyzer
experiment.hpc = exp.hpc
experiment.sh_hpc_config = exp.sh_hpc_config
experiment.mem_increase_factor = exp.mem_increase_factor
experiment.EMOD_venv = exp.EMOD_venv
experiment.analyzer_script = exp.analyzer_script
experiment.job_directory = exp.job_directory
experiment.emod_step = exp.emod_step
experiment.start_end = [sim_start_year_emod, sim_start_year_emod + sim_dur_years - 1]
generate_run_EMOD_file(experiment, platform, suite_directory = exp.suite_directory)
submit_analyze_EMOD(experiment, platform)
print(f"Experiment submission {experiment.uid} succeeded.")
return experiment