The Component Manager System

The vivarium 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.framework.components.manager.ComponentConfigError[source]

Error while interpreting configuration file or initializing components

class vivarium.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 (Component | Manager)

add(component)[source]
Parameters:

component (Component)

Return type:

None

update(components)[source]
Parameters:

components (List[Component | Manager] | Tuple[Component | Manager])

Return type:

None

pop()[source]
Return type:

Component | Manager

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

Manages the initialization and setup of vivarium components.

Maintains references to all components and managers in a vivarium 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 name

The name of this component.

setup(configuration, lifecycle_manager)[source]

Called by the simulation context.

Parameters:
Return type:

None

add_managers(managers)[source]

Registers new managers with the component manager.

Managers are configured and setup before components.

Parameters:

managers (List[Manager] | Tuple[Manager]) – Instantiated managers to register.

Return type:

None

add_components(components)[source]

Register new components with the component manager.

Components are configured and setup after managers.

Parameters:

components (List[Component] | Tuple[Component]) – Instantiated components to register.

Return type:

None

get_components_by_type(component_type)[source]

Get all components that are an instance of component_type.

Parameters:

component_type (type | Tuple[type, ...]) – A component type.

Returns:

A list of components of type component_type.

Return type:

List[Any]

get_component(name)[source]

Get the component with name name.

Names are guaranteed to be unique.

Parameters:

name (str) – A component name.

Returns:

A component that has name name.

Return type:

Component

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.

Returns:

A mapping of component names to components.

Return type:

Dict[str, Any]

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.

Parameters:

builder (Builder) – Interface to several simulation tools.

Return type:

None

apply_configuration_defaults(component)[source]
Parameters:

component (Component | Manager)

Return type:

None

class vivarium.framework.components.manager.ComponentInterface(manager)[source]

The builder interface for the component manager system. This class defines component manager methods a vivarium component can access from the builder. It provides methods for querying and adding components to the ComponentManager.

Parameters:

manager (ComponentManager)

get_component(name)[source]

Get the component that has name if presently held by the component manager. Names are guaranteed to be unique.

Parameters:

name (str) – A component name.

Return type:

A component that has name name.

get_components_by_type(component_type)[source]

Get all components that are an instance of component_type.

Parameters:

component_type (type | Tuple[type, ...]) – A component type to retrieve, compared against internal components using isinstance().

Returns:

A list of components of type component_type.

Return type:

List[Any]

list_components()[source]

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

Returns:

A dictionary mapping component names to components.

Return type:

Dict[str, Any]