pandemia.world

Subpackages

Submodules

Package Contents

Classes

Region

A region, consisting of agents, locations and activities.

VectorRegion

A region in vectorized format.

World

A world consiting of regions.

VectorWorld

A world consiting of vectorized regions.

class pandemia.world.Region(id: int, name: str, activities: list[str], agents: list[pandemia.world.agent.Agent], locations: list[pandemia.world.location.Location])

A region, consisting of agents, locations and activities.

A region can represent, for example a country or an administrative division within a country.

Parameters:

idint

An integer identifier for this region.

namestr

The name of the region. For example, if the region represents a country, this could be the country code in ISO 3166-1 alpha-2 format.

activitieslist[str]

A list of all activities performed by agents in this region.

agentslist[Agent]

A list of all agents in this region.

locationslist[Location]

A list of all locations in this region.

Attributes:

idint

An integer identifier for this region.

namestr

The name of the region. For example, if the region represents a country, this could be the country code in ISO 3166-1 alpha-2 format.

other_namestr

Another name of the region. For example, if the region represents a country, this could be the country code in ISO 3166-1 alpha-3 format.

super_regionstr

The group of regions to which this region belongs. For example, if the regions represents a country, its super region might be the continent to which it belongs.

activities: list[str]

A list of all activities performed by agents in this region.

agents: list[Agent]

A list of all agents in this region.

locations: list[Location]

A list of all locations in this region.

coordinateslist

Used to render the region as polygons. If provided, the list should be of the format:

[[points_0], [points_1], …, [points_N]]

with each points_n a list of 2-tuples of floats. A list points_n represents the x, y coordinates of each point along the border of a connected piece of the region.

region_coordinateslist

Used to render the region as grid squares. If provided, the list should be a list of 2-tuples of floats, representing the x, y coordinates of each grid square.

vectorize_region()

Converts the object of type Region to an object of type VectorRegion.

A VectorRegion is a vectorized versions of the former, with Python lists and dictionaries converted to numpy arrays for fast interface with low-level C functions.

Returns:
vector_regionVectorRegion

A vector representation of the region.

class pandemia.world.VectorRegion(id: int, name: str, ticks_in_week: int, number_of_activities: int, number_of_agents: int, number_of_locations: int, max_num_activity_locations: int)

A region in vectorized format.

Agents, locations and activities are now represented as integers, with various arrays used to store their attributes. Further attributes, in addition to the ones below, may be added to the vector world by simulation components, where necessary.

Parameters:

idint

An integer identifier for this region. This will be determined by the world factory.

namestr

A name for this region. For example, if the region represents a country, this could be the country code in ISO 3166-1 alpha-2 format.

ticks_in_weekint

The number of clock ticks in the week.

number_of_agents: int

The number of agents in this region.

number_of_activities: int

The number of activities performed by agents in this region.

number_of_locations: int

The number of locations in this region.

max_num_activity_locations: int

The maximum number of locations at which it is possible to perform an activity (int). This maximum is taken accross all agents and all activities in this region.

Attributes:

idint

An integer identifier for this region. This will be determined by the world factory.

namestr

A name for this region. For example, if the region represents a country, this could be the country code in ISO 3166-1 alpha-2 format.

other_namestr

Another name of the region. For example, if the region represents a country, this could be the country code in ISO 3166-1 alpha-3 format.

super_regionstr

The group of regions to which this region belongs. For example, if the regions represents a country, its super region might be the continent to which it belongs.

random_statenp.ndarray

A pair of 64-bit integers. This pair is the random seed to be used by the prng inside the C libraries. This is an numpy array of length 2, consisting of two integers of type np.uint64. Each region gets it own random state, to preserve determinism when parallelizing.

prngRandom

An instance of the Random class for this region. Each region gets it own instance of the Random class, to preserve determinism when parallelizing.

ticks_in_weekint

The number of clock ticks in the week.

number_of_agentsint

The number of agents in this region.

number_of_activitiesint

The number of activities performed by agents in this region.

number_of_locationsint

The number of locations in this region.

max_num_activity_locationsint

The maximum number of locations at which it is possible to perform an activity (int). This maximum is taken accross all agents and all activities in this region.

agenp.ndarray

An array of length number_of_agents recording the age of each agent.

