예제 #1
0
 def test_set_parameters_arrays_set_single_value(self):
     p = Parameters(input_households="notset.csv", read_param_file=False, read_hospital_param_file=False)
     assert (
         p.get_param("population_40_49") == 0
     ), "Array memebers not intilialised to zero"
     p.set_param("population_40_49", 400)
     assert (
         p.get_param("population_40_49") == 400
     ), "Did not set pop group to 400"
     assert p.get_param("population_50_59") == 0
예제 #2
0
    def test_update_fatality_fraction(self):
        params = Parameters(
            constant.TEST_DATA_TEMPLATE,
            constant.PARAM_LINE_NUMBER,
            constant.DATA_DIR_TEST,
            constant.TEST_HOUSEHOLD_FILE,
            constant.TEST_HOSPITAL_FILE,
        )
        params.set_param( "n_total", 50000 )
        model = Model(params)
        assert model.get_param("fatality_fraction_80") == 1.0

        model.update_running_params("fatality_fraction_80", 0.6)
        assert model.get_param("fatality_fraction_80") == 0.6
예제 #3
0
 def test_model_total_infected_by_age(self):
     params = Parameters(
         constant.TEST_DATA_TEMPLATE,
         constant.PARAM_LINE_NUMBER,
         constant.DATA_DIR_TEST,
         constant.TEST_HOUSEHOLD_FILE,
     )
     params.set_param( "app_users_fraction", 0.25)
     model = Model(params)
     for _ in range(30):
         model.one_time_step()
     res = model.one_time_step_results()
     for age in AgeGroupEnum:
         assert res.get(f"total_infected{age.name}", None) is not None, f"Could not get total_infected{age.name}"
     assert res.get("total_infected") == sum([res.get(f"total_infected{age.name}") for age in AgeGroupEnum]), "Total infected does not equal sum of age groups"
예제 #4
0
 def test_deaths(self):
     params = Parameters(
         constant.TEST_DATA_TEMPLATE,
         constant.PARAM_LINE_NUMBER,
         constant.DATA_DIR_TEST,
         constant.TEST_HOUSEHOLD_FILE,
         constant.TEST_HOSPITAL_FILE,
     )
     params.set_param( "n_total", 50000);
     model = Model(params)
     daily_deaths = []
     for step in range(50):
         model.one_time_step()
         daily_death = model.one_time_step_results()["daily_death"]
         daily_deaths.append(daily_death)
         assert sum(daily_deaths) == model.one_time_step_results()["total_death"]
     assert sum(daily_deaths) > 0
예제 #5
0
 def test_icu_entry(self):
     params = Parameters(
         constant.TEST_DATA_TEMPLATE,
         constant.PARAM_LINE_NUMBER,
         constant.DATA_DIR_TEST,
         constant.TEST_HOUSEHOLD_FILE,
         constant.TEST_HOSPITAL_FILE,
     )
     params.set_param( "n_total", 50000 )
     model = Model(params)
     daily_critical = []
     for step in range(50):
         model.one_time_step()
         daily_c = model.one_time_step_results()["hospital_to_critical_daily"]
         daily_critical.append(daily_c)
         assert sum(daily_critical) == model.one_time_step_results()["hospital_to_critical_total"]
     assert sum(daily_critical) > 0
예제 #6
0
 def test_hostpital_admissions(self):
     params = Parameters(
         constant.TEST_DATA_TEMPLATE,
         constant.PARAM_LINE_NUMBER,
         constant.DATA_DIR_TEST,
         constant.TEST_HOUSEHOLD_FILE,
         constant.TEST_HOSPITAL_FILE,
     )
     params.set_param( "n_total", 50000 )
     model = Model(params)
     daily_hospitalisations = []
     for step in range(50):
         model.one_time_step()
         daily_h = model.one_time_step_results()["hospital_admissions"]
         daily_hospitalisations.append(daily_h)
         assert sum(daily_hospitalisations) == model.one_time_step_results()["hospital_admissions_total"]
     assert sum(daily_hospitalisations) > 0
예제 #7
0
def basic_example_lockdown_infected_agent():
    params = Parameters("../tests/data/baseline_parameters.csv", 1, ".",
                        "../tests/data/baseline_household_demographics.csv")

    T = 50
    params.set_param("end_time", T)
    params.set_param("n_total", 10000)

    model = simulation.COVID19IBM(model=Model(params))
    agent = LockdownInfectedOnePercent()
    sim = simulation.Simulation(env=model,
                                agent=agent,
                                end_time=T,
                                verbose=True)

    # Run the model for 25 time steps, print output
    sim.steps(25)
    print(sim.results)
예제 #8
0
def basic_example_lockdown_agent():
    params = Parameters("../tests/data/baseline_parameters.csv", 1, ".",
                        "../tests/data/baseline_household_demographics.csv")

    T = 35
    params.set_param("end_time", T)

    model = simulation.COVID19IBM(model=Model(params))
    agent = LockdownAt20()
    sim = simulation.Simulation(env=model,
                                agent=agent,
                                end_time=T,
                                verbose=True)

    # Run the model for 25 time steps, print output
    sim.steps(25)
    print(sim.results)
    model.model.write_output_files()
