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)
- class vivarium.engine.framework.components.manager.ComponentManager[source]
Manages the initialization and setup of
vivarium.enginecomponents.Maintains references to all components and managers in a
vivarium.enginesimulation, applies their default configuration and initiates theirsetuplife-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
setuplifecycle 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’ssetupmethod.- property configuration: ConfigTree
The configuration tree for the simulation.
- 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:
- Parameters:
configuration (ConfigTree)
lifecycle_manager (LifeCycleManager)
- add_managers(managers)[source]
Registers new managers with the component manager.
Managers are configured and setup before components.
- add_components(components)[source]
Register new components with the component manager.
Components are configured and setup after managers.
- get_components_by_type(component_type)[source]
Get all components that are an instance of
component_type.
- get_component(name)[source]
Get the component with name
name.Names are guaranteed to be unique.
- Return type:
- Parameters:
name (str) – A component name.
- Returns:
A component that has name
name.- Raises:
ValueError – No component exists in the component manager with
name.
- get_current_component()[source]
Get the component currently being set up, if any.
- Return type:
- 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:
- 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_componenttocomponentfor 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
setupcallssuper().setup) work correctly.
- 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.