Example #1
0
def set_immune_forcing_builder(transition_matrix=None,
                               scale_factor_array=[2, 5, 10, 100]):
    builder = ModBuilder.from_combos([
        ModFn(set_transition_matrix, transition_matrix, scale_factor)
        for scale_factor in scale_factor_array
    ])
    return builder
Example #2
0
    def test_generic_sweep(self):
        def verify(b):
            md = [(0.05, 100, 'Namawala'), (0.05, 100, 'Matsari'),
                  (0.1, 100, 'Namawala'), (0.1, 100, 'Matsari')]

            ngenerated = 0
            for i, ml in enumerate(b.mod_generator):
                for m in ml:
                    m(self.cb)
                mdd = dict(
                    zip(('x_Temporary_Larval_Habitat', 'Simulation_Duration',
                         '_site_'), md[i]))
                mdd.update({'population_scale': 1})
                self.assertEqual(b.metadata, mdd)
                self.assertEqual(
                    self.cb.get_param('x_Temporary_Larval_Habitat'), md[i][0])
                ngenerated += 1
            self.assertEqual(ngenerated, 4)

        b = ModBuilder.from_combos([
            ModFn(DTKConfigBuilder.set_param, 'x_Temporary_Larval_Habitat', v)
            for v in [0.05, 0.1]
        ], [ModFn(DTKConfigBuilder.set_param, 'Simulation_Duration', 100)
            ], [ModFn(configure_site, s) for s in ['Namawala', 'Matsari']])

        verify(b)

        b = GenericSweepBuilder.from_dict({
            'x_Temporary_Larval_Habitat': [0.05, 0.1],
            'Simulation_Duration': [100],
            '_site_': ['Namawala', 'Matsari']
        })

        verify(b)
Example #3
0
    def test_vector_drug_param_sweep(self):
        b = ModBuilder.from_combos([
            ModFn(set_species_param,
                  'gambiae',
                  'Required_Habitat_Factor',
                  value=v) for v in [(100, 50), (200, 100)]
        ], [
            ModFn(set_drug_param, 'Artemether', 'Max_Drug_IRBC_Kill', value=v)
            for v in [4, 2]
        ])
        md = [(4, (100, 50)), (2, (100, 50)), (4, (200, 100)), (2, (200, 100))]

        ngenerated = 0
        for i, ml in enumerate(b.mod_generator):
            for m in ml:
                m(self.cb)
            self.assertListEqual([v for v in b.metadata.values()], list(md[i]))
            self.assertEqual(
                get_species_param(self.cb, 'gambiae',
                                  'Required_Habitat_Factor'), md[i][1])
            self.assertEqual(
                get_drug_param(self.cb, 'Artemether', 'Max_Drug_IRBC_Kill'),
                md[i][0])
            ngenerated += 1
        self.assertEqual(ngenerated, 4)
def set_immune_forcing_builder(transition_matrix=None,
                               scale_factor_array=[2, 5, 10, 100]):
    """Creates an experiment builder setting up immunity based on scale factor"""
    builder = ModBuilder.from_combos([
        ModFn(set_transition_matrix, transition_matrix, scale_factor)
        for scale_factor in scale_factor_array
    ])
    return builder
Example #5
0
    def test_multiple_site_exception(self):
        def verify(b):
            with self.assertRaises(ValueError):
                for ml in b.mod_generator:
                    pass

        b = ModBuilder.from_combos([ModFn(set_calibration_site, 'Matsari')],
                                   [ModFn(configure_site, 'Namawala')])
        verify(b)

        b = ModBuilder.from_combos([ModFn(configure_site, 'Matsari')],
                                   [ModFn(configure_site, 'Namawala')])
        verify(b)

        b = ModBuilder.from_combos([ModFn(set_calibration_site, 'Matsari')],
                                   [ModFn(set_calibration_site, 'Namawala')])
        verify(b)
    def exp_builder_func(self, next_params, n_replicates=None):
        if not n_replicates:
            n_replicates = self.sim_runs_per_param_set

        return ModBuilder.from_combos(
                [ModFn(self.config_builder.__class__.set_param, 'Run_Number', i+1) for i in range(n_replicates)],
                [ModFn(site.setup_fn) for site in self.sites],
                [ModFn(self.map_sample_to_model_input_fn, index, samples) for index, samples in  enumerate(next_params)]
        )