예제 #9
0
    def test_daily_deaths_by_age(self):
        params = Parameters(
            constant.TEST_DATA_TEMPLATE,
            constant.PARAM_LINE_NUMBER,
            constant.DATA_DIR_TEST,
            constant.TEST_HOUSEHOLD_FILE,
            constant.TEST_HOSPITAL_FILE,
        )
        params.set_param( "n_total", 50000 )
        model = Model(params)
                
        for step in range(50):
            model.one_time_step()
            daily_death = model.one_time_step_results()["daily_death"]

            sum_daily_deaths_by_age = 0
            for age in AgeGroupEnum:
                sum_daily_deaths_by_age += model.one_time_step_results()[f"daily_death{age.name}"]
            assert  daily_death == sum_daily_deaths_by_age
        assert model.one_time_step_results()[f"daily_death{age.name}"] > 0
예제 #10
0
def basic_example_dummy_agent():
    params = Parameters("../tests/data/baseline_parameters.csv", 1, ".",
                        "../tests/data/baseline_household_demographics.csv")

    T = 15
    params.set_param("end_time", T)

    model = simulation.COVID19IBM(model=Model(params))
    agent = simulation.Agent()  # Dummy agent
    sim = simulation.Simulation(env=model,
                                agent=agent,
                                end_time=T,
                                verbose=True)

    # Run the model for 3 time steps, print output
    sim.steps(3)
    print(sim.results)

    # RUn for another 5 time steps, print output
    sim.steps(5)
    print(sim.results)
예제 #11
0
    def test_set_lockdown_multiplier_params(self):
        params = Parameters(
            constant.TEST_DATA_TEMPLATE,
            constant.PARAM_LINE_NUMBER,
            constant.DATA_DIR_TEST,
            constant.TEST_HOUSEHOLD_FILE,
            constant.TEST_HOSPITAL_FILE,
            constant.PARAM_LINE_NUMBER
        )
        params.set_param( "n_total", 50000 )

        model = Model(params)
        assert covid19.get_param_lockdown_on(model.c_params) == 0
        for oc_net in OccupationNetworkEnum:
            model.update_running_params(f"lockdown_occupation_multiplier{oc_net.name}", 0.4)
            assert model.get_param(f"lockdown_occupation_multiplier{oc_net.name}") == 0.4

        for oc_net in OccupationNetworkEnum:
            model.update_running_params(f"lockdown_occupation_multiplier{oc_net.name}", 0.8)
            assert model.get_param(f"lockdown_occupation_multiplier{oc_net.name}") == 0.8

        model.update_running_params("lockdown_house_interaction_multiplier", 1.2)
        assert model.get_param("lockdown_house_interaction_multiplier") == 1.2

        model.update_running_params("lockdown_on", 1)
        assert covid19.get_param_lockdown_on(model.c_params) == 1

        for oc_net in OccupationNetworkEnum:
            model.update_running_params(f"lockdown_occupation_multiplier{oc_net.name}", 0.5)
            assert model.get_param(f"lockdown_occupation_multiplier{oc_net.name}") == 0.5

        model.update_running_params("lockdown_random_network_multiplier", 0.9)
        assert model.get_param("lockdown_random_network_multiplier") == 0.9

        model.update_running_params("lockdown_house_interaction_multiplier", 1.3)
        assert model.get_param("lockdown_house_interaction_multiplier") == 1.3

        assert covid19.get_param_lockdown_on(model.c_params) == 1
