Skip to content

epymorph.simulator.world_list

World implementation: ListWorld.

Cohort

Cohort(
    compartments: NDArray[SimDType],
    return_location: int,
    return_tick: int,
)

Represents a group of individuals, divided into IPM compartments as appropriate for the simulation. These individuals share the same "home location" and a time at which they should return there.

These are somewhat abstract concepts, however; a completely nomadic group doesn't really have a home location, merely the next location in a chain of movements.

SORT_KEY class-attribute instance-attribute

SORT_KEY = attrgetter('return_tick', 'return_location')

The natural sort order of a Cohort.

compartments instance-attribute

compartments: NDArray[SimDType] = compartments

return_location instance-attribute

return_location: int = return_location

return_tick instance-attribute

return_tick: int = return_tick

can_merge_with

can_merge_with(other: Self) -> bool

Returns true if two cohorts can be merged.

merge_from

merge_from(from_cohort: Self) -> None

Merges another cohort into this one, modifying in-place.

ListWorld

ListWorld(locations: list[list[Cohort]])

Bases: World

A world model which tracks state with lists: the world is a list of locations, and each location is a list of cohorts.

HOME_TICK class-attribute instance-attribute

HOME_TICK = -1

The value of a population's return_tick when the population is home.

nodes instance-attribute

nodes: int = len(locations)

compartments instance-attribute

compartments: int = len(compartments)

locations instance-attribute

locations: list[list[Cohort]] = locations

from_initials classmethod

from_initials(
    initial_compartments: NDArray[SimDType],
) -> Self

Create a world with the given initial compartments: assumes everyone starts at home, no travelers initially. initial_compartments is an (N,C) array.

normalize

normalize() -> None

Sorts all cohorts within each location and combines mergeable cohorts (in place). The world should be normalized after any modification.

get_cohorts

get_cohorts(location_idx: int) -> Sequence[Cohort]

Iterate over the cohorts present in a single location.

get_cohort_array

get_cohort_array(location_idx: int) -> NDArray[SimDType]

Retrieve an (X,C) array containing all cohorts at a single location, where X is the number of cohorts.

get_local_array

get_local_array() -> NDArray[SimDType]

Get the local populations of each node as an (N,C) array. This is the individuals which are theoretically eligible for movement.

get_local_cohorts

get_local_cohorts() -> Iterable[Cohort]

Iterate over all locations returning just the local cohort from each.

apply_cohort_delta

apply_cohort_delta(
    location_idx: int, delta: NDArray[SimDType]
) -> None

Apply the disease delta for all cohorts at the given location. delta is an (X,C) array where X is the number of cohorts.

apply_travel

apply_travel(
    travelers: NDArray[SimDType], return_tick: int
) -> None

Given an (N,N,C) array determining who should travel -- from-source-to-destination-by-compartment -- modify the world state as a result of that movement.

apply_return

apply_return(
    tick: Tick, *, return_stats: bool
) -> NDArray[SimDType] | None

Modify the world state as a result of returning all movers that are ready to be returned home. If return_stats is True, returns an NxNxC array containing the individuals moved during the return. Otherwise returns None.