Skip to content

Commit

Permalink
merged updated upstream and stashed changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Rez GodarzvandChegini authored and Rez GodarzvandChegini committed Oct 22, 2020
1 parent 2886f39 commit f52565b
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 145 deletions.
9 changes: 0 additions & 9 deletions src/covid19sim/human.py
Expand Up @@ -12,13 +12,7 @@
from orderedset import OrderedSet

from covid19sim.utils.mobility_planner import MobilityPlanner
<<<<<<< Updated upstream
from covid19sim.utils.utils import proba_to_risk_fn
from covid19sim.locations.city import PersonalMailboxType
=======
from covid19sim.utils.utils import compute_distance, proba_to_risk_fn
# from covid19sim.locations.city import PersonalMailboxType
>>>>>>> Stashed changes
from covid19sim.locations.hospital import Hospital, ICU
from collections import deque

Expand All @@ -36,11 +30,8 @@
from covid19sim.utils.constants import SECONDS_PER_MINUTE, SECONDS_PER_HOUR, SECONDS_PER_DAY
from covid19sim.utils.constants import NEGATIVE_TEST_RESULT, POSITIVE_TEST_RESULT
from covid19sim.utils.constants import TEST_TAKEN, RISK_LEVEL_UPDATE, SELF_DIAGNOSIS
<<<<<<< Updated upstream
=======
from covid19sim.utils.constants import TAKE_TEST_DUE_TO_SELF_DIAGNOSIS, TAKE_TEST_DUE_TO_RANDOM_REASON, TAKE_TEST_DUE_TO_RECOMMENDATION
from covid19sim.inference.clustering.base import get_cluster_manager_type
>>>>>>> Stashed changes

# if typing.TYPE_CHECKING:
from covid19sim.utils.env import Env
Expand Down
136 changes: 0 additions & 136 deletions src/covid19sim/locations/city.py
Expand Up @@ -184,143 +184,7 @@ def _compute_preferences(self):

