Composite, Composer, and MetaComposer Classes¶
-
class
vivarium.core.composer.
Composer
(config: Optional[dict] = None)[source]¶ Bases:
object
Base class for composer classes.
Composers generate composites.
All composer classes must inherit from this class.
- Parameters
config – Dictionary of configuration options that can override the class defaults.
-
generate
(config: Optional[dict] = None, path: Tuple[str, …] = ()) → vivarium.core.composer.Composite[source]¶ Generate processes and topology dictionaries.
- Parameters
config – Updates values in the configuration declared in the constructor.
path – Tuple with (‘path’, ‘to’, ‘level’) associates the processes and topology at this level.
- Returns
Dictionary with the following keys
processes
: Generated bygenerate_processes()
.steps
: Generated bygenerate_steps()
.flow
: Generated bygenerate_flow()
.topology
: Generated bygenerate_topology()
.
The values of these keys are all dictionaries suitable to be passed to the constructor for
vivarium.core.engine.Engine
.
-
generate_flow
(config: Optional[dict]) → Dict[str, Sequence[Tuple[str, …]]][source]¶ Generate the flow of step dependencies.
- Parameters
config – A dictionary of configuration options. All subclass implementation must accept this parameter, but some may ignore it.
- Returns
Subclass implementations should return a dictionary mapping step names to sequences (e.g. lists or tuples) of paths. Steps with no dependencies must be included, but they should be mapped to an empty sequence. Any steps returned by
generate_steps()
orgenerate_processes()
that are not included in the flow will be treated as if they depend on every step previously added to the engine.
-
abstract
generate_processes
(config: Optional[dict]) → Dict[str, Any][source]¶ Generate processes dictionary.
Every subclass must override this method. For backwards compatibility,
vivarium.core.process.Step
objects may be included in the returned dictionary, but this practice is discouraged and may be disallowed in a future release.- Parameters
config – A dictionary of configuration options. All subclass implementation must accept this parameter, but some may ignore it.
- Returns
Subclass implementations must return a dictionary mapping process names to instantiated and configured
vivarium.core.process.Process
objects.
-
generate_steps
(config: Optional[dict]) → Dict[str, Any][source]¶ Generate the steps dictionary.
Subclasses that want to include steps should override this method. This method is the preferred way to specify steps, though they may also be returned by
generate_processes()
.- Parameters
config – A dictionary of configuration options. All subclass implementation must accept this parameter, but some may ignore it.
- Returns
Subclass implementations should return a dictionary mapping step names to instantiated and configured
vivarium.core.process.Step
objects.
-
generate_store
(config: Optional[dict] = None) → vivarium.core.store.Store[source]¶
-
abstract
generate_topology
(config: Optional[dict]) → Dict[str, Union[Tuple[str, …], dict, object]][source]¶ Generate topology dictionary.
Every subclass must override this method.
- Parameters
config – A dictionary of configuration options. All subclass implementation must accept this parameter, but some may ignore it.
- Returns
Subclass implementations must return a topology dictionary.
-
get_parameters
() → dict[source]¶ Get the parameters for all processes.
- Returns
A map from process names to dictionaries of those processes’ parameters.
-
class
vivarium.core.composer.
Composite
(config: Optional[Dict[str, Any]] = None, store: Optional[vivarium.core.store.Store] = None, processes: Optional[Dict[str, Any]] = None, steps: Optional[Dict[str, Any]] = None, flow: Optional[Dict[str, Sequence[Tuple[str, …]]]] = None, topology: Optional[Dict[str, Union[Tuple[str, …], dict, object]]] = None, state: Optional[Dict[str, Any]] = None)[source]¶ Bases:
vivarium.library.datum.Datum
Composite parent class.
Contains keys for processes and topology
-
default_state
(config: Optional[dict] = None) → Optional[Dict[str, Any]][source]¶ Merge all processes’ default states :param config: A dictionary of configuration options. All :type config: dict :param subclass implementation must accept this parameter: :param but: :param some may ignore it.:
- Returns
Subclass implementations must return a dictionary mapping state paths to default values.
- Return type
(dict)
-
generate_store
(config: Optional[dict] = None) → vivarium.core.store.Store[source]¶
-
get_parameters
() → Dict[source]¶ Get the parameters for all processes. :returns: A map from process names to parameters.
-
initial_state
(config: Optional[dict] = None) → Optional[Dict[str, Any]][source]¶ Merge all processes’ initial states :param config: A dictionary of configuration options. All :type config: dict :param subclass implementation must accept this parameter: :param but: :param some may ignore it.:
- Returns
Subclass implementations must return a dictionary mapping state paths to initial values.
- Return type
(dict)
-
merge
(composite: Optional[vivarium.core.composer.Composite] = None, processes: Optional[Dict[str, vivarium.core.process.Process]] = None, topology: Optional[Dict[str, Union[Tuple[str, …], dict, object]]] = None, steps: Optional[Dict[str, Any]] = None, flow: Optional[Dict[str, Sequence[Tuple[str, …]]]] = None, state: Optional[Dict[str, Any]] = None, path: Optional[Tuple[str, …]] = None, schema_override: Optional[Dict[str, Any]] = None) → None[source]¶
-
-
class
vivarium.core.composer.
MetaComposer
(composers: Iterable[Any] = (), config: Optional[dict] = None)[source]¶ Bases:
vivarium.core.composer.Composer
A collection of
Composer
objects.The MetaComposer can be used to create composites that combine all the composers in the collection.
- Parameters
composers – Initial collection of composers.
config – Initial configuration.
-
add_composer
(composer: vivarium.core.composer.Composer, config: Optional[Dict] = None) → None[source]¶ Add a composer to the collection of stored composers.
- Parameters
composer – The composer to add.
config – The composer’s configuration, which will be merged with the stored config.
-
vivarium.core.composer.
get_composite_from_store
(store: vivarium.core.store.Store) → vivarium.core.composer.Composite[source]¶