weekly_routinesnp.ndarray

For each agent, a sequence of integers of length ticks_in_week, indicating which activities (represented as integers) are performed each tick.

num_activity_locationsnp.ndarray

For each agent, for each activity, the number of locations at which that agent can perform that activity.

activity_locationsnp.ndarray

For each agent, for each activity, the locations (represented as integers) at which the agent can perform that activity. The number of locations at which agents perform activities may be variable, as recorded by num_activity_locations, but should be bounded above by max_num_activity_locations. This array is not a jagged array, the entries between num_activity_locations and max_num_activity_locations being padding.

activity_location_weightsnp.ndarray

For each agent, for each activity, the weights for each location at which the agent can perform that activity. The weights need not sum to one, with these weights being only relavent upto num_activity_locations. This array is not a jagged array, the entries between num_activity_locations and max_num_activity_locations being padding.

activity_stringslist[str]

The list of activities for this region. If an activity is represented by the integer a, then the corresponding string will be activity_strings[a], for example “Home”.

location_typ_stringslist[str]

If a location is represented by the integer l, then location_typ_strings[l] gives the type of location l, for example “House”.

location_x_coordsnp.ndarray

The x coordinates of all locations in this region (np.ndarray).

location_y_coordsnp.ndarray

The y coordinates of all locations in this region (np.ndarray).

coordinateslist

Used to render the region as polygons. If provided, the list should be of the format:

[[points_0], [points_1], …, [points_N]]

with each points_n a list of 2-tuples of floats. A list points_n represents the x, y coordinates of each point along the border of a connected piece of the region.

region_coordinateslist

Used to render the region as grid squares. If provided, the list should be a list of 2-tuples of floats, representing the x, y coordinates of each grid square.

class pandemia.world.World(scale_factor)

A world consiting of regions.

For example, a country consisting of administrative divisions, or the whole world consisting of countries.

Parameters:

scale_factorfloat

Attached to each world is a scale factor, indicating that scaling may have taken place in the creation of the world. For example, a world with 1 million agents representing a real world with 100 million agents would have the scale factor 0.01. This is stored as an attribute since the scale factor is needed to scale quantities during input and output.

Attributes:

regionslist[Region]

The list of regions in this world.

number_of_regionsint

How many regions are in this world.

scale_factorfloat

Attached to each world is a scale factor, indicating that scaling may have taken place in the creation of the world. For example, a world with 1 million agents representing a real world with 100 million agents would have the scale factor 0.01. This is stored as an attribute since the scale factor is needed to scale quantities during input and output.

travel_matrixnp.ndarray

An array of integers of dimension number_of_regions x number_of_regions.

vectorize_world()

Converts an object of type World to an object of type VectorWorld. A VectorWorld contains a list of objects of type VectorRegion, as opposed to objects of type Region, as in a World.

Returns:
new_vector_worldVectorWorld

A vector representation of the world.

class pandemia.world.VectorWorld(scale_factor)

A world consiting of vectorized regions.

For example, a country consisting of administrative divisions, or the whole world consisting of countries.

Parameters:

scale_factorfloat

Attached to each world is a scale factor, indicating that scaling may have taken place in the creation of the world. For example, a world with 1 million agents representing a real world with 100 million agents would have the scale factor 0.01. This is stored as an attribute since the scale factor is needed to scale quantities during input and output.

Attributes:

vector_regionslist[VectorRegion]

The list of regions in this vectorized world.

number_of_regionsint

How many vectorized regions are in this vectorized world.

scale_factorfloat

Attached to each world is a scale factor, indicating that scaling may have taken place in the creation of the world. For example, a world with 1 million agents representing a real world with 100 million agents would have the scale factor 0.01. This is stored as an attribute since the scale factor is needed to scale quantities during input and output.

travel_matrixnp.ndarray

An array of integers of dimension number_of_regions x number_of_regions.

to_file(output_filename: str)

Write an object to disk at the filename given.

Parameters:

output_filename (str) – The filename to write to. Files get overwritten by default.

Returns:

None

static from_file(input_filename: str)

Read an object from disk from the filename given.

Parameters:

input_filename (str) – The filename to read from.

Returns:

The python object read from disk

Return type:

obj(Object)