Example #7
0
    def set_mods(cls, pv_pairs):
        """
        Dictionary may include the special keys: '__site__' or '__calibsite___',
        which are recognized as shorthand for site-configuration functions
        with the site name as the "parameter value".
        """
        def convert_to_mod_fn(pv_pair):
            p, v = pv_pair
            if p == '_site_':
                return ModFn(configure_site, v)
            return ModFn(DTKConfigBuilder.set_param, p, v)

        return ModBuilder.set_mods([convert_to_mod_fn(pv_pair) for pv_pair in pv_pairs])
    def add_test(self, test_name):
        m = ModBuilder.ModList()

        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)

        m.append(configure)

        return m
Example #9
0
    SetupParser.set("HPC", "priority", priority)
    SetupParser.set("HPC", "node_group", coreset)

    modlists = []
    new_modlist = [
        ModFn(pickup_from_sample, i)
        for i in range(len(arab_spline_list) * len(funest_spline_list))
    ]
    modlists.append(new_modlist)
    #
    # new_modlist = [ModFn(counterfactuals, itn, irs, mda, msat, chw_hs, chw_rcd)
    #                for itn in [True]
    #                for irs in [True]
    #                for mda in [True]
    #                for msat in [True]
    #                for chw_hs in [False, True]
    #                for chw_rcd in [False, True]]

    tuples_list = generate_input_variations()
    new_modlist = [
        ModFn(counterfactuals, x[0], x[1], x[2], x[3], x[4], x[5])
        for x in tuples_list
    ]
    modlists.append(new_modlist)

    builder = ModBuilder.from_combos(*modlists)

    exp_manager = ExperimentManagerFactory.init()
    exp_manager.run_simulations(config_builder=cb,
                                exp_name=experiment_name,
                                exp_builder=builder)
Example #10
0
        # 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,
            'sweep_name': sweep['name']
        })

# # ck4, for catalyst this block
# run_sim_args = run_sets[1]
# run_sim_args.pop('base_simulation_id')
# run_sim_args.pop('sweep_name')
# 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)
    ])

# This dictionary is used by the `dtk run` command line and allow to pass it some parameters
# If you are running through `python example_templates.py`, this dictionary is unused
run_sim_args = {
    'exp_builder': experiment_builder,
    'exp_name': 'TemplateDemo',
    'config_builder': config_builder
}

# This part is needed if you are running the script through `python example_templates.py`
# It is not used by the command line interface
if __name__ == "__main__":
    # The first thing to do is always to initialize the environment
    no_resistance = [
        [ModFn(DTKConfigBuilder.set_param, 'Run_Number', seed),
         ModFn(change_vector_params, species='gambiae', mutation_rate1=mutation_rate1,
               mutation_rate2=mutation_rate2, serialization_seed=0),
         ModFn(DTKConfigBuilder.set_param, 'Serialized_Population_Path', ''),
         ModFn(add_ITNs, coverage=0.6, start=start, insecticide='carbamate', label='No_resistance'),
         ModFn(add_ITNs, coverage=0.6, start=start + 3 * 365, insecticide='carbamate', label='No_resistance')
         ]
        for seed in range(num_seeds)
        for mutation_rate1 in [0.01]
        for mutation_rate2 in [0]
        for start in [180 + extra * 365]
    ]

    builder = ModBuilder.from_list(no_rotation_three_year + no_nets + no_resistance)

    ############################### REPORTERS ###############################################
    vector_genetics_report = 1
    vector_stats_report = 0
    malaria_summary_report = 0

    add_reporters(cb, vector_genetics_report=vector_genetics_report)

    ############################## HEALTH SEEKING ###########################################
    # Health seeking
    add_health_seeking(cb,
                       targets=[{'trigger': 'NewClinicalCase',
                                 'coverage': 0.5,
                                 'agemin': 0,
                                 'agemax': 100,
            }
        }]
    }
    set_species_genes(cb, genes)

    copy_to_likelihoods = np.arange(0.5, 0.59, 0.1).tolist()

    # Add gene trait modifiers

    gene_drive = [[
        ModFn(DTKConfigBuilder.set_param, 'Run_Number', seed),
        ModFn(add_release, label='Gene_drive'),
        ModFn(add_driver, copy_to_likelihood=likelihood),
    ] for seed in range(num_seeds) for likelihood in copy_to_likelihoods]

    builder = ModBuilder.from_list(gene_drive)

    # Call output reporters
    cb.add_reports(
        BaseVectorGeneticsReport(
            type='ReportVectorGenetics',
            species='arabiensis',
            gender='VECTOR_FEMALE',
            include_vector_state_columns=1,
            stratify_by='SPECIFIC_GENOME',
            combine_similar_genomes=1,
            specific_genome_combinations_for_stratification=[{
                "Allele_Combination": [["X", "X"], ["a1", "*"]]
            }, {
                "Allele_Combination": [["X", "X"], ["a0", "a0"]]
            }]))
