Population Interface

This module provides a PopulationInterface class with methods to initialize simulants and get a population view.

class vivarium.engine.framework.population.interface.PopulationInterface(manager)[source]

Provides access to the system for reading and updating the population.

The most important aspect of the simulation state is the population state table (or simply state table). It is a table with a row for every individual or cohort (referred to as a simulant) being simulated and a column for each of the attributes of the simulant being modeled. All access to the state table is mediated by population views, which may be requested from this system during setup time.

Parameters:

manager (PopulationManager)

get_view(component=None)[source]

Gets a time-varying view of the population state table.

The requested population view can be used to view the current state or to update the state with new values.

Return type:

PopulationView

Parameters:

component (Component | None) – The component requesting this view. If None, the view will provide read-only access.

Returns:

A view of the requested columns of the population state table.

get_simulant_creator()[source]

Gets a function that can generate new simulants.

The creator function takes the number of simulants to be created as its first argument and a population configuration dict that will be available to simulant initializers as its second argument. It generates the new rows in the population state table and then calls each initializer registered with the population system with a data object containing the state table index of the new simulants, the configuration info passed to the creator, the current simulation time, and the size of the next time step.

Returns:

The simulant creator function.

Return type:

Callable[[int, dict[str, Any] | None], pd.Index[int]]

register_initializer(initializer, columns, required_resources=())[source]

Registers a component’s initializers and any (private) columns created by them.

This does three primary things: 1. Registers each private column’s corresponding attribute producer. 2. Records metadata about which component created which private columns. 3. Registers the initializer as a resource.

A columns value of None indicates that no private columns are being registered. This is useful when a component or manager needs to register an initializer that does not create any private columns.

Return type:

None

Parameters:
  • initializer (Callable[[SimulantData], None]) – A function that will be called to initialize the state of new simulants.

  • columns (str | Sequence[str] | None) – The private columns that the given initializer provides the initial state information for.

  • required_resources (Sequence[str | Resource]) – The resources that the initializer requires to run. Strings are interpreted as attributes.

register_tracked_query(query)[source]

Adds a new query to the population manager’s tracked query string.

Return type:

None

Parameters:

query (str) – The new query to be added to the population manager’s tracked query string.

get_tracked_query()[source]

Gets a callable that returns the combined tracked query for the population.

Return type:

Callable[[], str]

get_population_index()[source]

Gets a callable that returns the population index.

Return type:

Callable[[], pd.Index[int]]