Esempio n. 1
0
    def get(self):
        query = Parameters.query()
        parameters = query.fetch(limit=None)

        if parameters is None or len(parameters) == 0:
            p = Parameters(name="ADE Project", value="TELECOM Nancy")
            p.put()
            query = Parameters.query()
            parameters = query.fetch(limit=None)
            time.sleep(1)

        self.render("administration_parameters.html", parameters=parameters)
Esempio n. 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
Esempio n. 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"
Esempio n. 4
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,
        )
        model = Model(params)
        assert covid19.get_param_lockdown_on(model.c_params) == 0

        model.update_running_params("lockdown_work_network_multiplier", 0.4)
        assert model.get_param("lockdown_work_network_multiplier") == 0.4

        model.update_running_params("lockdown_random_network_multiplier", 0.8)
        assert model.get_param("lockdown_random_network_multiplier") == 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

        model.update_running_params("lockdown_work_network_multiplier", 0.5)
        assert model.get_param("lockdown_work_network_multiplier") == 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
Esempio n. 5
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
Esempio n. 6
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
Esempio n. 7
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
Esempio n. 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()
Esempio n. 9
0
def get_sim_parameters():
    sim_params = Parameters()
    sim_params.t0 = 0
    sim_params.tf = 10
    sim_params.dt = 0.04
    sim_params.x0 = [0, 0, 0]
    sim_params.xf = [5, 5, 0]
    return sim_params
Esempio n. 10
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
Esempio n. 11
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)
Esempio n. 12
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
Esempio n. 13
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
Esempio n. 14
0
def get_traj_parameters():
    sim_params = get_sim_parameters()

    traj_params = Parameters()
    traj_params.t0 = sim_params.t0 + 1
    traj_params.tf = sim_params.tf - 1

    # boundary conditions for y1
    traj_params.Y1A = np.array([sim_params.x0[0], 0])
    traj_params.Y1B = np.array([sim_params.xf[0], 0])

    # boundary conditions for y2
    traj_params.Y2A = np.array([sim_params.x0[1], tan(sim_params.x0[2]), 0])
    traj_params.Y2B = np.array([sim_params.xf[1], tan(sim_params.xf[2]), 0])

    return traj_params
Esempio n. 15
0
 def test_hostpital_admissions(self):
     params = Parameters(
         constant.TEST_DATA_TEMPLATE,
         constant.PARAM_LINE_NUMBER,
         constant.DATA_DIR_TEST,
         constant.TEST_HOUSEHOLD_FILE,
     )
     model = Model(params)
     daily_hospitalisations = []
     daily_critical = []
     for step in range(10):
         model.one_time_step()
         daily_h = model.one_time_step_results()["hospital_admissions"]
         daily_c = model.one_time_step_results()["hospital_to_critical_daily"]
         daily_hospitalisations.append(daily_h)
         daily_critical.append(daily_c)
         assert sum(daily_hospitalisations) == model.one_time_step_results()["hospital_admissions_total"]
         assert sum(daily_critical) == model.one_time_step_results()["hospital_to_critical_total"]
Esempio n. 16
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)
Esempio n. 17
0
 def test_set_parameters_arrays_init_to_zero(self):
     p = Parameters(input_households="notset.csv", read_param_file=False, read_hospital_param_file=False)
     assert p.get_param("population_40_49") == 0
Esempio n. 18
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)
Esempio n. 19
0
hyperparams_dict["dataset"] = 'metr-la'
hyperparams_dict["horizon"] = 12
hyperparams_dict["history_length"] = 12

print("*********************************")
print("LOADING DATA")
print("*********************************")

dataset = Dataset(name=hyperparams_dict["dataset"],
                  horizon=hyperparams_dict["horizon"],
                  history_length=hyperparams_dict["history_length"],
                  path=DATADIR)

hyperparams_dict["num_nodes"] = dataset.num_nodes
hyperparams = Parameters(**hyperparams_dict)

print("*********************************")
print("TRAINING MODELS")
print("*********************************")

trainer = Trainer(hyperparams=hyperparams, logdir=LOGDIR)
trainer.fit(dataset=dataset)

print("*********************************")
print("COMPUTING METRICS")
print("*********************************")

early_stop_mae_h_repeats = dict()
early_stop_mape_h_repeats = dict()
early_stop_rmse_h_repeats = dict()
Esempio n. 20
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")
Esempio n. 21
0
from typing import Union
from constants import Constants

app = Flask(__name__)

database = Database(
    os.environ[Constants.DATABASE_URL],
    os.environ[Constants.DATABASE_REPLICA_SET],
    int(os.environ[Constants.DATABASE_PORT]),
    os.environ[Constants.DATABASE_NAME],
)

request_validator = UserRequest(database)
storage = ObjectStorage(database)
data = Data(database, storage)
parameters_handler = Parameters(database, data)


@app.route("/defaultModel", methods=["POST"])
def create_default_model() -> jsonify:
    service_type = request.args.get(Constants.TYPE_PARAM_NAME)

    model_name = request.json[Constants.MODEL_FIELD_NAME]
    description = request.json[Constants.DESCRIPTION_FIELD_NAME]
    module_path = request.json[Constants.MODULE_PATH_FIELD_NAME]
    class_name = request.json[Constants.CLASS_FIELD_NAME]
    class_parameters = request.json[Constants.FUNCTION_PARAMETERS_NAME]

    request_errors = analyse_post_request_errors(
        request_validator,
        model_name,
Esempio n. 22
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")
Esempio n. 23
0
def get_controller_params():
    k = Parameters()
    k.k01 = 1
    k.k02 = 1
    k.k12 = 5
    return k