Пример #1
0
    def commission_iteration(self, next_params):
        """
        Commission an experiment of simulations constructed from a list of combinations of
        random seeds, calibration sites, and the next sample points.
        Cache the relevant experiment and simulation information to the IterationState.
        """
        if self.simulations:
            logger.info(
                'Reloading simulation data from cached iteration (%s) state.' %
                self.iteration)
            self.exp_manager = ExperimentManagerFactory.from_experiment(
                DataStore.get_experiment(self.experiment_id))
        else:
            self.exp_manager = ExperimentManagerFactory.init()

            # use passed in function to create exp_builder
            exp_builder = self.exp_builder_func(next_params)

            self.exp_manager.run_simulations(
                config_builder=self.config_builder,
                exp_name='%s_iter%d' % (self.calibration_name, self.iteration),
                exp_builder=exp_builder,
                suite_id=self.suite_id)

            self.simulations = self.exp_manager.experiment.toJSON(
            )['simulations']
            self.experiment_id = self.exp_manager.experiment.exp_id
            self.save()
Пример #2
0
def run(args, unknownArgs):
    # get simulation-running instructions from script
    mod = args.loaded_module

    # Make sure we have run_sim_args
    if not hasattr(mod, 'run_sim_args'):
        if hasattr(mod, 'run_calib_args'):
            print(
                "The module you are trying to run seems to contain a calibration script and should be ran with the "
                "`calibtool run` command.")
            exit()

        print(
            "You are trying to run a module without the required run_sim_args dictionary."
        )
        print("The run_sim_args is expected to be of the format:")
        print(
            json.dumps(
                {
                    "config_builder": "cb",
                    "exp_name": "Experiment_name",
                    "exp_builder": "Optional builder"
                },
                indent=3))
        exit()

    # Assess arguments.
    mod.run_sim_args['blocking'] = True if args.blocking else False
    mod.run_sim_args['quiet'] = True if args.quiet else False

    # Create the experiment manager
    exp_manager = ExperimentManagerFactory.init()
    exp_manager.run_simulations(**mod.run_sim_args)
    return exp_manager
Пример #3
0
def run_experiment(configbuilder, experiment_name, experiment_builder,
                   analyzers):
    run_sim_args = {
        'config_builder': configbuilder,
        'exp_name': experiment_name,
        'exp_builder': experiment_builder
    }

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

    exp_manager = ExperimentManagerFactory.init()
    exp_manager.run_simulations(**run_sim_args)
    exp_manager.wait_for_finished(verbose=True)
    assert (exp_manager.succeeded())
    am = AnalyzeManager(exp_manager.experiment)
    for a in analyzers:
        am.add_analyzer(a)
    am.analyze()
# listening_duration of -1 indicates that this intervention will listen forever and perform the tasks whenever Action1 is sent out
add_node_IRS(cb, 30, trigger_condition_list=["Party"], listening_duration=-1)

# this intervention is distributed and starts listening on day 60, but distributes the IRS 1000 days after it is triggered
# please note if the listening duration was less than triggered day + campaign delay, the intervention would not run.
add_node_IRS(cb,
             60,
             triggered_campaign_delay=1000,
             trigger_condition_list=["PartyHarder"])

# listens for 15 days and, as the result, hears nothing and does nothing.
add_node_IRS(cb,
             60,
             trigger_condition_list=["PartyHarder"],
             listening_duration=15)

# run_sim_args is what the `dtk run` command will look for
run_sim_args = {
    'exp_name': 'Example Event Counter and Triggered and Delayed IRS',
    'config_builder': cb
}

# If you prefer running with `python example_example_event_count_and_triggered_events.py`, you will need the
# following block
if __name__ == "__main__":
    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)
    assert (exp_manager.succeeded())
Пример #5
0
        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.
# When present the `analyzers` variable is an array of Analyzers that will be executed when
# the command `dtk analyze larvicides_campaign.py` is called.
# Here we are using a simple TimeSeriesAnalyzer, grouping the simulations by the larvicide_start tag (averaging
# across the Run_Number). And displaying the results for 3 vector related channels.
analyzers = [
    TimeseriesAnalyzer(group_function=group_by_name('larvicide_start'),
                       channels=['Daily EIR', 'Adult Vectors', 'Infected'])
]

if __name__ == "__main__":
    SetupParser.init()
    em = ExperimentManagerFactory.init()
    em.run_simulations(**run_sim_args)
    em.wait_for_finished(verbose=True)
    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
Пример #7
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')