episimmer.utils

ArgParse API

parse_args()[source]

This function parses the command-line arguments

Returns

Parsed arguments

Return type

argparse.Namespace

Module Handling API

module_from_file(module_name, file_path)[source]

Returns the module from the file passed

Parameters
  • module_name (str) – Name of module

  • file_path (str) – Path to file used to create module

Returns

Module of file

Return type

module

get_policy(example_path)[source]

Returns the policy list created in the Generate_policy.py file

Parameters

example_path (str) – Path to directory containing simulation files

Returns

Policy list to be run during simulation

Return type

List[Policy]

get_model(example_path)[source]

Instantiates and returns the disease model object created in the UserModel.py file

Parameters

example_path (str) – Path to directory containing simulation files

Returns

Disease Model object

Return type

BaseModel

Time API

class Time[source]

Class that handles the time step and world of simulation.

current_world: Optional[int] = None
current_time_step: Optional[int] = None
static get_current_world()[source]

Returns the current world of simulation.

Returns

Index of current world

Return type

int

static get_current_time_step()[source]

Returns the current time step of simulation.

Returns

Index of current time step

Return type

int

static reset()[source]

Resets the world and time step at the beginning of a new simulation.

Return type

None

static new_world()[source]

Sets the value of current_world and current time step at the onset of a world.

Return type

None

static increment_current_time_step()[source]

increments the current time step during simulation.

Return type

None

Statistics API

Stats

Class to handle variable statistics in Episimmer

expand_levels_recursion

This function is a recursive function which expands the current object's variables to a given number of levels.

expand_levels

Expands the object by expanding the members of the object such as dictionaries and iterables.

process_dict_recursion

This function is a recursive function which selects the variables of the dictionary to be saved.

process_dict

Processes the expanded object as a dictionary by choosing to save only required properties.

get_pretty_print_str

Returns the dictionary as a string in pretty print format

save_pickle

Saves the dictionary into a pickle file

save_to_text_file

Saves the string to a text file.

save_stats

Decorator to save statistics (object members) into a dictionary

write_stats

Decorator to write statistics (object members) into a file

class Stats[source]

Class to handle variable statistics in Episimmer

stats_dict = {}
static add_content(key, content)[source]

Adds content to the statistics dictionary into a list.

Parameters
  • key (str) – Key to be added to dictionary

  • content (Dict[str, Dict]) – Content to be added as value to the key in dictionary

Return type

None

static get_dict()[source]

Returns the statistics dictionary

Returns

the statistics dictionary

Return type

Dict[str, Dict]

expand_levels_recursion(obj, levels, cur_level)[source]

This function is a recursive function which expands the current object’s variables to a given number of levels. If the object is a dictionary or an iterable,only then will the object be expanded. Other objects are returned as is.

Parameters
  • obj (object) – Object to be expanded

  • levels (int) – Number of levels to expand the object

  • cur_level (int) – Current level expanded

Returns

An expanded object

Return type

Union[Dict[str, Dict], object]

expand_levels(obj, levels)[source]

Expands the object by expanding the members of the object such as dictionaries and iterables. Calls the expand_levels_recursion method for expansion of object.

Parameters
  • obj (object) – Object to be expanded

  • levels (int) – Number of levels to expand the object

Returns

An expanded object

Return type

Union[Dict[str, Dict], object]

process_dict_recursion(stats_dict, final_level_properties, levels, cur_level)[source]

This function is a recursive function which selects the variables of the dictionary to be saved.

Parameters
  • stats_dict (Dict[str, Dict]) – Dictionary containing an object’s expanded members

  • final_level_properties (Union[str, List[str]]) – Properties required to be saved

  • levels (int) – NNumber of levels the object was expanded

  • cur_level (int) – Current level of dictionary

Returns

Processed dictionary

Return type

Dict[str, Dict]

process_dict(stats_dict, final_level_properties, levels)[source]

Processes the expanded object as a dictionary by choosing to save only required properties. Calls the process_dict_recursion method.

Parameters
  • stats_dict (Dict[str, Dict]) – Dictionary containing an object’s expanded members

  • final_level_properties (Union[str, List[str]]) – Properties required to be saved

  • levels (int) – NNumber of levels the object was expanded

Returns

Processed dictionary

Return type

Dict[str, Dict]

get_pretty_print_str(stats_dict)[source]

Returns the dictionary as a string in pretty print format

Parameters

stats_dict (Dict[str, Dict]) – Dictionary to be converted to pretty print string

Returns

String representing dictionary in pretty print format

Return type

str

save_pickle(example_path, pickle_file, final_dict)[source]

Saves the dictionary into a pickle file

Parameters
  • example_path (str) – Path to directory containing simulation files.

  • pickle_file (str) – Name of pickle file

  • final_dict (Dict[str, Dict]) – Dictionary to be saved

Return type

None

save_to_text_file(example_path, string, text_filename)[source]

Saves the string to a text file.

Parameters
  • example_path (str) – Path to directory containing simulation files.

  • string (str) – String to be saved

  • text_filename (str) – Name of text file

Return type

None

save_stats(obj_lev_tuples, key, final_level_properties='All')[source]

Decorator to save statistics (object members) into a dictionary

