Beispiel #1
0
def test__move_people_to_leisure(sim: Simulator):
    n_leisure = 0
    n_cinemas = 0
    n_pubs = 0
    n_groceries = 0
    repetitions = 500
    for _ in range(repetitions):
        sim.clear_world()
        sim.activity_manager.move_people_to_active_subgroups(
            ["leisure", "residence"])
        for person in sim.world.people.members:
            if person.leisure is not None:
                n_leisure += 1
                if person.leisure.group.spec == "care_home":
                    assert person.leisure.subgroup_type == 2  # visitors
                elif person.leisure.group.spec == "cinema":
                    n_cinemas += 1
                elif person.leisure.group.spec == "pub":
                    n_pubs += 1
                elif person.leisure.group.spec == "grocery":
                    n_groceries += 1
                # print(f'There are {len(person.leisure.people)} in this group')
                assert person in person.leisure.people
    assert n_leisure > 0
    assert n_cinemas > 0
    assert n_pubs > 0
    assert n_groceries > 0
    sim.clear_world()
Beispiel #2
0
def test__clear_world(sim: Simulator):
    sim.clear_world()
    for group_name in sim.activity_manager.activities_to_groups(
            sim.activity_manager.all_activities):
        if group_name in ["household_visits", "care_home_visits"]:
            continue
        grouptype = getattr(sim.world, group_name)
        for group in grouptype.members:
            for subgroup in group.subgroups:
                assert len(subgroup.people) == 0

    for person in sim.world.people.members:
        assert person.busy == False
def test__infection_is_isolated(selector):
    geography = Geography.from_file({"area": ["E00002559"]})
    world = generate_world_from_geography(geography, include_households=True)
    interaction = Interaction.from_file()
    infection_seed = InfectionSeed(world.super_areas, selector)
    n_cases = 5
    infection_seed.unleash_virus(
        n_cases)  # play around with the initial number of cases
    policies = Policies([])
    simulator = Simulator.from_file(
        world=world,
        interaction=interaction,
        infection_selector=selector,
        config_filename=pathlib.Path(__file__).parent.absolute() /
        "interaction_test_config.yaml",
        leisure=None,
        policies=policies,
        save_path=None,
    )
    infected_people = [person for person in world.people if person.infected]
    assert len(infected_people) == 5
    infected_households = []
    for household in world.households:
        infected = False
        for person in household.people:
            if person.infected:
                infected = True
                break
        if infected:
            infected_households.append(household)
    assert len(infected_households) <= 5
    simulator.run()
    for person in world.people:
        if not (person.residence.group in infected_households):
            assert not person.infected and person.susceptible
Beispiel #4
0
def make_policy_simulator(dummy_world, interaction, selector):
    config_name = paths.configs_path / "tests/test_simulator_simple.yaml"
    sim = Simulator.from_file(
        dummy_world,
        interaction,
        infection_selector=selector,
        config_filename=config_name,
        save_path=None,
        policies=None,
        leisure=None,
    )
    return sim
Beispiel #5
0
 def generate_simulator(self):
     domain = self.generate_domain()
     health_index_generator = self.generate_health_index_generator()
     infection_selector = self.generate_infection_selector(
         health_index_generator=health_index_generator)
     interaction = self.generate_interaction(
         baseline_interaction_path=self.paths["baseline_interaction_path"],
         population=domain.people,
     )
     leisure = self.generate_leisure(domain=domain)
     travel = self.generate_travel()
     policies = self.generate_policies()
     record = self.generate_record()
     record.static_data(world=domain)
     infection_seed = self.generate_infection_seed(
         world=domain,
         infection_selector=infection_selector,
     )
     record.meta_information(
         comment=self.purpose_of_the_run,
         random_state=self.random_seed,
         number_of_cores=mpi_size,
     )
     simulator = Simulator.from_file(
         world=domain,
         interaction=interaction,
         config_filename=self.paths["simulation_config_path"],
         leisure=leisure,
         travel=travel,
         infection_seed=infection_seed,
         infection_selector=infection_selector,
         policies=policies,
         record=record,
     )
     # change number of days, this can only be done like this for now
     simulator.timer.total_days = self.n_days
     simulator.timer.final_date = simulator.timer.initial_date + datetime.timedelta(
         days=self.n_days)
     return simulator
Beispiel #6
0
def create_sim(world, interaction, selector):

    leisure_instance = leisure.generate_leisure_for_config(
        world=world, config_filename=test_config)
    leisure_instance.distribute_social_venues_to_households(world.households)
    policies = Policies([
        Quarantine(n_days=5),
        Quarantine(n_days=10),
        CloseLeisureVenue(start_time="2020-3-1",
                          end_time="2020-3-30",
                          venues_to_close=['pub', 'cinema'])
    ])
    infection_seed = InfectionSeed(super_areas=world.super_areas,
                                   selector=selector)
    n_cases = 2
    infection_seed.unleash_virus(n_cases)

    sim = Simulator.from_file(world=world,
                              interaction=interaction,
                              infection_selector=selector,
                              config_filename=test_config,
                              leisure=leisure_instance,
                              policies=policies)
    return sim
Beispiel #7
0
def test__move_people_to_residence(sim: Simulator):
    sim.activity_manager.move_people_to_active_subgroups(["residence"])
    for person in sim.world.people.members:
        assert person in person.residence.people
    sim.clear_world()
Beispiel #8
0
    communals=world.communals
)
leisure_instance.leisure_distributors[
    "female_communals"
] = FemaleCommunalDistributor.from_config(female_communals=world.female_communals)

# associate social activities to shelters
leisure_instance.distribute_social_venues_to_households(world.shelters)

# ==================================================================================#

# =================================== simulator ===============================#
Simulator.ActivityManager = CampActivityManager
simulator = Simulator.from_file(
    world=world,
    interaction=interaction,
    leisure=leisure_instance,
    policies=policies,
    config_filename=CONFIG_PATH,
    infection_selector=selector,
    save_path="results_no_comorbidities"
)

leisure_instance.leisure_distributors

simulator.timer.reset()

simulator.run()

# ==================================================================================#
leisure.distribute_social_venues_to_areas(world.areas, world.super_areas)

# ==================================================================================#

# =================================== simulator ===============================#

# records
record = Record(record_path=args.save_path, record_static_data=True)
record.static_data(world=world)

Simulator.ActivityManager = CampActivityManager
simulator = Simulator.from_file(
    world=world,
    interaction=interaction,
    leisure=leisure,
    policies=policies,
    config_filename=CONFIG_PATH,
    infection_selector=selector,
    record=record,
)

leisure.leisure_distributors

simulator.timer.reset()

simulator.run()

# ==================================================================================#

# =================================== read logger ===============================#