Exemple #1
0
def make_base_infectiousness_to_r_job(scenario_name,
                                      city_name,
                                      scale,
                                      param_range,
                                      interventions=None,
                                      num_repetitions=7,
                                      num_rs=0):
    """
    Wraps the inialization of a job that creates a graph of R as a function of base infectiousness value.

    :param scenario_name: name of the run, to use in output directory and output files
    :param city_name: the city name to simulate
    :param scale: city size scale
    :param param_range: list of all the base infectiousness values
    :param interventions: list of interventions to apply during the simulation
    :param num_repetitions: int repetition for each base infectiousness value
    :param num_rs: number of Rs to compute
    :return: ParamChangeRJob
    """
    simple_job = SimpleJob(scenario_name,
                           city_name,
                           scale,
                           interventions=interventions,
                           infection_params=NaiveInitialInfectionParams(20))
    repeated_job = RepeatJob(simple_job, num_repetitions)
    return ParamChangeRJob(repeated_job, ("person", "base_infectiousness"),
                           param_range,
                           num_rs=num_rs)
Exemple #2
0
def test_param_change_base_infectiousness(params):
    """
    Tests that when the base infectiousness is 0, the disease does not spread
    :param params: application params
    :return: True if all the sick people are from the initial set
    """
    params_to_change = {('person', 'base_infectiousness'): 0.0}
    job = SimpleJob("test_base_infectiousness_0", 'kefar yona', 1.0,
                    infection_params=NaiveInitialInfectionParams(10),
                    params_to_change=params_to_change)
    outdir = run([job], verbosity=True, multi_processed=False, with_population_caching=False)
    results = Statistics.load(os.path.join(outdir, 'test_base_infectiousness_0', 'statistics.pkl'))
    total_infected = results.sum_days_data(
        lambda person: person.disease_state != DiseaseState.SUSCEPTIBLE,
        True
    )[-1]
    assert total_infected == 10
Exemple #3
0
def test_param_change_immune_parm(params):
    """
    Tests that when when we immune most od the population at the start of the disease
    they stay Immune and not deased while the simulation
    :param params: application params
    :return: True if the amount of people that are immune to the diease increased while the simulation
    """
    params_to_change = {('person', 'base_infectiousness'): 0.9}
    job = SimpleJob("test_base_infectiousness_0", 'kefar yona', 1.0,
                    infection_params=NaiveInitialInfectionParams(10,per_to_Immune= 0.9),
                    params_to_change=params_to_change)
    outdir = run([job], verbosity=True, multi_processed=False, with_population_caching=False)
    results = Statistics.load(os.path.join(outdir, 'test_base_infectiousness_0', 'statistics.pkl'))
    total_immuned = results.sum_days_data(
        lambda person: person.disease_state == DiseaseState.IMMUNE,
        True
    )[-1]
    assert 0.89 * 23061 <= total_immuned 
Exemple #4
0
def main():
    """
    This is the main function that runs the simulation.
    here we are able to add different intervention, params, and more configurations to the run.
    This is an example for using the code in the project, and running different simulations of the disease.
    """
    # sets the logging output to be at debug level, meaning more output than a regular run
    logging.basicConfig(format='%(levelname)s:%(message)s',
                        level=logging.DEBUG)

    scenarios = {
        # "scenario_1": scenario_1_interventions,
        # "scenario_21": scenario_21_interventions,
        # "scenario_22": scenario_22_interventions,
        # "scenario_23": scenario_23_interventions,
        # "scenario_24": scenario_24_interventions,
        # "scenario_25": scenario_25_interventions,
        # "scenario_26": scenario_26_interventions,
        # "scenario_232": scenario_232_interventions,
        # "scenario_262": scenario_262_interventions,
        # "scenario_272": scenario_272_interventions,
        # "scenario_282": scenario_282_interventions,
        # "scenario_36": scenario_36_interventions,
        # "scenario_39": scenario_39_interventions,
        # "scenario_365": scenario_365_interventions,
        # "scenario_395": scenario_395_interventions
        #"reality1" : scenario_reality1
        #"check" : scenario_check
        #"reality2" : scenario_reality2
        #"reality3": scenario_reality3
        #"reality4": scenario_reality4
        #"no_interventions": no_interventions
        #"not_relaxing_interventions": not_relaxing_interventions
        #"grant_time1" : grant_time1,
        #"grant_time2" : grant_time2
        "paper_1": paper_1
        #"paper_2" : paper_2
        #"paper_3" : paper_3
        #"paper_4" : paper_4
        #"paper_5": paper_5
        #"paper_6": paper_6
        #"paper_7": paper_7
        #"paper_8": paper_8
        #"paper_2_comp_9": paper_2_comp_9
    }

    datas_to_plot = get_datas_to_plot()

    # choosing the city and the scale of the run:
    # the city name and scale determine the city and the size proportion to take (use 'all' for entire country)
    # city_name, scale = 'holon', 1
    # city_name, scale = 'all', 0.01 # This means loading 1% of the entire country
    # city_name, scale = 'all', 0.1 # This means loading the entire country
    print("Running all simulations...")
    config_path = os.path.join(os.path.dirname(__file__), "config.json")
    with open(config_path) as json_data_file:
        ConfigData = json.load(json_data_file)
        paramsDataPath = ConfigData['ParamsFilePath']

    Params.load_from(os.path.join(os.path.dirname(__file__), paramsDataPath),
                     override=True)

    # we build a list of the jobs to run:
    # each job can be run as a different process, and the population generation will be done once
    # if caching option is on

    jobs = []
    for initial_percentage_immune in [0.0, 0.5]:
        for initial_num_infected in [25, 100, 250, 500]:
            for city_name, scale in [("Holon", 1), ("Bene Beraq", 1)]:
                for compliance in [0.8]:
                    for ci_delay in [4]:
                        for hi_delay in [4]:
                            for symptomatic_probs_scale in [1]:
                                for scenario_name, intervention_scheme in scenarios.items(
                                ):
                                    params_to_change = {
                                        ('disease_parameters', 'symptomatic_given_infected_per_age'):
                                        get_rescaled_symptomatic_probs(
                                            symptomatic_probs_scale)
                                    }
                                    full_scenario_name = generate_scenario_name(
                                        city_name, scenario_name,
                                        initial_num_infected,
                                        initial_percentage_immune, compliance,
                                        ci_delay, hi_delay,
                                        symptomatic_probs_scale)
                                    #                                    full_scenario_name = "res"
                                    jobs.append(
                                        RepeatJob(
                                            SimpleJob(
                                                full_scenario_name,
                                                days=180,
                                                city_name=city_name,
                                                scale=scale,
                                                infection_params=
                                                NaiveInitialInfectionParams(
                                                    initial_num_infected,
                                                    per_to_Immune=
                                                    initial_percentage_immune),
                                                #infection_params=SmartInitialInfectionParams(initial_num_infected, round(initial_num_infected/10)),
                                                params_to_change=
                                                params_to_change,
                                                interventions=
                                                intervention_scheme(
                                                    compliance, ci_delay,
                                                    hi_delay),
                                                datas_to_plot=datas_to_plot),
                                            num_repetitions=50))

    # add job to make r to base infectiousness graph:
    # jobs += [make_base_infectiousness_to_r_job('r_graph_default', city_name, scale,
    #                                            [0.03, 0.06, 0.1, 0.13, 0.16, 0.2],
    #                                            interventions=ci_sde,num_repetitions=3)]

    # this start the run of the jobs
    run(jobs,
        multi_processed=True,
        with_population_caching=False,
        verbosity=False)