Resource Interface

This module provides an interface to the ResourceManager.

class vivarium.framework.resource.interface.ResourceInterface(manager)[source]

The resource management system.

A “resource” in vivarium is something like a state table private column, a lookup table, or a randomness stream. These resources are used to initialize or alter the state of the simulation. Many of these resources might depend on each other and therefore need to be created or updated in a particular order. These dependency chains can be quite long and complex.

Placing the ordering responsibility on end users makes simulations very fragile and difficult to understand. Instead, the resource management system allows users to only specify local dependencies (referred to throughout as “required resources”). The system then uses the local dependency information to construct a full dependency graph, validate that there are no cyclic dependencies, and return resources and their producers in an order that makes sense.

Parameters:

manager (ResourceManager)

add_resource(resource)[source]

Adds managed resources to the resource pool.

Return type:

None

Parameters:

resource (Resource) – The resource being added.

Raises:

ResourceError – If there are multiple producers of the same resource.

add_private_columns(initializer, columns, required_resources)[source]

Adds private column resources to the resource pool.

Return type:

None

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

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

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

get_population_initializers()[source]

Returns a dependency-sorted list of population initializers.

We exclude all non-initializer dependencies. They were necessary in graph construction, but we only need the column producers at population creation time.

Return type:

list[Any]