Example #14
0
temp_h = [12.424280532176581]
habitat_scales = it.product(temp_h, const_h)

site = 'Hautkatanga'
demographics_filename = "Hautkatanga_node13.json"
air_temp_filename = "DemocraticRepublicOfTheCongo_30arcsec_air_temperature_daily.bin"
land_temp_filename = "DemocraticRepublicOfTheCongo_30arcsec_air_temperature_daily.bin"
rainfall_filename = "DemocraticRepublicOfTheCongo_30arcsec_rainfall_daily.bin"
relative_humidity_filename = "DemocraticRepublicOfTheCongo_30arcsec_relative_humidity_daily.bin"

exp_name = site + '_baseline_single'

nyears = 50

builder = ModBuilder.from_combos(
    [ModFn(set_habs_scale, habs)
     for habs in habitat_scales],  # set habitat scales
    [ModFn(DTKConfigBuilder.set_param, 'Run_Number', r) for r in range(1)])

cb = DTKConfigBuilder.from_defaults('MALARIA_SIM')

cb.update_params({
    "Num_Cores": 1,
    "Age_Initialization_Distribution_Type": 'DISTRIBUTION_COMPLEX',
    "Simulation_Duration": nyears * 365,
    "Enable_Demographics_Reporting": 1,
    "Enable_Demographics_Builtin": 0,
    "Valid_Intervention_States": [],
    "New_Diagnostic_Sensitivity": 0.05  # 20/uL
})

# match demographics file for constant population size (with exponential age distribution)
from simtools.ModBuilder import ModFn, ModBuilder

from dtk.utils.core.DTKConfigBuilder import DTKConfigBuilder
from malaria.reports.MalariaReport import add_patient_report
from dtk.vector.study_sites import configure_site
from dtk.vector.species import set_species_param
from simtools.SetupParser import SetupParser

SetupParser.default_block = 'HPC'
exp_name = 'DrugCampaignVectorParamSweep'

builder = ModBuilder.from_combos([
    ModFn(DTKConfigBuilder.set_param, 'x_Temporary_Larval_Habitat', h)
    for h in [0.05]
], [ModFn(configure_site, 'Namawala')], [
    ModFn(set_species_param, 'gambiae', 'Required_Habitat_Factor', value=v)
    for v in [(100, 50), (200, 100)]
], [
    ModFn(set_drug_param, 'Artemether', 'Max_Drug_IRBC_Kill', value=v)
    for v in [4, 2]
])

cb = DTKConfigBuilder.from_defaults('MALARIA_SIM')
cb.update_params({
    'Num_Cores': 1,
    'Base_Population_Scale_Factor': 0.01,
    'Simulation_Duration': 30
})