def split_locations_into_districts(self, n_districts: int):
"""
<<<<<<< Updated upstream
humans_notified, infections_seeded = False, False
last_day_idx = 0
while True:
current_day = (self.env.timestamp - self.start_time).days
# seed infections and change mixing constants (end of burn-in period)
if (
not infections_seeded
and self.env.timestamp == self.conf['COVID_SPREAD_START_TIME']
):
self._initiate_infection_spread_and_modify_mixing_if_needed()
infections_seeded = True
# Notify humans to follow interventions on intervention day
if (
not humans_notified
and self.env.timestamp == self.conf.get('INTERVENTION_START_TIME')
):
log("\n *** ****** *** ****** *** INITIATING INTERVENTION *** *** ****** *** ******\n", self.logfile)
log(self.conf['INTERVENTION'], self.logfile)
# if its a tracing method, load the class that can compute risk
if self.conf['RISK_MODEL'] != "":
self.tracing_method = get_tracing_method(risk_model=self.conf['RISK_MODEL'], conf=self.conf)
self.have_some_humans_download_the_app()
# initialize everyone from the baseline behavior
for human in self.humans:
human.intervened_behavior.initialize()
if self.tracing_method is not None:
human.set_tracing_method(self.tracing_method)
# log reduction levels
log("\nCONTACT REDUCTION LEVELS (first one is not used) -", self.logfile)
for location_type, value in human.intervened_behavior.reduction_levels.items():
log(f"{location_type}: {value} ", self.logfile)
humans_notified = True
if self.tracing_method is not None:
self.tracker.track_daily_recommendation_levels(set_tracing_started_true=True)
# modify knobs because now people are more aware
if self.conf['ASSUME_NO_ENVIRONMENTAL_INFECTION_AFTER_INTERVENTION_START']:
self.conf['_ENVIRONMENTAL_INFECTION_KNOB'] = 0.0
if self.conf['ASSUME_NO_UNKNOWN_INTERACTIONS_AFTER_INTERVENTION_START']:
self.conf['_MEAN_DAILY_UNKNOWN_CONTACTS'] = 0.0
log("\n*** *** ****** *** ****** *** ****** *** ****** *** ****** *** ****** *** ****** *** ***\n", self.logfile)
# run city testing routine, providing test results for those who need them
# TODO: running this every hour of the day might not be correct.
# TODO: testing budget is used up at hour 0 if its small
self.covid_testing_facility.clear_test_queue()
alive_humans = []
# run non-app-related-stuff for all humans here (test seeking, infectiousness updates)
for human in self.humans:
if not human.is_dead:
human.check_if_needs_covid_test() # humans can decide to get tested whenever
human.check_covid_symptom_start()
human.check_covid_recovery()
human.fill_infectiousness_history_map(current_day)
alive_humans.append(human)
# now, run app-related stuff (risk assessment, message preparation, ...)
prev_risk_history_maps, update_messages = self.run_app(current_day, outfile, alive_humans)
# update messages may not be sent if the distribution strategy (e.g. GAEN) chooses to filter them
self.register_new_messages(
current_day_idx=current_day,
current_timestamp=self.env.timestamp,
update_messages=update_messages,
prev_human_risk_history_maps=prev_risk_history_maps,
new_human_risk_history_maps={h: h.risk_history_map for h in self.humans},
)
# for debugging/plotting a posteriori, track all human/location attributes...
self.tracker.track_humans(hd=self.hd, current_timestamp=self.env.timestamp)
# self.tracker.track_locations() # TODO
yield self.env.timeout(int(duration))
# finally, run end-of-day activities (if possible); these include mailbox cleanups, symptom updates, ...
if current_day != last_day_idx:
alive_humans = [human for human in self.humans if not human.is_dead]
last_day_idx = current_day
if self.conf.get("DIRECT_INTERVENTION", -1) == current_day:
self.conf['GLOBAL_MOBILITY_SCALING_FACTOR'] = self.conf['GLOBAL_MOBILITY_SCALING_FACTOR'] / 2
self.do_daily_activies(current_day, alive_humans)
def do_daily_activies(
self,
current_day: int,
alive_humans: typing.Iterable["Human"],
):
"""Runs all activities that should be completed only once per day."""
# Compute the transition matrix of recommendation levels to
# target distribution of recommendation levels
self.daily_rec_level_mapping = self.compute_daily_rec_level_mapping(current_day)
self.cleanup_global_mailbox(self.env.timestamp)
# TODO: this is an assumption which will break in reality, instead of updating once per day everyone
# at the same time, it should be throughout the day
for human in alive_humans:
human.recover_health() # recover from cold/flu/allergies if it's time
human.catch_other_disease_at_random() # catch cold/flu/allergies at random
human.update_symptoms()
human.increment_healthy_day()
human.check_if_test_results_should_be_reset() # reset test results if its time
human.mobility_planner.send_social_invites()
self.tracker.increment_day()
if self.conf.get("USE_GAEN"):
print(
"cur_day: {}, budget spent: {} / {} ".format(
current_day,
self.sent_messages_by_day.get(current_day, 0),
int(self.conf["n_people"] * self.conf["MESSAGE_BUDGET_GAEN"])
),
)
def run_app(
self,
current_day: int,
outfile: typing.AnyStr,
alive_humans: typing.Iterable["Human"]
) -> typing.Tuple[typing.Dict, typing.List[UpdateMessage]]:
"""Runs the application logic for all humans that are still alive.

The logic is split into three parts. First, 'lightweight' jobs will run. These include
daily risk level initialization, symptoms reporting updates, and digital (binary) contact
tracing (if necessary). Then, if a risk inference model is being used or if we are collecting
training data, batches of humans will be used to do clustering and to call the model. Finally,
the recommendation level of all humans will be updated, they will generate update messages
(if necessary), and the tracker will be updated with the state of all humans.
=======
splits the location objects between district processes
>>>>>>> Stashed changes
"""
self.districts: List[District] = [None] * n_districts
ind: int = 0
Expand Down

0 comments on commit f52565b

Please sign in to comment.