示例#1
0
def test_all_country_simulation_slow():
    """
    Runs a simulation on 10% of the entire country.
    This takes a while, so it's marked as "slow" (and should be run nightly rather than on every commit)
    """
    job = SimpleJob("test_default_all_0.1", 'all', 0.1)
    run([job])
示例#2
0
def test_simple_simulation_multi():
    """
    Runs 3 simulations of the disease multi processed
    """
    jobs = [SimpleJob("test_default", 'kefar yona', 1.0), SimpleJob("test_default2", 'kefar yona', 1.0),
            SimpleJob("test_default3", 'kefar yona', 1.0)]
    run(jobs, multi_processed=True)
示例#3
0
def test_household_isolation_intervention_simulation(hi_exit):
    """
    Tests that when asymptomatic and presymptomatic people are not infectious and household isolation occur with no delay,
    all the poeple that are infected are infected at home (of at the beginning), due to the household isolation
    :param hi_exit: params that make sure there are no delay or too short of isolation
    :return: None (since this is a test), but it is asserted that all infections occur within the household
    """
    scenario_name = "test_HI"
    params_to_change = {
        ("disease_parameters", "infectiousness_per_stage", "incubating_post_latent"):
        0.0,
        ("disease_parameters", "infectiousness_per_stage", "asymptomatic"):
        0.0
    }
    delay_on_exit, is_exit_after_recovery = hi_exit
    job = SimpleJob(scenario_name,
                    city_name='kefar yona',
                    interventions=[
                        HouseholdIsolationIntervention(
                            compliance=1,
                            start_date=INITIAL_DATE,
                            duration=timedelta(250),
                            delay_on_enter=0,
                            delay_on_exit=delay_on_exit,
                            is_exit_after_recovery=is_exit_after_recovery)
                    ],
                    scale=1.0,
                    params_to_change=params_to_change,
                    infection_params=SmartInitialInfectionParams(100, 50))
    outdir = run([job], multi_processed=False, with_population_caching=False)
    results = Statistics.load(
        os.path.join(outdir, scenario_name, 'statistics.pkl'))
    summary = results.get_summary_data_for_age_group((0, 99))
    assert summary["Total infected in household"] + summary[
        "Total infected in initial_group"] == summary["Total infected"]
示例#4
0
def test_R0Big():
    """
    In case of R0 is much larger there shouled be a pandemic but not all of citizens
    will get cought
    R0 is computed by Beta/Gama where:
    Beta = m*p (number of interaction * probebility of infection)
    Gama = 1/d (d days where person is sick)
    """
    scenario_name = "test_NoInfection"
    params_to_change = {
        ("disease_parameters", "infectiousness_per_stage", "incubating_post_latent"):
        1,
        ("disease_parameters", "infectiousness_per_stage", "asymptomatic"):
        1,
        ("disease_parameters", "infectiousness_per_stage", "symptomatic"):
        1,
        ("disease_parameters", "infectiousness_per_stage", "critical"):
        1
    }
    jobs = [
        SimpleJob(scenario_name,
                  'kefar yona',
                  1.0,
                  params_to_change=params_to_change)
    ]
    outdir = run(jobs,
                 verbosity=True,
                 multi_processed=False,
                 with_population_caching=False)
    results = Statistics.load(
        os.path.join(outdir, scenario_name, 'statistics.pkl'))
    total_infected = results.sum_days_data(
        lambda person: person.disease_state != DiseaseState.
        SYMPTOMATICINFECTIOUS, True)[-1]
示例#5
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
示例#6
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 
示例#7
0
def test_school_closure_intervention_simulation():
    """
    Test that when school isolation is on, no one is infected at school.
    :return: True is there are 0 infections at school
    """
    scenario_name = "test_PC"
    job = SimpleJob(scenario_name,
                    city_name='kefar yona',
                    interventions=[
                        SchoolClosureIntervention(start_date=INITIAL_DATE,
                                                  duration=timedelta(250),
                                                  compliance=1.0,
                                                  proportion_of_envs=1.0,
                                                  city_name='kefar yona',
                                                  age_segment=(0, 9))
                    ],
                    scale=1.0,
                    infection_params=SmartInitialInfectionParams(100, 50))
    outdir = run([job], multi_processed=False, with_population_caching=False)
    results = Statistics.load(
        os.path.join(outdir, scenario_name, 'statistics.pkl'))
    summary = results.get_summary_data_for_age_group((0, 9))
    assert summary["Total infected in school"] == 0
示例#8
0
def test_school_isolation_intervention_simulation():
    """
    Test that when school isolation is on, all the relevant people are infected only at shool
    """
    scenario_name = "test_PI"
    job = SimpleJob(scenario_name,
                    city_name='kefar yona',
                    interventions=[
                        SchoolIsolationIntervention(start_date=INITIAL_DATE,
                                                    duration=timedelta(250),
                                                    compliance=1.0,
                                                    proportion_of_envs=1.0,
                                                    city_name='kefar yona',
                                                    age_segment=(4, 12))
                    ],
                    scale=1.0,
                    infection_params=SmartInitialInfectionParams(100, 50))
    outdir = run([job], multi_processed=False, with_population_caching=False)
    results = Statistics.load(
        os.path.join(outdir, scenario_name, 'statistics.pkl'))
    summary = results.get_summary_data_for_age_group((4, 12))
    assert summary["Total infected in school"] + summary[
        "Total infected in initial_group"] == summary["Total infected"]
示例#9
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)
示例#10
0
def test_simple_simulation_single():
    """
    Runs the simple simulation of the disease on kefar yone (a city with about 20,000 people)
    """
    jobs = [SimpleJob("test_default", 'kefar yona', 1.0)]
    run(jobs, multi_processed=False)
示例#11
0
def test_simulation_haifa():
    """
    Runs Haifa simulation of the disease
    """
    job = SimpleJob("test_default_haifa", 'haifa', 1.0)
    run([job])
示例#12
0
def test_mini_all_country_simulation():
    """
    Runs a simulation on 3% of the entire country
    """
    job = SimpleJob("test_default_all_0.03", 'all', 0.03)
    run([job])