add_drug_campaign(cb, 'DHA', start_days=[10])
add_patient_report(cb)
    def submit_experiment(self,
                          cb,
                          num_seeds=1,
                          intervention_sweep=False,
                          migration_sweep=False,
                          vector_migration_sweep=False,
                          simple_intervention_sweep=False,
                          custom_name=None):

        # Implement the actual (not dummy) baseline healthseeking
        self.implement_baseline_healthseeking(cb)

        modlists = []

        if num_seeds > 1:
            new_modlist = [
                ModFn(DTKConfigBuilder.set_param, 'Run_Number', seed)
                for seed in range(num_seeds)
            ]
            modlists.append(new_modlist)

        if migration_sweep:
            new_modlist = [
                ModFn(DTKConfigBuilder.set_param, 'x_Local_Migration', x)
                for x in [0.5, 1, 5, 10]
            ]
            modlists.append(new_modlist)

        if vector_migration_sweep:
            new_modlist = [
                ModFn(self.vector_migration_sweeper, vector_migration_on)
                for vector_migration_on in [True, False]
            ]
            modlists.append(new_modlist)

        if simple_intervention_sweep:
            new_modlist = [
                ModFn(self.implement_interventions, True, False, False, False,
                      False),
                ModFn(self.implement_interventions, False, True, False, False,
                      False),
                ModFn(self.implement_interventions, False, False, True, False,
                      False),
                ModFn(self.implement_interventions, False, False, False, True,
                      False),
                ModFn(self.implement_interventions, False, False, False, False,
                      True),
                ModFn(self.implement_interventions, True, True, True, True,
                      True)
            ]
            modlists.append(new_modlist)
        else:
            # new_modlist = [ModFn(self.implement_interventions, True, True, True, True, True)]
            new_modlist = [
                ModFn(self.implement_interventions, True, True, False, False,
                      False)
            ]
            modlists.append(new_modlist)

        builder = ModBuilder.from_combos(*modlists)

        run_name = self.exp_name
        if custom_name:
            run_name = custom_name

        # SetupParser.init()
        # SetupParser.set("HPC","priority","Normal")
        # exp_manager = ExperimentManagerFactory.init()
        # exp_manager.run_simulations(config_builder=self.cb, exp_name=run_name, exp_builder=builder)
        # return self.cb
        exp_manager = ExperimentManagerFactory.init()
        exp_manager.run_simulations(config_builder=cb,
                                    exp_name=run_name,
                                    exp_builder=builder)
        return cb
Example #17
0
coverages = [0.6, 0.7, 0.8, 0.9, 1.0]

SMC = [
            [
               ModFn(DTKConfigBuilder.set_param, 'Run_Number', seed),
               ModFn(DTKConfigBuilder.set_param, 'Simulation_Duration', smc_start_day+365),
               ModFn(add_smc_group,
                         start_days=[smc_start_day],
                         coverage=smc_coverage, drug='DP', agemax=5),
               ModFn(add_summary_report_by_start_day, start_day=smc_start_day),
            ]
           for smc_coverage in coverages
           for seed in range(num_seeds)
        ]

builder = ModBuilder.from_list(SMC)

run_sim_args = {'config_builder': cb,
                'exp_name': expname,
                'exp_builder': builder}


if __name__ == "__main__":

    SetupParser.default_block = 'HPC'

    SetupParser.init()
    exp_manager = ExperimentManagerFactory.init()
    exp_manager.run_simulations(**run_sim_args)
    # Wait for the simulations to be done
    exp_manager.wait_for_finished(verbose=True)
Example #18
0
prefix = "GarkiNE"

exp_name = prefix + "_pop_rep_3_locations_con_sw_w_seasonality"

num_cores = 24

num_years = 1

builder = ModBuilder.from_combos(
    [ModFn(configure_site, site)],
    [
        ModFn(DTKConfigBuilder.set_param, "x_Vector_Migration_Local", vm)
        for vm in [1]
    ],  #, 5*1e-1, 1]],
    [ModFn(DTKConfigBuilder.set_param, 'Run_Number', r) for r in range(1, 2)],

    # [ModFn(DTKConfigBuilder.set_param, 'HEG_Infection_Modification', im) for im in [0.05]],
    # [ModFn(DTKConfigBuilder.set_param, 'HEG_Fecundity_Limiting', fl) for fl in [0.05]],
    # [ModFn(DTKConfigBuilder.set_param, 'HEG_Homing_Rate', hr) for hr in [0.95]],
    # [ModFn(heg_release, num_released, num_repetitions = 10, released_species = "arabiensis", start_day = d, node_list = range(200, 300, 45)) for (num_released, d)  in [(500, 480)]],
    #[ModFn(heg_release, num_released, num_repetitions = 52, released_species = "arabiensis", start_day = d, node_list = [1]) for (num_released, d)  in [(500, 365)]],
    #[ModFn(heg_release, num_released, num_repetitions = 52, released_species = "arabiensis", start_day = d, node_list = range(1, 400, 20)) for (num_released, d)  in [(500, 365)]],
)

cb = DTKConfigBuilder.from_defaults('VECTOR_SIM',
                                    Num_Cores=num_cores,
                                    Simulation_Duration=int(365 * num_years))