예제 #12
0
    def test_set_get_parameters(self):
        """
        Test the a parameter can be changed in between step runs
        """
        # Create model object
        params = Parameters(
            constant.TEST_DATA_TEMPLATE,
            constant.PARAM_LINE_NUMBER,
            constant.DATA_DIR_TEST,
            constant.TEST_HOUSEHOLD_FILE,
        )
        params.set_param("app_users_fraction", 0.25)
        model = Model(params)

        STEPS = 2
        # Run steps
        for step in range(0, STEPS):
            model.one_time_step()
            res = model.one_time_step_results()

            # Try to set valid parameters
            model.update_running_params("test_on_symptoms", 1)
            np.testing.assert_equal(model.get_param("test_on_symptoms"), 1)

            model.update_running_params("test_on_traced", 1)
            np.testing.assert_equal(model.get_param("test_on_traced"), 1)

            model.update_running_params("quarantine_on_traced", 1)
            np.testing.assert_equal(model.get_param("quarantine_on_traced"), 1)

            model.update_running_params("traceable_interaction_fraction", 0.30)
            np.testing.assert_equal(
                model.get_param("traceable_interaction_fraction"), 0.30)

            model.update_running_params("tracing_network_depth", 1)
            np.testing.assert_equal(model.get_param("tracing_network_depth"),
                                    1)

            model.update_running_params("allow_clinical_diagnosis", 1)
            np.testing.assert_equal(
                model.get_param("allow_clinical_diagnosis"), 1)

            model.update_running_params("quarantine_household_on_positive", 1)
            np.testing.assert_equal(
                model.get_param("quarantine_household_on_positive"), 1)

            model.update_running_params("quarantine_household_on_symptoms", 1)
            np.testing.assert_equal(
                model.get_param("quarantine_household_on_symptoms"), 1)

            model.update_running_params(
                "quarantine_household_on_traced_positive", 1)
            np.testing.assert_equal(
                model.get_param("quarantine_household_on_traced_positive"), 1)

            model.update_running_params(
                "quarantine_household_contacts_on_positive", 1)
            np.testing.assert_equal(
                model.get_param("quarantine_household_contacts_on_positive"),
                1,
            )

            model.update_running_params("quarantine_days", 1)
            np.testing.assert_equal(model.get_param("quarantine_days"), 1)

            model.update_running_params("test_order_wait", 1)
            np.testing.assert_equal(model.get_param("test_order_wait"), 1)

            model.update_running_params("test_result_wait", 1)
            np.testing.assert_equal(model.get_param("test_result_wait"), 1)

            model.update_running_params("self_quarantine_fraction", 1)
            np.testing.assert_equal(
                model.get_param("self_quarantine_fraction"), 1)

            # Try to set/get invalid parameters
            with pytest.raises(ModelParameterException):
                model.update_running_params("wrong_parameter", 1)

            with pytest.raises(ModelParameterException):
                model.get_param("wrong_parameter")
예제 #13
0
    def test_set_get_model_parameters(self):
        """
        Test the a parameter can be changed in between step runs
        """
        # Cr.eate model object
        params = Parameters(
            constant.TEST_DATA_TEMPLATE,
            constant.PARAM_LINE_NUMBER,
            constant.DATA_DIR_TEST,
            constant.TEST_HOUSEHOLD_FILE,
            constant.TEST_HOSPITAL_FILE,
            constant.HOSPITAL_PARAM_LINE_NUMBER
        )
        params.set_param( "n_total", 50000 )
        model = Model(params)

        # Run steps
        for step in range(0, STEPS):
            model.one_time_step()

            # Try to set valid model parameters
            model.update_running_params("test_on_symptoms", 1)
            np.testing.assert_equal(model.get_param("test_on_symptoms"), 1)

            model.update_running_params("test_on_traced", 1)
            np.testing.assert_equal(model.get_param("test_on_traced"), 1)

            model.update_running_params("quarantine_on_traced", 1)
            np.testing.assert_equal(model.get_param("quarantine_on_traced"), 1)

            model.update_running_params("traceable_interaction_fraction", 0.30)
            np.testing.assert_equal(
                model.get_param("traceable_interaction_fraction"), 0.30
            )

            model.update_running_params("tracing_network_depth", 1)
            np.testing.assert_equal(model.get_param("tracing_network_depth"), 1)

            model.update_running_params("allow_clinical_diagnosis", 1)
            np.testing.assert_equal(model.get_param("allow_clinical_diagnosis"), 1)

            model.update_running_params("quarantine_household_on_positive", 1)
            np.testing.assert_equal(
                model.get_param("quarantine_household_on_positive"), 1
            )

            model.update_running_params("quarantine_household_on_symptoms", 1)
            np.testing.assert_equal(
                model.get_param("quarantine_household_on_symptoms"), 1
            )

            model.update_running_params("quarantine_household_on_traced_positive", 1)
            np.testing.assert_equal(
                model.get_param("quarantine_household_on_traced_positive"), 1
            )

            model.update_running_params("quarantine_household_contacts_on_positive", 1)
            np.testing.assert_equal(
                model.get_param("quarantine_household_contacts_on_positive"), 1,
            )

            model.update_running_params("quarantine_days", 1)
            np.testing.assert_equal(model.get_param("quarantine_days"), 1)

            model.update_running_params("test_order_wait", 1)
            np.testing.assert_equal(model.get_param("test_order_wait"), 1)

            model.update_running_params("test_result_wait", 1)
            np.testing.assert_equal(model.get_param("test_result_wait"), 1)

            model.update_running_params("self_quarantine_fraction", 1)
            np.testing.assert_equal(model.get_param("self_quarantine_fraction"), 1)

            # Try to set/get array model parameters
            for age in AgeGroupEnum:
                contacts = randrange(1, 10)
                model.update_running_params(f"priority_test_contacts{age.name}", contacts)
                assert model.get_param(f"priority_test_contacts{age.name}") == contacts

            # Try to set/get invalid parameters
            with pytest.raises(ModelParameterException):
                model.update_running_params("wrong_parameter", 1)

            with pytest.raises(ModelParameterException):
                model.get_param("wrong_parameter")
예제 #14
0
 def test_set_age_out_of_range(self):
     p = Parameters(input_households="notset.csv", read_param_file=False, read_hospital_param_file=False)
     with pytest.raises(ParameterException):
         p.set_param("population_80_89", 5000)