def configure(cb): ModBuilder.metadata.update({'Config_Name': test_name}) test = DTKConfigBuilder.from_files( os.path.join(self.regression_path, test_name, 'config.json'), os.path.join(self.regression_path, test_name, 'campaign.json')) cb.copy_from(test)
def configure_forest_system(years=100, migration_start_day=91, migration_type='one_season'): # General village_nodes = [1, 2] forest_nodes = [3] geog_name = "Ratanikiri_3node" cb = DTKConfigBuilder.from_defaults('MALARIA_SIM') standard_cb_updates(cb, years, geog_name) update_vector_params(cb) # For the forest: add Individual Properties so only some people travel to forest nodes change_individual_property_at_age(cb, 'ForestGoing', 'LovesForest', coverage=0.7, change_age_in_days=15 * 365, revert=20 * 365) add_forest_migration(cb, migration_start_day, years, forest_nodes, village_nodes, mig_type=migration_type) recurring_outbreak(cb, start_day=(91 + 30), outbreak_fraction=0.2, nodes={ "class": "NodeSetNodeList", 'Node_List': forest_nodes }) return cb
def configure_sahel_intervention_system(years=100): # General cb = DTKConfigBuilder.from_defaults('MALARIA_SIM') standard_cb_updates(cb, years) update_vector_params(cb) return cb
def test_add_ITN(): # cb = {} cb = DTKConfigBuilder.from_defaults('MALARIA_SIM') coverage_by_age = {'min': 0, 'max': 200, 'coverage': 1} ITN_event = add_ITN(cb, start=0, coverage_by_ages=[coverage_by_age], waning={}, nodeIDs=[]) print(ITN_event) print(ITN_event.to_json())
def do_stuff(): SetupParser.default_block = 'HPC' gen_cb = DTKConfigBuilder.from_defaults('GENERIC_SIM_SEIR') gen_cb.params["Simulation_Duration"] = 200 exp_tags = {} exp_tags['role'] = 'serialization_test' exp_tags['model'] = 'generic' s_ts = [5, 25, 150] T = skt.SerializationKsTest(config_builder=gen_cb, experiment_name='Generic serialization test', experiment_tags=exp_tags, timesteps_to_serialize=s_ts, inset_channels=[ 'New Infections', 'Infected', 'Statistical Population' ]) T.run_test()
def setUp(self): current_dir = os.path.dirname(os.path.realpath(__file__)) input_dir = os.path.join(current_dir, 'input') self.am_simtools = os.path.join(input_dir, 'am_simtools.ini') # Adjust path sensitive parameters in the ini file cp = ConfigParser() cp.read(self.am_simtools) cp.set('DEFAULT', 'path', input_dir) cp.set('DEFAULT', 'example_dir', os.path.join(current_dir, '..', '..', 'examples')) cp.write(open(self.am_simtools, 'w')) SetupParser.init(selected_block=self.SELECTED_BLOCK, setup_file=self.am_simtools) self.config_builder = DTKConfigBuilder.from_defaults('VECTOR_SIM') configure_site(self.config_builder, 'Namawala') self.config_builder.add_reports(BaseReport(type="VectorHabitatReport"))
def configure_VC_GM_intervention_system(prefix, geography, num_cores=1, num_years=100, migration_mul=1): # General cb = DTKConfigBuilder.from_defaults( 'MALARIA_SIM', Num_Cores=num_cores, Simulation_Duration=int(365 * num_years), ) standard_cb_updates(cb, prefix, geography, migration_mul) update_vector_params(cb) return cb
def do_stuff(): SetupParser.default_block = 'HPC' vec_cb = DTKConfigBuilder.from_defaults('VECTOR_SIM') configure_site(vec_cb, 'Namawala') exp_tags = {} exp_tags['role'] = 'serialization_test' exp_tags['model'] = 'vector' s_ts = [5, 25, 150] T = skt.SerializationKsTest(config_builder=vec_cb, experiment_name='Vector serialization test', experiment_tags=exp_tags, timesteps_to_serialize=s_ts, inset_channels=['Adult Vectors', 'New Infections', 'Infected', 'Statistical Population', 'Daily EIR']) T.run_test()
def prepare_malariatherapy_configbuilder(config_path, immunity_forcing=True, years=1): # Setup ------------------------------------------------------------------------------------------- cb = DTKConfigBuilder.from_files(config_path) cb.update_params({ 'Vector_Species_Names': [], 'Simulation_Duration': 365 * years, 'Demographics_Filenames': ['Malariatherapy_demographics.json'] }) set_climate_constant(cb) # Add source of infection (challenge bite or forced EIR) ------------------------------------------ add_challenge_trial(cb, start_day=0) # ---- CUSTOM REPORTS ---- add_patient_report(cb) return cb
def test_listed_events(self): from simtools.SetupParser import SetupParser SetupParser.init() # Create a builder based on the files builder = DTKConfigBuilder.from_files( os.path.join(self.input_path, 'customevents', 'configbad.json'), os.path.join(self.input_path, 'customevents', 'campaign.json')) # Call the file writter def fake_write(name, content): return builder.file_writer(fake_write) # Try if the listed events worked self.assertEqual( set(builder.config['parameters']['Listed_Events']), set([ "Received_ITN", "TestedPositive", "Received_Campaign_Drugs", "Received_Treatment", "Received_Test", "Received_Survey", "Diagnostic_Survey_5", "Give_Drugs" ]))
from dtk.utils.core.DTKConfigBuilder import DTKConfigBuilder from simtools.SetupParser import SetupParser from simtools.ExperimentManager.ExperimentManagerFactory import ExperimentManagerFactory # Run on HPC SetupParser.default_block = "HPC" # Tell this module how to find the config and campaign files to be used. Set campaign_file to None if not used. input_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "input") config_file = os.path.join(input_dir, 'config.json') campaign_file = os.path.join(input_dir, 'campaign.json') kwargs = {} cb = DTKConfigBuilder.from_files(config_name=config_file, campaign_name=campaign_file, **kwargs) cb.set_collection_id('71483975-57dc-e711-9414-f0921c16b9e5') # Name of the experiment exp_name = 'catalyst_comparison-MalariaSandbox' # when run with 'dtk catalyst', run_sim_args['exp_name'] will have additional information appended. run_sim_args = { 'exp_name': exp_name, # 'exp_builder': builder, # users may have created one; this will be overridden in 'dtk catalyst' 'config_builder': cb } if __name__ == "__main__": SetupParser.init()
def basic_gridded_config_builder(immunity_params="prashanth"): cb = DTKConfigBuilder.from_defaults('MALARIA_SIM') # Reduce StdOut size and prevent DTK from spitting out too many messages cb.update_params({ "logLevel_default": "WARNING", "Enable_Log_Throttling": 1, "Memory_Usage_Warning_Threshold_Working_Set_MB": 50000, "Memory_Usage_Halting_Threshold_Working_Set_MB": 60000, "logLevel_JsonConfigurable": "WARNING", "Disable_IP_Whitelist": 1 }) cb.update_params(immunity.params) cb.update_params(infection.params) cb.update_params(symptoms.params) if immunity_params == 'prashanth': cb.update_params({ 'Antigen_Switch_Rate': pow(10, -9.116590124), 'Base_Gametocyte_Production_Rate': 0.06150582, 'Base_Gametocyte_Mosquito_Survival_Rate': 0.002011099, 'Falciparum_MSP_Variants': 32, 'Falciparum_Nonspecific_Types': 76, 'Falciparum_PfEMP1_Variants': 1070, 'Gametocyte_Stage_Survival_Rate': 0.588569307, 'MSP1_Merozoite_Kill_Fraction': 0.511735322, 'Max_Individual_Infections': 3, 'Nonspecific_Antigenicity_Factor': 0.415111634 }) elif immunity_params == "jaline": cb.update_params({ 'Base_Gametocyte_Production_Rate': 0.044, "Gametocyte_Stage_Survival_Rate": 0.82, 'Antigen_Switch_Rate': 2.96e-9, 'Falciparum_PfEMP1_Variants': 1112, 'Falciparum_MSP_Variants': 7, 'MSP1_Merozoite_Kill_Fraction': 0.43, 'Falciparum_Nonspecific_Types': 90, 'Nonspecific_Antigenicity_Factor': 0.42, 'Base_Gametocyte_Mosquito_Survival_Rate': 0.00088, "Max_Individual_Infections": 5 }) cb.update_params({ "Climate_Model": "CLIMATE_CONSTANT", "Base_Air_Temperature": 27, "Base_Land_Temperature": 27, "Migration_Model": "NO_MIGRATION", "Enable_Immunity_Distribution": 0, "Enable_Immunity_Initialization_Distribution": 0, "Immunity_Initialization_Distribution_Type": "DISTRIBUTION_OFF" }) cb.update_params({ "Enable_Demographics_Other": 1, "Enable_Demographics_Builtin": 0, "Valid_Intervention_States": [], "Report_Detection_Threshold_PfHRP2": 40.0, "Report_Detection_Threshold_Blood_Smear_Parasites": 0, "Parasite_Smear_Sensitivity": 0.025, "Birth_Rate_Dependence": "FIXED_BIRTH_RATE", # Match demographics file for constant population size (with exponential age distribution) "Enable_Nondisease_Mortality": 1, }) # Intervention events intervene_events_list = [ "Bednet_Got_New_One", "Bednet_Using", "Bednet_Discarded" ] cb.update_params({ "Report_Event_Recorder": 0, "Report_Event_Recorder_Ignore_Events_In_List": 0, "Listed_Events": intervene_events_list, "Report_Event_Recorder_Events": intervene_events_list }) # Basic entomology set_species_param(cb, 'arabiensis', 'Indoor_Feeding_Fraction', 0.5) set_species_param(cb, 'arabiensis', 'Adult_Life_Expectancy', 20) set_species_param(cb, 'arabiensis', 'Anthropophily', 0.65) set_species_param(cb, 'funestus', "Indoor_Feeding_Fraction", 0.9) set_species_param(cb, 'funestus', 'Adult_Life_Expectancy', 20) set_species_param(cb, 'funestus', 'Anthropophily', 0.65) return cb
# For quick test simulations, this is set to a very low value static_params = {'Base_Population_Scale_Factor': 0.05} cfg.set_params(static_params) cpn.set_params(static_params) # Prepare templates templates = TemplateHelper() table_base = { 'ACTIVE_TEMPLATES': [cfg, cpn, demog_pfa, demog_acc, demog_asrt], 'TAGS': { 'Scenario': 'StatusQuo_Baseline', 'pyOptimTool': None } } config_builder = DTKConfigBuilder() config_builder.ignore_missing = True def constrain_sample(sample): if 'Pr Ex Trns Male LOW' and 'Pr Ex Trns Male MED' in sample: sample['Pr Ex Trns Male LOW'] = min( [sample['Pr Ex Trns Male LOW'], sample['Pr Ex Trns Male MED']]) if 'Pr Ex Trns Fem LOW' and 'Pr Ex Trns Fem MED' in sample: sample['Pr Ex Trns Fem LOW'] = min( [sample['Pr Ex Trns Fem LOW'], sample['Pr Ex Trns Fem MED']]) return sample def map_sample_to_model_input(config_builder, s):
SetupParser.init('HPC') # Find experiment from whose config/campaigns we want to use (also get sweep params) comparison_exp_id = "9945ae69-3106-e711-9400-f0921c16849c" sim_name = 'Rerun_Rampup_MDA_Better_Diagnostic' expt = retrieve_experiment(comparison_exp_id) df = pd.DataFrame([x.tags for x in expt.simulations]) df['outpath'] = pd.Series([sim.get_path() for sim in expt.simulations]) # generate cb object from the first of these files (the only difference will be in the sweep params) cb_dir = df['outpath'][0] cb = DTKConfigBuilder.from_files(config_name=os.path.join(cb_dir, 'config.json'), campaign_name=os.path.join(cb_dir, 'campaign.json')) CompsDTKOutputParser.sim_dir_map = None #cb.update_params({'Num_Cores': 1}) sites = [ MyanmarCalibSite() ] # Here we are specifying the initial values for the next point data initial_state = [{ 'NodeIDs':[], 'Serialization':2007, 'Prevalence_date':2006, 'Prevalence_threshold':0.4, 'New_Duration': 1643, # Duration of second iteration
run_sets = [] for sweep in SWEEPS: i = 0 for sim_id in os.listdir(path=simulation_input_files_dir): # Create one experiment per base_simulationXsweep pairing. Each exp contains one sim per sweep setting. i += 1 simulation_directory = os.path.join(simulation_input_files_dir, sim_id) if not os.path.isdir(simulation_directory): # skip over Readme file continue # create a config builder for the current experiment, derived from the base simulation input files config_filepath = os.path.join(simulation_directory, 'config.json') campaign_filepath = os.path.join( simulation_directory, 'campaign_Swaziland_v05Sep2018_FINAL_reftracktopup_2011_v2.json') cb = DTKConfigBuilder.from_files(config_name=config_filepath, campaign_name=campaign_filepath) cb.set_input_files_root( path=simulation_directory ) # discoverability of other input files, e.g. PFA_Overlay.json exp_name = EXP_NAME_PATTERN % (sweep['name'], i) # Create a generator of the per-simulation differences from the base simulation builder = ModBuilder.from_combos(sweep['mods']) # keep track of each run_sim_args dictionary, one per experiment run_sets.append({ 'exp_name': exp_name, 'exp_builder': builder, 'config_builder': cb, 'base_simulation_id': sim_id,
from malaria.reports.MalariaReport import add_filtered_report from dtk.vector.species import set_larval_habitat from simtools.SetupParser import SetupParser from spline_functions import * # from .spline_functions import get_spline_values_for_all_params, get_annual_representative_spline, \ # get_representative_spline_multipiers from dtk.interventions.novel_vector_control import add_ATSB from ATSBEntoCalibSite import ATSBEntoCalibSite # Which simtools.ini block to use for this calibration SetupParser.default_block = 'HPC' # Start from a base MALARIA_SIM config builder # This config builder will be modify by the different sites defined below cb = DTKConfigBuilder.from_defaults('MALARIA_SIM') update_species_param(cb, 'gambiae', 'Indoor_Feeding_Fraction', 0.5) update_species_param(cb, 'funestus', 'Indoor_Feeding_Fraction', 0.9) update_species_param(cb, 'gambiae', 'Vector_Sugar_Feeding_Frequency', 'VECTOR_SUGAR_FEEDING_EVERY_DAY', overwrite=False) update_species_param(cb, 'gambiae', 'Anthropophily', 0.8) update_species_param(cb, 'gambiae', 'Adult_Life_Expectancy', 20) datadir = 'C:\\Users\\jkurlander\\Dropbox (IDM)' # List of sites we want to calibrate on throwaway = 1 species = 'gambiae' reference_fname = 'cluster_mosquito_counts_per_house_by_month.csv' reference_spline = 'Multi_year_calibration_by_HFCA_180404/best_180409/Panjane_funestus.csv' irs_fn = os.path.join(datadir, 'Malaria Team Folder/projects/Mozambique/entomology_calibration/cluster_all_irs_events_pyrethroid_2014.csv')
BaseInputPath = load_input_path() if not os.path.exists(BaseInputPath): os.mkdir(BaseInputPath) OutputPath = os.path.join(load_output_path(), ScenarioName) if not os.path.exists(OutputPath): os.mkdir(OutputPath) if not os.path.exists(os.path.join(OutputPath, 'input_files')): os.mkdir(os.path.join(OutputPath, 'input_files')) #Name the input files DemoFile = os.path.join(BaseInputPath, 'demographics.json') CampaignFile = os.path.join(BaseInputPath, 'campaign.json') ConfigFile = os.path.join(BaseInputPath, 'config.json') SimDurationInYears = 1 TotalPopulation = 5e5 cb = DTKConfigBuilder.from_files(ConfigFile, campaign_name=CampaignFile) cb.set_param('Simulation_Duration', SimDurationInYears * 365.0) demoFile = DemographicsFile.from_file(DemoFile) demoFile.content['Nodes'][0]['NodeAttributes'][ 'InitialPopulation'] = TotalPopulation #Fix this if len(demoFile.nodes) == 1: for node in demoFile.nodes.values(): node.pop = TotalPopulation else: raise ValueError('demographics.json assumed to have only one node') demoFile = SetAgeDistribution( demoFile,
def setUp(self): self.cb = DTKConfigBuilder.from_defaults('VECTOR_SIM')
def setUp(self): self.cb = DTKConfigBuilder.from_defaults('MALARIA_SIM')
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)
def basic_gridded_config_builder(archetype="Southern"): cb = DTKConfigBuilder.from_defaults('MALARIA_SIM') cb.update_params(immunity.params) cb.update_params(infection.params) cb.update_params(symptoms.params) cb.update_params({ 'Antigen_Switch_Rate': pow(10, -9.116590124), 'Base_Gametocyte_Production_Rate': 0.06150582, 'Base_Gametocyte_Mosquito_Survival_Rate': 0.002011099, 'Falciparum_MSP_Variants': 32, 'Falciparum_Nonspecific_Types': 76, 'Falciparum_PfEMP1_Variants': 1070, 'Gametocyte_Stage_Survival_Rate': 0.588569307, 'MSP1_Merozoite_Kill_Fraction': 0.511735322, 'Max_Individual_Infections': 3, 'Nonspecific_Antigenicity_Factor': 0.415111634 }) cb.update_params({ "Climate_Model": "CLIMATE_BY_DATA", "Migration_Model": "NO_MIGRATION", "Enable_Immunity_Distribution": 0, "Enable_Immunity_Initialization_Distribution": 0, "Immunity_Initialization_Distribution_Type": "DISTRIBUTION_OFF", "Enable_Demographics_Risk": 1 }) cb.update_params({ "Disable_IP_Whitelist": 1, "Enable_Demographics_Other": 1, "Enable_Demographics_Builtin": 0, "Valid_Intervention_States": [], "Report_Detection_Threshold_PfHRP2": 40.0, "Report_Detection_Threshold_Blood_Smear_Parasites": 0, "Parasite_Smear_Sensitivity": 0.025, "Report_Detection_Threshold_True_Parasite_Density": 40, "Birth_Rate_Dependence": "FIXED_BIRTH_RATE", # Match demographics file for constant population size (with exponential age distribution) "Enable_Nondisease_Mortality": 1, }) # Intervention events intervene_events_list = [ "Bednet_Got_New_One", "Bednet_Using", "Bednet_Discarded" ] full_custom_events_list = [ "Bednet_Got_New_One", "Bednet_Using", "Bednet_Discarded", "Received_Treatment", "Received_Campaign_Drugs", "Received_RCD_Drugs", "Received_Test", "Received_SMC", "Took_Dose", "InfectionDropped", "Received_Ivermectin", "Received_Primaquine", "Received_Campaign_Drugs_Term_1", "Received_Campaign_Drugs_Term_2", "Received_Campaign_Drugs_Term_3" ] cb.set_param("Custom_Individual_Events", full_custom_events_list) cb.update_params({ "Report_Event_Recorder": 0, "Report_Event_Recorder_Ignore_Events_In_List": 0, # "Listed_Events": full_custom_events_list, #intervene_events_list "Report_Event_Recorder_Events": full_custom_events_list #intervene_events_list }) # Basic entomology set_ento(cb, archetype=archetype ) # I think there just needs to be something set for now return cb
def basic_cb(self): SetupParser.default_block = self.parser_location self.cb = DTKConfigBuilder.from_defaults('MALARIA_SIM') self.cb.set_experiment_executable( os.path.join(self.dropbox_base, 'bin/malaria_ongoing_build_185/Eradication.exe')) self.cb.set_input_files_root( os.path.join(self.dropbox_base, 'inputs/catchments/')) # Tell config builder where to find dlls for specified Bamboo build of executable self.cb.set_dll_root( os.path.join(self.dropbox_base, 'bin/malaria_ongoing_build_185/')) self.cb.set_param("Num_Cores", self.num_cores) # Reduce StdOut size self.cb.params['logLevel_default'] = "WARNING" self.cb.params['Enable_Log_Throttling'] = 1 self.cb.params["Memory_Usage_Warning_Threshold_Working_Set_MB"] = 50000 self.cb.params["Memory_Usage_Halting_Threshold_Working_Set_MB"] = 60000 # Prevent DTK from spitting out too many messages self.cb.params['logLevel_JsonConfigurable'] = "WARNING" self.cb.params['Disable_IP_Whitelist'] = 1 # Latest parameters # self.cb.update_params(immunity.params) self.cb.update_params(infection.params) self.cb.update_params(symptoms.params) if self.immunity_params == 'prashanth': self.cb.update_params({ 'Antigen_Switch_Rate': pow(10, -9.116590124), 'Base_Gametocyte_Production_Rate': 0.06150582, 'Base_Gametocyte_Mosquito_Survival_Rate': 0.002011099, 'Falciparum_MSP_Variants': 32, 'Falciparum_Nonspecific_Types': 76, 'Falciparum_PfEMP1_Variants': 1070, 'Gametocyte_Stage_Survival_Rate': 0.588569307, 'MSP1_Merozoite_Kill_Fraction': 0.511735322, 'Max_Individual_Infections': 3, 'Nonspecific_Antigenicity_Factor': 0.415111634 }) elif self.immunity_params == "jaline": self.cb.update_params({ 'Base_Gametocyte_Production_Rate': 0.044, "Gametocyte_Stage_Survival_Rate": 0.82, 'Antigen_Switch_Rate': 2.96e-9, 'Falciparum_PfEMP1_Variants': 1112, 'Falciparum_MSP_Variants': 7, 'MSP1_Merozoite_Kill_Fraction': 0.43, 'Falciparum_Nonspecific_Types': 90, 'Nonspecific_Antigenicity_Factor': 0.42, 'Base_Gametocyte_Mosquito_Survival_Rate': 0.00088, "Max_Individual_Infections": 5 })
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 simtools.Utilities.Experiments import retrieve_simulation from COMPS.Client import Client Client.login("comps.idmod.org") SetupParser.default_block = "HPC" priority = "Highest" coreset = "emod_32cores" cb = DTKConfigBuilder.from_defaults('VECTOR_SIM', Simulation_Duration=365) configure_site(cb, 'Namawala') # Using dtk-tools example exe/dlls, which fits the DTKConfigBuilder.from_defaults call cb.set_experiment_executable( "C:/Users/jsuresh/Code/dtk-tools/examples/inputs/Eradication.exe") cb.set_dll_root("C:/Users/jsuresh/Code/dtk-tools/examples/inputs/dlls") # Serialization stuff: # To write out a serialization file at a timestep cb.set_param("Serialization_Time_Steps", [100, 200, 300]) # To draw from a serialized file: def draw_from_burnin(cb, burnin_sim_id):
def setUp(self): self.cb = DTKConfigBuilder.from_defaults('MALARIA_SIM') self.input_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'input')
import os from dtk.interventions.larvicides import add_larvicides from dtk.utils.analyzers import TimeseriesAnalyzer, group_by_name from dtk.utils.core.DTKConfigBuilder import DTKConfigBuilder from simtools.ExperimentManager.ExperimentManagerFactory import ExperimentManagerFactory from simtools.ModBuilder import ModBuilder, ModFn from simtools.SetupParser import SetupParser SetupParser.default_block = 'HPC' # Create a config builder from set of input files input_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "inputs", "Sweeps") cb = DTKConfigBuilder.from_files(os.path.join(input_dir, 'config.json'), os.path.join(input_dir, 'campaign.json')) # Change the duration of the simulations to 5 years cb.set_param('Simulation_Duration', 5 * 365) # Define a set_larvicides function in order for the builder to call with different values # Functions passed to the builder needs to take a ConfigBuilder as first parameter # Here we are interested on sweeping on the start date of the intervention. def set_larvicides(cb, start): # Add larvicides to the campaign held in the ConfigBuilder add_larvicides(cb, start) # Returns the tag we want our simulation to have # In order to identify which value of the sweep we used, we are tagging our simulations # with larvicide_start = start date of the larvicides intervention
'Testing1b': 'Works' }], [[cfg, cpn_outbreak, demog_pfa], 1980, 0.50, 1.0e-3, { 'Testing2': None }]] # Initialize the template system # ============================== # Create an instance of the TemplateHelper helper class and, if desired, give it templates to work with. # In this example, there's no need to set the campaign_template because it will be set dynamically from the table above. templates = TemplateHelper() # Give the header and table to the template helper templates.set_dynamic_header_table(header, table) # Let's use a standard DTKConfigBuilder. config_builder = DTKConfigBuilder() # ignore_missing is required when using templates config_builder.ignore_missing = True # Use the default COMPS 2.10 and the SamplesInput folder for input files # See examples\AssetManagement\use_custom_executable.py for more information config_builder.set_exe_collection('EMOD 2.10') # For the experiment builder in the example, we use a ModBuilder from_combos to run # each of the configurations for two separate run numbers. # The first line needs to be the modifier functions coming from the templates experiment_builder = ModBuilder.from_combos( templates.get_modifier_functions(), # <-- Do this first! [ ModFn(DTKConfigBuilder.set_param, 'Run_Number', rn) for rn in range(2, 4)
from simtools.ModBuilder import ModBuilder, ModFn from simtools.SetupParser import SetupParser from single_node_simulations.helper_functions import change_vector_params, update_config_params, add_reporters, \ add_ITNs, add_insecticides if __name__ == "__main__": dir = './' geography = 'Burkina Faso' prefix = 'single_node_simulations' exp_name = "insecticide_resistance_single_node" extra = 0 num_years = 6 + extra num_seeds = 50 cb = DTKConfigBuilder.from_defaults('MALARIA_SIM', Simulation_Duration=int(365 * num_years)) update_config_params(cb, direc=dir, geography=geography) add_insecticides(cb, pyrethroid_killing=0.125, carbamate_killing=0.25) serialized_file_list = ['', ''] cb.update_params({ 'Serialized_Population_Filenames': serialized_file_list }) ########################## VECTOR GENETICS ############################################ three_year_gap = [ [ModFn(DTKConfigBuilder.set_param, 'Run_Number', seed), ModFn(change_vector_params, species='gambiae', mutation_rate1=mutation_rate1, mutation_rate2=mutation_rate2, serialization_seed=0),
import os import json import math import random from dtk.utils.core.DTKConfigBuilder import DTKConfigBuilder from dtk.utils.reports.BaseAgeHistReport import BaseAgeHistReport from simtools.ModBuilder import ModBuilder, ModFn from simtools.SetupParser import SetupParser from simtools.ExperimentManager.ExperimentManagerFactory import ExperimentManagerFactory from SetupFunctions import sample_point_fn #Run on HPC SetupParser.default_block = "HPC" cb = DTKConfigBuilder.from_files(config_name='InputFiles\\config.json', campaign_name='InputFiles\\basecampaign.json') cb.set_param('Num_Cores', 1) cb.set_experiment_executable(path='Executable\\Eradication.exe') cb.add_demog_overlay( name='demographics.json', content=json.load( open('InputFiles\\Nigeria_Ward_smaller_minpop5000_demographics.json'))) cb.experiment_files.add_file( path='InputFiles\\Nigeria_Ward_smaller_minpop5000_air_migration.bin') cb.experiment_files.add_file( path='InputFiles\\Nigeria_Ward_smaller_minpop5000_air_migration.bin.json') cb.experiment_files.add_file( path='InputFiles\\Nigeria_Ward_smaller_minpop5000_local_migration.bin') cb.experiment_files.add_file( path='InputFiles\\Nigeria_Ward_smaller_minpop5000_local_migration.bin.json' )
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.incidence_counter import add_incidence_counter from dtk.interventions.irs import add_node_IRS from malaria.reports.MalariaReport import add_event_counter_report # you need to isntall the malaria package # This block will be used unless overridden on the command-line # this means that simtools.ini local block will be used SetupParser.default_block = 'LOCAL' cb = DTKConfigBuilder.from_defaults('VECTOR_SIM') configure_site(cb, 'Namawala') # event counter can help you keep track of events that are happening add_event_counter_report( cb, ["HappyBirthday", "Party", "PartyHarder", "IRS_Blackout_Event_Trigger"]) # adding an incidence counter, which starts on day 20, and counts "Happy Birthday" events for 30 days. the default # thresholds are 10 and 100 event counts and default events being sent out when the threshold is reached are Action1 and Action2 add_incidence_counter( cb, start_day=20, count_duration=30, count_triggers=['HappyBirthday'], threshold_type= 'COUNT', #this is the default, we can also look at % per eligible population thresholds=[13, 254], triggered_events=['Party', 'PartyHarder'])
## Execute directly: 'python example_sweep.py' ## or via the dtk.py script: 'dtk run example_sweep.py' import numpy as np from dtk.utils.core.DTKConfigBuilder import DTKConfigBuilder from dtk.utils.builders.sweep import GenericSweepBuilder from dtk.vector.study_sites import configure_site from simtools.SetupParser import SetupParser from simtools.ExperimentManager.ExperimentManagerFactory import ExperimentManagerFactory # Run on HPC SetupParser.default_block = "HPC" # Configure a default 5 years simulation cb = DTKConfigBuilder.from_defaults('MALARIA_SIM', Simulation_Duration=365 * 5) # Set it in Namawala configure_site(cb, 'Namawala') # Name of the experiment exp_name = 'ExampleSweep' # Create a builder to sweep over the birth rate multiplier builder = GenericSweepBuilder.from_dict({'x_Birth': np.arange(1, 1.5, .1)}) run_sim_args = { 'exp_name': exp_name, 'exp_builder': builder, 'config_builder': cb }