From 8f9148a8189b69d98380fb4daaaea72ac91c7672 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 20 Dec 2022 03:01:43 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- docs/conf.py | 1 + episimmer/agent.py | 1 + episimmer/location.py | 1 + episimmer/model.py | 3 +++ episimmer/policy/base.py | 3 +++ episimmer/policy/contact_tracing_policy.py | 2 ++ episimmer/policy/lockdown_policy.py | 6 ++++++ episimmer/policy/testing_policy.py | 4 ++++ episimmer/policy/vaccination_policy.py | 3 +++ episimmer/read_file.py | 10 ++++++++++ episimmer/simulate.py | 1 + episimmer/utils/statistics.py | 4 ++++ episimmer/utils/visualize.py | 4 ++++ episimmer/vulnerability_detection/agent_vd.py | 5 +++++ episimmer/vulnerability_detection/base.py | 5 +++++ episimmer/vulnerability_detection/event_vd.py | 1 + episimmer/vulnerability_detection/vd.py | 1 + episimmer/world.py | 1 + tests/unit/Complete_Interaction_Space/UserModel.py | 1 + tests/unit/test_model.py | 1 + tests/unit/test_read_file.py | 1 + 21 files changed, 59 insertions(+) diff --git a/docs/conf.py b/docs/conf.py index 01223be0..8801bc02 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -106,6 +106,7 @@ def setup(app): + def skip(app, what, name, obj, skip, options): members = [ '__init__', diff --git a/episimmer/agent.py b/episimmer/agent.py index 4d6da26a..359dd0b5 100644 --- a/episimmer/agent.py +++ b/episimmer/agent.py @@ -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 diff --git a/episimmer/location.py b/episimmer/location.py index 948ba11f..8a707cc5 100644 --- a/episimmer/location.py +++ b/episimmer/location.py @@ -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'] diff --git a/episimmer/model.py b/episimmer/model.py index ee217824..b198812a 100644 --- a/episimmer/model.py +++ b/episimmer/model.py @@ -20,6 +20,7 @@ class BaseModel(): Args: name: Name of Disease Model """ + def __init__(self, name: str): self.name: str = name @@ -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]]): @@ -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] = [] diff --git a/episimmer/policy/base.py b/episimmer/policy/base.py index 6877b121..a5b89e2f 100644 --- a/episimmer/policy/base.py +++ b/episimmer/policy/base.py @@ -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 @@ -67,6 +68,7 @@ class AgentPolicy(Policy): Args: policy_type: Type of Agent Policy """ + def __init__(self, policy_type: str): super().__init__(policy_type) @@ -124,5 +126,6 @@ class EventPolicy(Policy): Args: policy_type: Type of Event Policy """ + def __init__(self, policy_type: str): super().__init__(policy_type) diff --git a/episimmer/policy/contact_tracing_policy.py b/episimmer/policy/contact_tracing_policy.py index 7a87f287..8fbaaebf 100644 --- a/episimmer/policy/contact_tracing_policy.py +++ b/episimmer/policy/contact_tracing_policy.py @@ -12,6 +12,7 @@ class ContactList(): """ Class built to implement an ordered and unique list of contacts """ + def __init__(self): self.contacts: List[str] = [] @@ -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, diff --git a/episimmer/policy/lockdown_policy.py b/episimmer/policy/lockdown_policy.py index 6073d8f4..23956196 100644 --- a/episimmer/policy/lockdown_policy.py +++ b/episimmer/policy/lockdown_policy.py @@ -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 @@ -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) @@ -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], @@ -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, @@ -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 @@ -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], diff --git a/episimmer/policy/testing_policy.py b/episimmer/policy/testing_policy.py index a6076f4e..303ca2ee 100644 --- a/episimmer/policy/testing_policy.py +++ b/episimmer/policy/testing_policy.py @@ -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): @@ -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 @@ -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): @@ -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 diff --git a/episimmer/policy/vaccination_policy.py b/episimmer/policy/vaccination_policy.py index be2202ea..8bd4c816 100644 --- a/episimmer/policy/vaccination_policy.py +++ b/episimmer/policy/vaccination_policy.py @@ -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): @@ -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, @@ -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') diff --git a/episimmer/read_file.py b/episimmer/read_file.py index e13ce909..752b9fe7 100644 --- a/episimmer/read_file.py +++ b/episimmer/read_file.py @@ -19,6 +19,7 @@ class ReadConfiguration(): Args: filename: Name of the directory containing simulation files """ + def __init__(self, filename: str): self.filename: str = filename @@ -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) @@ -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] = [] @@ -345,6 +348,7 @@ class BaseReadFile(): """ Base class for reading agents, locations, interactions and events from a file. """ + def __init__(self): pass @@ -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 @@ -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__() @@ -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__() @@ -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 @@ -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, @@ -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 = '' diff --git a/episimmer/simulate.py b/episimmer/simulate.py index 37f0f32f..605c2cdb 100644 --- a/episimmer/simulate.py +++ b/episimmer/simulate.py @@ -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): diff --git a/episimmer/utils/statistics.py b/episimmer/utils/statistics.py index 000f1576..6b57f5aa 100644 --- a/episimmer/utils/statistics.py +++ b/episimmer/utils/statistics.py @@ -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) @@ -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) diff --git a/episimmer/utils/visualize.py b/episimmer/utils/visualize.py index dbe56c5e..6d606f83 100644 --- a/episimmer/utils/visualize.py +++ b/episimmer/utils/visualize.py @@ -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) @@ -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(): diff --git a/episimmer/vulnerability_detection/agent_vd.py b/episimmer/vulnerability_detection/agent_vd.py index ef93c140..026f2059 100644 --- a/episimmer/vulnerability_detection/agent_vd.py +++ b/episimmer/vulnerability_detection/agent_vd.py @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) diff --git a/episimmer/vulnerability_detection/base.py b/episimmer/vulnerability_detection/base.py index 1871490a..77b63a3f 100644 --- a/episimmer/vulnerability_detection/base.py +++ b/episimmer/vulnerability_detection/base.py @@ -11,6 +11,7 @@ class AgentVD(): Args: world_obj: World object of simulation """ + def __init__(self, world_obj: World): self.world_obj: World = world_obj self.agent_scores: Dict[Union[str, int], float] = {} @@ -96,6 +97,7 @@ class VulnerableAgent(AgentVD): Args: world_obj: World object of simulation """ + def __init__(self, world_obj: World): super().__init__(world_obj) self.type: str = 'Vulnerable Agents' @@ -108,6 +110,7 @@ class AgentVulnerability(AgentVD): Args: world_obj: World object of simulation """ + def __init__(self, world_obj: World): super().__init__(world_obj) self.type: str = 'Agent Vulnerability' @@ -126,6 +129,7 @@ class EventVD: Args: world_obj: World object of simulation """ + def __init__(self, world_obj: World): self.world_obj: World = world_obj self.event_scores: Dict[str, float] = {} @@ -209,6 +213,7 @@ class EventVulnerability(EventVD): Args: world_obj: World object of simulation """ + def __init__(self, world_obj: World): super().__init__(world_obj) self.type: str = 'Event Vulnerability' diff --git a/episimmer/vulnerability_detection/event_vd.py b/episimmer/vulnerability_detection/event_vd.py index 205877f9..770be9b1 100644 --- a/episimmer/vulnerability_detection/event_vd.py +++ b/episimmer/vulnerability_detection/event_vd.py @@ -67,6 +67,7 @@ class SimpleEventVulnerability(EventVulnerability): 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) diff --git a/episimmer/vulnerability_detection/vd.py b/episimmer/vulnerability_detection/vd.py index 8693f7f1..04e539e3 100644 --- a/episimmer/vulnerability_detection/vd.py +++ b/episimmer/vulnerability_detection/vd.py @@ -13,6 +13,7 @@ class VD(): vd_config_obj: ReadVDConfiguration object world_obj: World object of simulation """ + def __init__(self, vd_config_obj: ReadVDConfiguration, world_obj: World): self.vd_config_obj: ReadVDConfiguration = vd_config_obj self.world_obj: World = world_obj diff --git a/episimmer/world.py b/episimmer/world.py index e216797b..f2d85770 100644 --- a/episimmer/world.py +++ b/episimmer/world.py @@ -29,6 +29,7 @@ class World(): event_files_list: List of path names of all the events list files one_time_event_file: File name of the one time event """ + def __init__(self, config_obj: ReadConfiguration, model: BaseModel, policy_list: List[Policy], agents_filename: str, interaction_files_list: List[List[str]], diff --git a/tests/unit/Complete_Interaction_Space/UserModel.py b/tests/unit/Complete_Interaction_Space/UserModel.py index 58471662..484a5964 100644 --- a/tests/unit/Complete_Interaction_Space/UserModel.py +++ b/tests/unit/Complete_Interaction_Space/UserModel.py @@ -21,6 +21,7 @@ def event_receive_fn(agent, ambient_infection, event_info, location, class UserModel(model.StochasticModel): + def __init__(self): individual_types = ['Susceptible', 'Infected', 'Recovered'] infected_states = ['Infected'] diff --git a/tests/unit/test_model.py b/tests/unit/test_model.py index d9c84e99..1bdb161c 100644 --- a/tests/unit/test_model.py +++ b/tests/unit/test_model.py @@ -6,6 +6,7 @@ class TestModel(unittest.TestCase): + def test_state_proportion_checker(self): base_model = BaseModel('Test') success_dict = {'a': 0.1, 'b': 0.2, 'c': 0.7} diff --git a/tests/unit/test_read_file.py b/tests/unit/test_read_file.py index 5c2f3aa1..1f69a3f8 100644 --- a/tests/unit/test_read_file.py +++ b/tests/unit/test_read_file.py @@ -9,6 +9,7 @@ class TestReadFile(unittest.TestCase): + def test_read_config(self): example_path = osp.join('tests', 'unit', 'Complete_Interaction_Space') config_filename = osp.join(example_path, 'config.txt')