# set demographics file name
cb.update_params({
    'Demographics_Filenames':
        [ModFn(DTKConfigBuilder.set_param, 'Run_Number', seed),
         ModFn(DTKConfigBuilder.set_param, 'Serialized_Population_Path', ''),
         ModFn(add_nets, coverage=net_coverage, number=0, num_nodes=0, start_day=start_day),
         ModFn(add_drivers, copy_to_likelihood=likelihood),
         ModFn(add_trait_modifiers, transmission_to_human=transmission_prob)
         ]
        for seed in range(num_seeds)
        for start_day in [0]
        for number in [0]
        for numnodes in [0]
        for net_coverage in [0.0]
        for likelihood in [0.0]
        for transmission_prob in [1.0]
    ]

    builder = ModBuilder.from_list(VC_and_GM + VC + GM + No_interventions)
    # builder = ModBuilder.from_list(VC)

    ################################ INTERVENTIONS ###################################

    # Health seeking
    add_health_seeking(cb,
                       targets=[{'trigger': 'NewClinicalCase',
                                 'coverage': 0.5,
                                 'agemin': 0,
                                 'agemax': 100,
                                 'seek': 1,
                                 'rate': 0.3},
                                {'trigger': 'NewSevereCase',
                                 'coverage': 0.8,
                                 'agemin': 0,
Example #20
0
from malaria.interventions.malaria_challenge import add_challenge_trial
from simtools.ModBuilder import  ModFn, ModBuilder
from malaria.reports.MalariaReport import add_survey_report
from malaria.reports.MalariaReport import add_summary_report

burnin_duration = 25550

monthlyEIRs_1 = [1.9375, 3.375, 7.5, 1.9375, 0.5, 0.5, 0.5, 0.5, 0.25, 0.5, 0.5,1.0]
monthlyEIRs_2 = [3.875, 7.75, 15.0, 3.875, 1, 1, 1, 1, 0.5, 1, 1,2]

exp_name  = 'Challenge_bite_20_350_Dan_fix'

builder = ModBuilder.from_list(
    [[ModFn(add_challenge_trial, x, disable_vitals = False),
      ModFn(add_survey_report,[x],reporting_interval = 730),
      ModFn(add_summary_report,x,interval = 365/12,description = 'Monthly Report',
             age_bins = [1.0, 4.0, 8.0, 18.0, 28.0, 43.0, 400000.0],
             parasitemia_bins = [0.0, 16.0, 409.0, 4000000.0])
     ]
      for x in range(730,740,10)])


# builder = ModBuilder.from_list(
#     [[ModFn(add_InputEIR, monthlyEIRs_1, start_day=x, nodes={
#             "Node_List": [
#                1
#             ],
#             "class": "NodeSetNodeList"
#          }),
#       ModFn(add_InputEIR, monthlyEIRs_2, start_day=x, nodes={
#             "Node_List": [
#                2
Example #21
0
            "Decay_Time_Constant": 30
        }
    }]

    add_ATSB(cb,
             coverage=coverage,
             start=100,
             duration=365,
             kill_cfg=killing_cfg[1])
    return {'coverage': coverage, 'initial_killing': killing}


# add_ATSB(cb, start=100, coverage=1, duration=365)

builder = ModBuilder.from_list([[
    ModFn(atsb_fn, cov, kill),
    ModFn(DTKConfigBuilder.set_param, 'Run_Number', x)
] for cov in [0, 1] for kill in [0.15] for x in range(1)])

run_sim_args = {
    'config_builder': cb,
    'exp_name': exp_name,
    'exp_builder': builder
}

if __name__ == "__main__":
    SetupParser.init('HPC')
    exp_manager = ExperimentManagerFactory.init()
    exp_manager.run_simulations(**run_sim_args)
    # Wait for the simulations to be done
    exp_manager.wait_for_finished(verbose=True)
    assert (exp_manager.succeeded())
Example #22
0
            # Construct the table
            table = [list(c.values()) for c in combined]

            # Change some things in the config.json
            config.set_param('Config_Name', scenario_name)

            # Initialize the template
            tpl = TemplateHelper()
            tpl.set_dynamic_header_table(headers, table)
            tpl.active_templates = [
                config, campaign_tpl, demog, demog_pfa, demog_asrt, demog_acc
            ]

            # Create an experiment builder
            experiment_builder = ModBuilder.from_combos(
                tpl.get_modifier_functions())
            experiment_manager = ExperimentManagerFactory.from_cb(
                config_builder)
            COMPS_experiment_name = scenario_name
            # COMPS_experiment_name = suite_name # I want hover-over in COMPS to be the suite name

            experiment_manager.run_simulations(exp_name=COMPS_experiment_name,
                                               exp_builder=experiment_builder,
                                               suite_id=suite_id)
            experiments.append(experiment_manager)
            experiments_ids.append(experiment_manager.experiment.exp_id)

        # Dump the experiment ids for resume
        with open('ids.json', 'w') as out:
            json.dump(experiments_ids, out)
                    RuralMultiplier[ind], UrbanMultiplier[ind], MCV1Days[ind],
                    mAbProfile[ind], Dropout[ind], MCV2Days[ind],
                    BirthRateScale[ind], basePop, 3.0
                ]
            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 [
                    "Serialized_Population_Filenames": [
                        name for name in os.listdir(
                            os.path.join(df["outpath"][x], "output"))
                        if "state" in name
                    ],
                    "Run_Number":
                    y,
                    "x_Temporary_Larval_Habitat":
                    df["x_Temporary_Larval_Habitat"][x]
                }) for x in df.index for y in range(num_runs)
        ]

        builder = ModBuilder.from_list(
            [[
                burnin_fn,
                ModFn(add_intervention, intervention, coverage,
                      species_details)
            ] for burnin_fn in from_burnin_list
             for intervention in interventions
             for coverage in np.linspace(0, 1, num_coverage_bins)])

    else:
        print("building burnin")
        builder = ModBuilder.from_list(
            [[
                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),
Example #25
0
              smc_start_day + 365),
        ModFn(
            add_smc_group,
            start_days=[smc_start_day],
            coverage=smc_coverage,
            drug=drug,
            agemax=agemax,
        ),
        ModFn(add_summary_report, start_day=smc_start_day),
        ModFn(DTKConfigBuilder.set_param, 'Serialized_Population_Path',
              '{path}/output'.format(path=path))
    ] for smc_start_day in intervention_days for smc_coverage in coverages
           for seed in range(num_seeds) for path in serialized_file_output
           for agemax in [5, 10] for drug in ['DP']]

    builder = ModBuilder.from_list(expanded_SMC_IVM)

    set_climate_constant(cb)
    set_species_param(
        cb, 'gambiae', 'Larval_Habitat_Types', {
            "LINEAR_SPLINE": {
                "Capacity_Distribution_Per_Year": {
                    "Times": [
                        0.0, 30.417, 60.833, 91.25, 121.667, 152.083, 182.5,
                        212.917, 243.333, 273.75, 304.167, 334.583
                    ],
                    "Values":
                    [3, 0.8, 1.25, 0.1, 2.7, 8, 4, 35, 6.8, 6.5, 2.6, 2.1]
                },
                "Max_Larval_Capacity": 1e9
            }
Example #26
0
                     "class": 'WaningEffectConstant',
                     "Initial_Effect": killing,
                 }
             },
             duration=10000)
    # add_ATSB(cb, coverage=coverage, start=100, duration=365, kill_cfg=killing_cfg[1])
    return {'killing': killing, 'startDay': startDay}


