"Enable_Vital_Dynamics": 1,
                      "Enable_Birth": 1,
                      'Enable_Default_Reporting': 1,
                      'Enable_Demographics_Other': 1,
                      'logLevel_default': 'ERROR',
                      # 'Enable_Property_Output': 1,

                      'x_Temporary_Larval_Habitat': 1,

                      "Simulation_Duration": sim_duration,
                      "Run_Number": 0,
                      "Vector_Species_Names": ['gambiae']
                      })

    add_SerializationTimesteps(cb, [sim_duration], end_at_final=True)
    #
    # add_health_seeking(cb,
    #                    targets=[{'trigger': 'NewClinicalCase', 'coverage': 0.3, 'agemin': 5, 'agemax': 70, 'seek': 1.0,
    #                              'rate': 0.3},
    #                             {'trigger': 'NewClinicalCase', 'coverage': 0.5, 'agemin': 0, 'agemax': 5,
    #                              'seek': 1.0, 'rate': 0.3},
    #                             {'trigger': 'NewSevereCase', 'coverage': 0.5, 'seek': 1.0, 'rate': 0.5}],
    #                    drug=['Artemether', 'Lumefantrine'],
    #                    dosing='FullTreatmentNewDetectionTech',
    #                    nodes={"class": "NodeSetAll"},
    #                    repetitions=1,
    #                    start_day=sim_duration-10*365,
    #                    tsteps_btwn_repetitions=365,
    #                    broadcast_event_name='Received_Treatment'
    #                    )
Example #2
0
cb_serializing = DTKConfigBuilder.from_defaults('VECTOR_SIM')
configure_site(cb_serializing, 'Namawala')

cb_reloading = DTKConfigBuilder.from_defaults('VECTOR_SIM')
configure_site(cb_reloading, 'Namawala')