Parameters
  • obj_lev_tuples (List[Tuple[str, int]]) – List of tuples containing the object to be saved (as a string) and the number of levels

  • key (str) – Key to use while saving the content in the statistics dictionary

  • final_level_properties (Union[str, List[str]]) – Properties to save. Can be a list of properties/members of the object or ‘All’

Returns

Callable function

Return type

Callable

write_stats(pickle_file, text_file)[source]

Decorator to write statistics (object members) into a file

Parameters
  • pickle_file (str) – Name of pickle file

  • text_file (str) – Name of text file

Returns

Callable function

Return type

Callable

Visualization API

plot_results

Plots the epidemic trajectory

buildgraph

Builds the epidemic trajectory graph for current frame i

store_animated_time_plot

Saves the animation of epidemic trajectory to a gif file

get_interaction_graph_from_object

Generates the interaction graph from the simulation object

save_env_graph

Decorator to save the interactions graph to the Simulate object

set_ax_params

Sets the title and legend of the Axes for the interaction graph

draw_graph

Sets the node positions and edges according to the spring layout and returns them.

animate_graph

Sets up the figure to plot the current time step interaction network

store_animated_dynamic_graph

Decorator to store the evolving interactions graph as a gif.

plot_results(example_path, model, avg_dict, stddev_dict, max_dict, min_dict, plot)[source]

Plots the epidemic trajectory

Parameters
  • example_path (str) – Path to directory containing simulation files

  • model (BaseModel) – Disease model used

  • avg_dict (Dict[str, List[float]]) – Average of epidemic trajectory

  • stddev_dict (Dict[str, List[float]]) – Standard deviation of epidemic trajectory

  • max_dict (Dict[str, List[int]]) – Maximum values of epidemic trajectory across worlds

  • min_dict (Dict[str, List[int]]) – Minimum values of epidemic trajectory across worlds

  • plot (bool) – Boolean used to plot the epidemic trajectory

Return type

None

buildgraph(i, model, avg_dict)[source]

Builds the epidemic trajectory graph for current frame i

Parameters
  • i (int) – Current frame

  • model (BaseModel) – Disease model used

  • avg_dict (Dict[str, List[float]]) – Average of epidemic trajectory

Return type

None

store_animated_time_plot(example_path, model, avg_dict)[source]

Saves the animation of epidemic trajectory to a gif file

Parameters
  • example_path (str) – Path to directory containing simulation files

  • model (BaseModel) – Disease model used

  • avg_dict (Dict[str, List[float]]) – Average of epidemic trajectory

Return type

None

get_interaction_graph_from_object(obj)[source]

Generates the interaction graph from the simulation object

Parameters

obj (Simulate) – Simulation object

Returns

Interaction graph

Return type

networkx.classes.graph.Graph

save_env_graph()[source]

Decorator to save the interactions graph to the Simulate object

Returns

Callable function

Return type

Callable

set_ax_params(ax, model, time_step)[source]

Sets the title and legend of the Axes for the interaction graph

Parameters
  • ax (matplotlib.axes._axes.Axes) – Axes

  • model (BaseModel) – Disease model used

  • time_step (int) – Current time step

Returns

Axes

Return type

matplotlib.axes._axes.Axes

draw_graph(g, ax, seed)[source]

Sets the node positions and edges according to the spring layout and returns them.

Parameters
  • g (networkx.classes.graph.Graph) – Current interaction graph

  • ax (matplotlib.axes._axes.Axes) – Axes

  • seed (Union[str, int]) – Seed for consistent graph

Returns

Nodes and Edges

Return type

Tuple[matplotlib.collections.PatchCollection, matplotlib.collections.LineCollection]

animate_graph(time_step, fig, model, g_list, seed)[source]

Sets up the figure to plot the current time step interaction network

Parameters
  • time_step (int) – Current time step

  • fig (matplotlib.figure.Figure) – Figure used to plot

  • model (BaseModel) – Disease model used

  • g_list (List[networkx.classes.graph.Graph]) – List of interaction graphs for every time step

  • seed (Union[str, int]) – Seed for consistent graph

Returns

Nodes and edges for current time step

Return type

Tuple[matplotlib.collections.PatchCollection, matplotlib.collections.LineCollection]

store_animated_dynamic_graph()[source]

Decorator to store the evolving interactions graph as a gif.

Returns

Callable function

Return type

Callable

Math API

deep_copy_average

This function returns the average of the values in the epidemic trajectory

deep_copy_stddev

This function returns the standard deviation of the values in the epidemic trajectory.

deep_copy_average(tdict, number)[source]

This function returns the average of the values in the epidemic trajectory

Parameters
  • tdict (Dict[str, List[int]]) – Time series dictionary.

  • number (int) – Number of worlds

Returns

Average of epidemic trajectory

Return type

Dict[str, List[float]]

deep_copy_stddev(tdict, t2_dict, number)[source]

This function returns the standard deviation of the values in the epidemic trajectory.

Parameters
  • tdict (Dict[str, List[int]]) – Time series dictionary.

  • t2_dict (Dict[str, List[int]]) – Squared time series dictionary.

  • number (int) – Number of worlds

Returns

Standard Deviation of epidemic trajectory

Return type

Dict[str, List[float]]