# add_ATSB(cb, start=100, coverage=1, duration=365)

builder = ModBuilder.from_list([
    [
        ModFn(atsb_fn, killing, (years - 2) * 365),
        ModFn(DTKConfigBuilder.set_param, 'x_Temporary_Larval_Habitat', hab)
        # Run simulation with coverage, duration, or repetitions spread.
        # Don't leave duration over 210 because we don't know how ATSBs act after 210 days, or how they act after Dec 31.
    ] for killing in np.linspace(0, 0.25, 20)
    for hab in np.arange(0.2, 1, 0.478 / 10)
])

run_sim_args = {
    'config_builder': cb,
    'exp_name': exp_name,
    'exp_builder': builder
}

if __name__ == "__main__":
    SetupParser.init('HPC')
    exp_manager = ExperimentManagerFactory.init()
    exp_manager.run_simulations(**run_sim_args)
Example #27
0
# +-------------------+----------------+
# | 0                 | 0              |
# | 5                 | 0              |
# | 10                | 0              |
# | ...               | ...            |
# | 5                 | 1              |
# | 10                | 1              |
# | 365               | 1              |
# | ...               | ...            |
# | 365               | 4              |
# | 730               | 4              |
# +-------------------+----------------+
builder = ModBuilder.from_combos(
    [ModFn(set_larvicides, start_time) for start_time in (0, 5, 10, 365, 730)],
    [
        ModFn(DTKConfigBuilder.set_param, 'Run_Number', seed)
        for seed in range(5)
    ],
)

