Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Nov 18, 2024
1 parent b20cd07 commit aa6dbff
Show file tree
Hide file tree
Showing 21 changed files with 67 additions and 8 deletions.
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@


def setup(app):

def skip(app, what, name, obj, skip, options):
members = [
'__init__',
Expand Down
1 change: 1 addition & 0 deletions episimmer/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class Agent():
state: The state of the agent.
info_dict: Information of each agent taken from the agents file.
"""

def __init__(self, state: Union[str, None], info_dict: Dict[str, str]):
self.state: Union[str, None] = state
self.next_state: Union[str, None] = None
Expand Down
1 change: 1 addition & 0 deletions episimmer/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class Location():
Args:
info_dict: Information of each location taken from the locations file .
"""

def __init__(self, info_dict: Dict[str, str]):
self.info: Dict[str, str] = info_dict
self.index: str = info_dict['Location Index']
Expand Down
3 changes: 3 additions & 0 deletions episimmer/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class BaseModel():
Args:
name: Name of Disease Model
"""

def __init__(self, name: str):
self.name: str = name

Expand Down Expand Up @@ -380,6 +381,7 @@ def __init__(self):
infected_states: The states that are infectious
state_proportion: Starting proportions of each state
"""

def __init__(self, individual_state_types: List[str],
infected_states: List[str],
state_proportion: Dict[str, Union[float, int]]):
Expand Down Expand Up @@ -750,6 +752,7 @@ def __init__(self):
self.set_event_contribution_fn(event_contribute_fn)
self.set_event_receive_fn(event_receive_fn)
"""

def __init__(self):
super().__init__('Scheduled Model')
self.individual_state_types: List[str] = []
Expand Down
3 changes: 3 additions & 0 deletions episimmer/policy/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Policy():
Args:
policy_type: Type of Agent Policy
"""

def __init__(self, policy_type: str):
self.policy_type: str = policy_type

Expand Down Expand Up @@ -67,6 +68,7 @@ class AgentPolicy(Policy):
Args:
policy_type: Type of Agent Policy
"""

def __init__(self, policy_type: str):
super().__init__(policy_type)

Expand Down Expand Up @@ -124,5 +126,6 @@ class EventPolicy(Policy):
Args:
policy_type: Type of Event Policy
"""

def __init__(self, policy_type: str):
super().__init__(policy_type)
2 changes: 2 additions & 0 deletions episimmer/policy/contact_tracing_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class ContactList():
"""
Class built to implement an ordered and unique list of contacts
"""

def __init__(self):
self.contacts: List[str] = []

Expand Down Expand Up @@ -94,6 +95,7 @@ def generate_policy():
attribute : Parameter (attribute) type of agents
value_list: List of attribute values of agents
"""

def __init__(self,
num_of_days: int,
attribute: Union[str, None] = None,
Expand Down
6 changes: 6 additions & 0 deletions episimmer/policy/lockdown_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class AgentLockdownPolicy(AgentPolicy):
do_lockdown_fn: User-defined function to specify which time step(s) to enforce lockdown in
p: Probability of agent to contribute and receive infection from any source of infection under lockdown
"""

def __init__(self, do_lockdown_fn: Callable, p: float):
super().__init__('Restrict')
self.do_lockdown_fn: Callable = do_lockdown_fn
Expand Down Expand Up @@ -64,6 +65,7 @@ def lockdown_fn(time_step):
do_lockdown_fn: User-defined function to specify which time step(s) to enforce lockdown in
p: Probability of agent to contribute and receive infection from any source of infection under lockdown
"""

def __init__(self, do_lockdown_fn: Callable, p: float = 0.0):
super().__init__(do_lockdown_fn, p)

Expand Down Expand Up @@ -119,6 +121,7 @@ def lockdown_fn(time_step):
do_lockdown_fn: User-defined function to specify which time step(s) to enforce lockdown in
p: Probability of agent to contribute and receive infection from any source of infection under lockdown
"""

def __init__(self,
attribute: str,
value_list: List[str],
Expand Down Expand Up @@ -209,6 +212,7 @@ def generate_policy():
contact_tracing: Boolean specifying whether lockdown for contacts of positively tested agents is enabled or not
p: Probability of agent to contribute and receive infection from any source of infection under lockdown
"""

def __init__(self,
do_lockdown_fn: Callable,
lockdown_period: int,
Expand Down Expand Up @@ -290,6 +294,7 @@ class EventLockdownPolicy(EventPolicy):
do_lockdown_fn: User-defined function to specify which time step(s) to enforce lockdown in
p: Probability of an event occurring during lockdown
"""

def __init__(self, do_lockdown_fn: Callable, p: float):
super().__init__('Restrict')
self.do_lockdown_fn: Callable = do_lockdown_fn
Expand Down Expand Up @@ -334,6 +339,7 @@ def generate_policy():
do_lockdown_fn: User-defined function to specify which time step(s) to enforce lockdown in
p: Probability of an event occurring during lockdown
"""

def __init__(self,
attribute: str,
value_list: List[str],
Expand Down
4 changes: 4 additions & 0 deletions episimmer/policy/testing_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class TestResult():
time_step_done: Time step machine completed test
valid_period: Number of time steps the test is considered to be valid
"""

def __init__(self, result: str, agent: Agent, machine_name: str,
time_step: int, machine_start_step: int, time_step_done: int,
valid_period: int):
Expand Down Expand Up @@ -69,6 +70,7 @@ class TestTube():
"""
Class for a Testtube.
"""

def __init__(self):
self.testtube_agent_dict: Dict[Agent, Dict[str, Union[str, int]]] = {}
self.testtube_result: Union[str, None] = None
Expand Down Expand Up @@ -154,6 +156,7 @@ class Machine():
capacity: Capacity of the machine for tests
valid_period: Number of time steps the test is considered to be valid
"""

def __init__(self, machine_name: str, cost: int,
false_positive_rate: float, false_negative_rate: float,
turnaround_time: int, capacity: int, valid_period: int):
Expand Down Expand Up @@ -423,6 +426,7 @@ def generate_policy():
Args:
agents_per_step_fn: User-defined function to specify the number of agents to test per time step
"""

def __init__(self, agents_per_step_fn: Callable):
super().__init__('Testing')
self.register_agent_testtube_func: Union[Callable, None] = None
Expand Down
11 changes: 7 additions & 4 deletions episimmer/policy/vaccination_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class VaccineResult():
decay_days: Number of days of protection offered by the vaccine
current_dose: The dose of the vaccine administered to the agent
"""

def __init__(self, vaccine_name: str, agent: Agent, result: str,
time_step: int, efficacy: float, decay_days: int,
current_dose: int):
Expand Down Expand Up @@ -57,6 +58,7 @@ class VaccineType():
interval: List specifying minimum days to pass before the administration of the next dose, for each dose of a
multi-dose vaccine
"""

def __init__(self,
name: str,
cost: int,
Expand Down Expand Up @@ -154,6 +156,7 @@ def generate_policy():
Args:
agents_per_step_fn: User-defined function to specify the number of agents to vaccinate per time step
"""

def __init__(self, agents_per_step_fn: Callable):
super().__init__('Vaccination')

Expand Down Expand Up @@ -437,10 +440,10 @@ def full_multi_dose_vaccination(self, attribute: Union[str, None],
and lh.vaccine_name in self.available_vaccines
and self.available_vaccines[lh.vaccine_name]['type']
== 'Multi'):
if (lh.current_dose <
self.available_vaccines[lh.vaccine_name]['dose']
and time_step - lh.time_stamp >=
self.available_vaccines[lh.vaccine_name]
if (lh.current_dose
< self.available_vaccines[lh.vaccine_name]['dose']
and time_step - lh.time_stamp
>= self.available_vaccines[lh.vaccine_name]
['interval'][lh.current_dose - 1]):
current_vaccine = None
for vaccine in self.vaccines:
Expand Down
10 changes: 10 additions & 0 deletions episimmer/read_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class ReadConfiguration():
Args:
filename: Name of the directory containing simulation files
"""

def __init__(self, filename: str):

self.filename: str = filename
Expand Down Expand Up @@ -246,6 +247,7 @@ class ReadVDConfiguration():
Args:
filename: Name of the directory containing simulation files
"""

def __init__(self, filename: str):
self.filename: str = filename
self.example_path: str = osp.dirname(filename)
Expand Down Expand Up @@ -320,6 +322,7 @@ class ReadFilesList():
Args:
filename: Name of the files list file
"""

def __init__(self, filename: str):
self.filename: str = filename
self.file_list: List[str] = []
Expand All @@ -345,6 +348,7 @@ class BaseReadFile():
"""
Base class for reading agents, locations, interactions and events from a file.
"""

def __init__(self):
pass

Expand Down Expand Up @@ -374,6 +378,7 @@ class ReadAgents(BaseReadFile):
config_obj: An object of class :class:`~episimmer.read_file.ReadConfiguration` containing the simulation
configurations.
"""

def __init__(self, filename: str, config_obj: ReadConfiguration):
super().__init__()
self.filename: str = filename
Expand Down Expand Up @@ -457,6 +462,7 @@ class ReadInteractions(BaseReadFile):
configurations.
agents_obj: An object of class :class:`ReadAgents` containing agent information
"""

def __init__(self, filename: str, config_obj: ReadConfiguration,
agents_obj: ReadAgents):
super().__init__()
Expand Down Expand Up @@ -556,6 +562,7 @@ class ReadProbabilisticInteractions(BaseReadFile):
configurations.
agents_obj: An object of class :class:`ReadAgents` containing agent information
"""

def __init__(self, filename: str, config_obj: ReadConfiguration,
agents_obj: ReadAgents):
super().__init__()
Expand Down Expand Up @@ -664,6 +671,7 @@ class ReadLocations(BaseReadFile):
config_obj: An object of class :class:`ReadConfiguration` containing the simulation
configurations.
"""

def __init__(self, filename: str, config_obj: ReadConfiguration):
super().__init__()
self.filename: str = filename
Expand Down Expand Up @@ -727,6 +735,7 @@ class ReadEvents(BaseReadFile):
locations_obj: An object of class :class:`ReadLocations` containing location information
agents_obj: An object of class :class:`ReadAgents` containing agent information
"""

def __init__(self,
filename: str,
config_obj: Union[ReadConfiguration, None] = None,
Expand Down Expand Up @@ -824,6 +833,7 @@ class ReadOneTimeEvents(ReadEvents):
Args:
filename: Name of the file containing one time event information.
"""

def __init__(self, filename: str):
super().__init__(filename)
self.event_info_keys: str = ''
Expand Down
1 change: 1 addition & 0 deletions episimmer/simulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Simulate():
agents_obj: An object of class :class:`~episimmer.read_file.ReadAgents`
locations_obj: An object of class :class:`~episimmer.read_file.ReadLocations`
"""

def __init__(self, config_obj: ReadConfiguration, model: BaseModel,
policy_list: List[Policy], agents_obj: ReadAgents,
locations_obj: ReadLocations):
Expand Down
4 changes: 4 additions & 0 deletions episimmer/utils/statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,9 @@ def save_stats(
Returns:
Callable function
"""

def decorator(func: Callable) -> Callable:

@functools.wraps(func)
def wrapper(ref: 'Simulate', *args, **kwargs) -> None:
func(ref, *args, **kwargs)
Expand Down Expand Up @@ -270,7 +272,9 @@ def write_stats(pickle_file: str, text_file: str) -> Callable:
Returns:
Callable function
"""

def decorator(func: Callable) -> Callable:

@functools.wraps(func)
def wrapper(*args, **kwargs):
func(*args, **kwargs)
Expand Down
12 changes: 8 additions & 4 deletions episimmer/utils/visualize.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ def get_interaction_graph_from_object(obj: 'Simulate') -> nx.Graph:
if agent.can_contribute_infection > 0:
for int_agent in agent.contact_list:
int_agent_indx = int_agent['Interacting Agent Index']
if (agents_obj.agents[int_agent_indx].can_receive_infection >
0):
if (agents_obj.agents[int_agent_indx].can_receive_infection
> 0):
g.add_edge(agent.index, int_agent_indx, color='black')

# Events
Expand All @@ -155,8 +155,8 @@ def get_interaction_graph_from_object(obj: 'Simulate') -> nx.Graph:
pos=(-1500 - 500 * j, 500 * i))
for agent in event_info['Agents']:
if (agents_obj.agents[agent].can_receive_infection > 0 or
agents_obj.agents[agent].can_contribute_infection >
0):
agents_obj.agents[agent].can_contribute_infection
> 0):
g.add_edge(event_info['Location Index'] + '_event' +
str(i),
agent,
Expand All @@ -172,7 +172,9 @@ def save_env_graph() -> Callable:
Returns:
Callable function
"""

def decorator(func: Callable) -> Callable:

@functools.wraps(func)
def wrapper(ref: 'Simulate', *args, **kwargs) -> None:
func(ref, *args, **kwargs)
Expand Down Expand Up @@ -279,7 +281,9 @@ def store_animated_dynamic_graph() -> Callable:
Returns:
Callable function
"""

def decorator(func: Callable) -> Callable:

@functools.wraps(func)
def wrapper(ref: 'Simulate', *args, **kwargs) -> None:
if ref.config_obj.worlds - 1 == Time.get_current_world():
Expand Down
5 changes: 5 additions & 0 deletions episimmer/vulnerability_detection/agent_vd.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class SimpleVulnerableAgent(VulnerableAgent):
world_obj: World object of simulation
parameter_dict: Dictionary of parameters relevant to the algorithm
"""

def __init__(self, world_obj: World,
parameter_dict: Dict[str, Union[List[str], int]]):
super().__init__(world_obj)
Expand Down Expand Up @@ -133,6 +134,7 @@ class EarlyVulnerableAgent(VulnerableAgent):
world_obj: World object of simulation
parameter_dict: Dictionary of parameters relevant to the algorithm
"""

def __init__(self, world_obj: World,
parameter_dict: Dict[str, Union[List[str], int]]):
super().__init__(world_obj)
Expand Down Expand Up @@ -275,6 +277,7 @@ class SimpleAgentVulnerability(AgentVulnerability):
world_obj: World object of simulation
parameter_dict: Dictionary of parameters relevant to the algorithm
"""

def __init__(self, world_obj: World,
parameter_dict: Dict[str, Union[List[str], int]]):
super().__init__(world_obj)
Expand Down Expand Up @@ -426,6 +429,7 @@ class ChunkAgentVulnerability(AgentVulnerability):
world_obj: World object of simulation
parameter_dict: Dictionary of parameters relevant to the algorithm
"""

def __init__(self, world_obj: World,
parameter_dict: Dict[str, Union[List[str], int, List[int]]]):
super().__init__(world_obj)
Expand Down Expand Up @@ -693,6 +697,7 @@ class BanditAlgos(AgentVulnerability):
world_obj: World object of simulation
parameter_dict: Dictionary of parameters relevant to the algorithm
"""

def __init__(self, world_obj: World,
parameter_dict: Dict[str, Union[List[str], int, str]]):
super().__init__(world_obj)
Expand Down
Loading

0 comments on commit aa6dbff

Please sign in to comment.