Component Manager

The vivarium.engine component manager system is responsible for maintaining a reference to all of the managers and components in a simulation, providing an interface for adding additional components or managers, and applying default configurations and initiating the setup stage of the lifecycle. This module provides the default implementation and interface.

The ComponentManager is the first plugin loaded by the SimulationContext and managers and components are given to it by the context. It is called on to setup everything it holds when the context itself is setup.

exception vivarium.engine.framework.components.manager.ComponentConfigError[source]

Error while interpreting configuration file or initializing components

class vivarium.engine.framework.components.manager.OrderedComponentSet(*args)[source]

A container for Vivarium components.

It preserves ordering, enforces uniqueness by name, and provides a subset of set-like semantics.

Parameters:

args (T)

add(component)[source]
Return type:

None

Parameters:

component (T)

update(components)[source]
Return type:

None

Parameters:

components (Sequence[T])

pop()[source]
Return type:

TypeVar(T, Component, Manager)

class vivarium.engine.framework.components.manager.ComponentManager[source]

Manages the initialization and setup of vivarium.engine components.

Maintains references to all components and managers in a vivarium.engine simulation, applies their default configuration and initiates their setup life-cycle stage.

The component manager maintains a separate list of managers and components and provides methods for adding to these lists and getting members that correspond to a specific type. It also initiates the setup lifecycle phase for all components and managers it controls. This is done first for managers and then components, and involves applying default configurations and calling the object’s setup method.

property configuration: ConfigTree

The configuration tree for the simulation.

property name: str

The name of this component.

setup_manager(configuration, lifecycle_manager)[source]

Sets up the component manager.

It registers lifecycle constraints and stores the configuration tree. Unlike other managers, this is called directly by the simulation context during its __init__.

Return type:

None

Parameters:
add_managers(managers)[source]

Registers new managers with the component manager.

Managers are configured and setup before components.

Return type:

None

Parameters:

managers (Sequence[Manager]) – Instantiated managers to register.

add_components(components)[source]

Register new components with the component manager.

Components are configured and setup after managers.

Return type:

None

Parameters:

components (Sequence[Component]) – Instantiated components to register.

get_components_by_type(component_type)[source]

Get all components that are an instance of component_type.

Return type:

list[TypeVar(C, bound= Component)]

Parameters:

component_type (type[C] | Sequence[type[C]]) – A component type.

Returns:

A list of components of type component_type.

get_component(name)[source]

Get the component with name name.

Names are guaranteed to be unique.

Return type:

Component | Manager

Parameters:

name (str) – A component name.

Returns:

A component that has name name.

Raises:

ValueError – No component exists in the component manager with name.

list_components()[source]

Get a mapping of component names to components held by the manager.

Return type:

dict[str, Component | Manager]

Returns:

A mapping of component names to components.

get_current_component()[source]

Get the component currently being set up, if any.

Return type:

Component

Returns:

The component currently being set up.

Raises:

LifeCycleError – No component is currently being set up.

get_current_component_or_manager()[source]

Get the component or manager currently being set up, if any.

Return type:

Component | Manager

Returns:

The component or manager currently being set up.

Raises:

LifeCycleError – No component or manager is currently being set up.

tracking_setup(component)[source]

Context manager that sets _current_component to component for the duration of the block, then restores the previous value.

Using save-and-restore rather than a plain assignment means nested calls (e.g. a manager whose setup calls super().setup) work correctly.

Return type:

Iterator[None]

Parameters:

component (Component | Manager) – The component or manager currently being set up.

setup_components(builder)[source]

Separately configure and set up the managers and components held by the component manager, in that order.

The setup process involves applying default configurations and then calling the manager or component’s setup method. This can result in new components as a side effect of setup because components themselves have access to this interface through the builder in their setup method.

Return type:

None

Parameters:

builder (Builder) – Interface to several simulation tools.

apply_configuration_defaults(component)[source]
Return type:

None

Parameters:

component (Component | Manager)