# The run_sim_args is a dictionary informing the command line of:
# - What config builder to use
# - What is the name we want for the experiment
# - Which experiment builder to use
run_sim_args = {
    'config_builder': cb,
    'exp_name': 'Sample larvicides epxeriment',
    'exp_builder': builder
}

# In this file we also decided to include the analyzers.
Example #28
0
                   nreports=1,
                   age_bins=[5, 125],
                   parasitemia_bins=[0, 50, 200, 500, 2000000])

healthseeking_coverage_pairs = [[0.30, 0.30]]  # as U5 and then >5 year olds

# creates a sweep of simulations with varying coverages and Run_Number seeds
healthseeking = [[
    ModFn(sweep_coverages, coverages),
    ModFn(scale_linear_spline_max_habitat, x),
    ModFn(DTKConfigBuilder.set_param, 'Run_Number', seed)
] for x in np.logspace(-3, -0.3, 50)
                 for coverages in healthseeking_coverage_pairs
                 for seed in range(num_seeds)]

builder = ModBuilder.from_list(healthseeking)

# Run args
run_sim_args = {
    'config_builder': cb,
    'exp_name': exp_name,
    'exp_builder': builder
}

if __name__ == "__main__":

    if not SetupParser.initialized:
        SetupParser.init('HPC')

    exp_manager = ExperimentManagerFactory.init()
    exp_manager.run_simulations(**run_sim_args)
    set_species_param(cb, 'funestus', 'Larval_Habitat_Types',
                      {"CONSTANT": 11250000000})
    set_species_param(cb, 'funestus', 'Male_Life_Expectancy', 5)
    set_species_param(cb, 'funestus', 'Adult_Life_Expectancy', 10)
    set_species_param(cb, 'funestus', 'Transmission_Rate', 0.5)
    set_species_param(cb, 'funestus', 'Indoor_Feeding_Fraction', 1.0)

    ########################## VECTOR GENETICS ####################################################
    add_genes(cb)

    mendelian = [[
        ModFn(DTKConfigBuilder.set_param, 'Run_Number', seed),
        ModFn(add_release, label=label, number=10000),
    ] for seed in range(num_seeds) for label in ['No_inrogression']]

    builder = ModBuilder.from_list(mendelian)

    # Call output reporters
    cb.add_reports(
        BaseVectorGeneticsReport(
            type='ReportVectorGenetics',
            species='arabiensis',
            gender='VECTOR_FEMALE',
            include_vector_state_columns=1,
            stratify_by='SPECIFIC_GENOME',
            combine_similar_genomes=1,
            specific_genome_combinations_for_stratification=[{
                "Allele_Combination": [["X", "X"], ["a0", "*"]]
            }]))
    cb.add_reports(
        BaseVectorGeneticsReport(
    def add_my_outbreak(cb, start_day):
        recurring_outbreak(cb, start_day=start_day, repetitions=1)
        return {'outbreak_start_day': start_day}

    builder = ModBuilder.from_list([[
        ModFn(add_my_outbreak, start_day=x * 365),
        ModFn(DTKConfigBuilder.set_param, 'Run_Number', y),
        ModFn(DTKConfigBuilder.set_param, 'Simulation_Duration',
              (x * 365) + (3 * 365)),
        ModFn(add_filtered_report, start=x * 365, end=(x * 365) + (3 * 365)),
        ModFn(add_health_seeking,
              start_day=0,
              targets=[{
                  'trigger': 'NewClinicalCase',
                  'coverage': 1,
                  'agemin': 0,
                  'agemax': 200,
                  'seek': 1,
                  'rate': 0.3
              }, {
                  'trigger': 'NewSevereCase',
                  'coverage': 1,
                  'seek': 1,
                  'rate': 0.5
              }])
    ] for y in range(num_seeds) for x in range(51)])
    #ModFn(add_my_outbreak, start_day=x),
    #ModFn(add_health_seeking, start_day=0, targets=[
    #{'trigger': 'NewClinicalCase', 'coverage': 1, 'agemin': 0, 'agemax': 200, 'seek': 1,'rate': 0.3},
    #{'trigger': 'NewSevereCase', 'coverage': 1, 'seek': 1, 'rate': 0.5}])