if __name__ == "__main__":
    SetupParser.init()
    exp_manager = ExperimentManagerFactory.from_setup()

    timesteps_to_serialize = [5, 10, 50]
    old_simulation_duration = cb_serializing.params["Simulation_Duration"]
    serialized_last_timestep = timesteps_to_serialize[-1]
    serialization.add_SerializationTimesteps(config_builder=cb_serializing,
                                             timesteps=timesteps_to_serialize,
                                             end_at_final=True)

    serialized_builder = SingleSimulationBuilder()
    exp_manager.run_simulations(config_builder=cb_serializing,
                                exp_builder=serialized_builder,
                                exp_name="Sample serialization test")
    exp_manager.wait_for_finished()

    serialized_sim = exp_manager.experiment.simulations[0]
    serialized_output_path = path.join(serialized_sim.get_path(), 'output')
    s_pop_filename = "state-00050.dtk"

    reloaded_builder = SingleSimulationBuilder()
    cb_reloading.params["Start_Time"] = serialized_last_timestep
    cb_reloading.params[
Example #3
0
    def run_test(self):
        SetupParser.init()
        self.exp_manager = ExperimentManagerFactory.init()
        exp_manager = self.exp_manager

        for tag in self.exp_tags:
            exp_manager.experiment_tags[tag] = self.exp_tags[tag]

        cfg_builder = self.cb
        cfg_builder.set_param("Config_Name", "Full run sim")
        fullrun_builder = SingleSimulationBuilder()
        fullrun_builder.tags['role'] = 'fullrun'
        exp_manager.run_simulations(config_builder=cfg_builder,
                                    exp_builder=fullrun_builder,
                                    exp_name=self.exp_name)

        old_sim_duration = cfg_builder.params["Simulation_Duration"]
        for ts in self.timesteps_to_serialize:
            ts_string = str(ts)
            serialization.add_SerializationTimesteps(
                config_builder=cfg_builder, timesteps=[ts], end_at_final=True)
            cfg_builder.set_param("Config_Name",
                                  "Serializing sim at {0}".format(ts_string))
            serialized_builder = SingleSimulationBuilder()
            serialized_builder.tags['role'] = 'serializer'
            serialized_builder.tags[self.s_timestep_tagname] = ts_string
            exp_manager.run_simulations(config_builder=cfg_builder,
                                        exp_builder=serialized_builder,
                                        exp_name=self.exp_name)

        exp_manager.wait_for_finished()

        self.baseline_sim = exp_manager.experiment.get_simulations_with_tag(
            'role', 'fullrun')[0]
        cfg_builder.params.pop("Serialization_Time_Steps")

        for ts in self.timesteps_to_serialize:
            ts_string = str(ts)
            serialized_sim = exp_manager.experiment.get_simulations_with_tag(
                self.s_timestep_tagname, ts_string)[0]
            serialized_output_path = path.join(serialized_sim.get_path(),
                                               'output')

            # build s_pop_filename
            prefix_len = 5 - len(ts_string)
            prefix = '0' * prefix_len
            s_pop_filename = 'state-{0}{1}.dtk'.format(prefix, ts_string)

            cfg_builder.set_param("Config_Name",
                                  "Reloading sim at {0}".format(ts_string))
            reloaded_builder = SingleSimulationBuilder()
            reloaded_builder.tags['role'] = 'reloader'
            reloaded_builder.tags[self.s_timestep_tagname] = ts_string
            cfg_builder.params["Start_Time"] = ts
            cfg_builder.params["Simulation_Duration"] = old_sim_duration - ts

            serialization.load_Serialized_Population(
                config_builder=cfg_builder,
                population_filenames=[s_pop_filename],
                population_path=serialized_output_path)
            exp_manager.run_simulations(config_builder=cfg_builder,
                                        exp_builder=reloaded_builder,
                                        exp_name=self.exp_name)
        exp_manager.wait_for_finished()
        self.create_combined_charts()
        if self.inset_channels:
            self.test_channels(self.inset_channels,
                               original_report_name='InsetChart.json')
if __name__ == "__main__":
    # Initialize the SetupParser
    SetupParser.init()

    # Create a configbuilder for the simulation to serialize
    cb_serializing = DTKConfigBuilder.from_defaults('VECTOR_SIM')
    configure_site(cb_serializing, 'Namawala')
    cb_serializing.set_param("Simulation_Duration", 365)

    # Create an experiment manager
    exp_manager = ExperimentManagerFactory.init()

    # Set the serialization
    add_SerializationTimesteps(config_builder=cb_serializing,
                               timesteps=[timestep_to_reload],
                               end_at_final=True)

    s_pop_filename = "state-{0:05d}.dtk".format(timestep_to_reload)
    # Run the simulation
    exp_manager.run_simulations(config_builder=cb_serializing,
                                exp_name="Sample serialization test")

    exp_manager.wait_for_finished(verbose=True)

    # Download the state file
    simulation = exp_manager.experiment.simulations[0]
    da = DownloadAnalyzer(filenames=["output\\{}".format(s_pop_filename)],
                          output_path="temp")
    am = AnalyzeManager(sim_list=[simulation], analyzers=[da])
    am.analyze()
if __name__ == "__main__":
    dir = './'
    geography = 'Burkina Faso'
    prefix = 'single_node_simulations'
    exp = 8.60
    exp_name = "insecticide_resistance_single_node_serialization"

    num_years = 40
    num_seeds = 1

    cb = DTKConfigBuilder.from_defaults('MALARIA_SIM',
                                        Simulation_Duration=int(365 *
                                                                num_years))

    update_config_params(cb, direc=dir, geography=geography)
    add_SerializationTimesteps(cb, [num_years * 365], end_at_final=True)

    ########################## VECTOR GENETICS ####################################################

    builder = ModBuilder.from_list([
        [
            ModFn(DTKConfigBuilder.set_param, 'Run_Number', seed),
            ModFn(change_vector_params,
                  species='gambiae',
                  mutation_rate1=mutation_rate,
                  mutation_rate2=mutation_rate,
                  serialization_seed=seed)
        ] for seed in range(num_seeds)
        for mutation_rate in [0]  # pow(10, x) for x in range(-5, 0)
    ])
from simtools.SetupParser import SetupParser
from examples.simple_1node_drug_interventions.configure_sahel_intervention_system import configure_sahel_intervention_system
from dtk.generic.serialization import add_SerializationTimesteps

sim_duration = 1  # in years
num_seeds = 1

serialization_path = './input'

expname = 'single_node_example_with_interventions_serialized_file'

# Initialize and setup config builder
cb = configure_sahel_intervention_system(sim_duration)

builder = GenericSweepBuilder.from_dict({'Run_Number': range(1)})
add_SerializationTimesteps(cb, [60 * 365], end_at_final=True)

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