Results Manager
- class vivarium.engine.framework.results.manager.ResultsManager[source]
Backend manager object for the results management system.
This class contains the public methods used by the
ResultsInterfaceto register stratifications and observations as well as theget_resultsmethod used to retrieve formatted results by theResultsContext.-
CONFIGURATION_DEFAULTS:
dict[str,Any] = {'stratification': {'default': [], 'excluded_categories': {}}} A dictionary containing the defaults for any configurations managed by this manager. An empty dictionary indicates no managed configurations.
- on_post_setup(_)[source]
Sets stratifications on observations and initializes results for each measure.
- on_time_step_prepare(event)[source]
Defines the listener callable for the time_step__prepare phase.
- on_time_step_cleanup(event)[source]
Defines the listener callable for the time_step__cleanup phase.
- set_default_stratifications(builder)[source]
Sets the default stratifications for the results context.
This passes the default stratifications from the configuration to the
ResultsContextset_default_stratifications()method to be set.
- register_stratification(name, categories, excluded_categories, mapper, is_vectorized, requires_attributes=[])[source]
Registers a stratification that can be used by stratified observations.
Adds a stratification to the
ResultsContextas well as the stratification’s required resources to this manager.- Return type:
- Parameters:
name (str) – Name of the stratification.
categories (list[str]) – Exhaustive list of all possible stratification values.
excluded_categories (list[str] | None) – List of possible stratification values to exclude from results processing. If None (the default), will use exclusions as defined in the configuration.
mapper (Callable[[DataFrame], Series] | Callable[[Series], str] | None) – A callable that maps population attributes specified by the requires_attributes argument to the stratification categories. It can either map the entire population or an individual simulant. A simulation will fail if the mapper ever produces an invalid value.
is_vectorized (bool) – True if the mapper function will map the entire population, and False if it will only map a single simulant.
requires_attributes (list[str]) – A list of the state table columns that are required by the mapper to produce the stratification.
- register_binned_stratification(target, binned_column, bin_edges, labels, excluded_categories, **cut_kwargs)[source]
Registers a continuous target quantity to observe into bins in a binned_column.
- Return type:
- Parameters:
target (str) – Name of population attribute to be binned.
binned_column (str) – Name of the (binned) stratification.
bin_edges (Sequence[int | float]) – List of scalars defining the bin edges, passed to :meth: pandas.cut. The length must be equal to the length of labels plus 1.
labels (list[str]) – List of string labels for bins. The length must be equal to the length of bin_edges minus 1.
excluded_categories (list[str] | None) – List of possible stratification values to exclude from results processing. If None (the default), will use exclusions as defined in the configuration.
**cut_kwargs (int | str | bool) – Keyword arguments for :meth: pandas.cut.
- register_observation(observation_type, name, population_filter, when, requires_attributes, **kwargs)[source]
Registers an observation to the results system.
- Return type:
- Parameters:
observation_type (type[Observation]) – Specific class type of observation to register.
name (str) – Name of the observation. It will also be the name of the output results file for this particular observation.
population_filter (PopulationFilter) – A named tuple of population filtering details. The first item is a Pandas query string to filter the population down to the simulants who should be considered for the observation. The second item is a boolean indicating whether to include untracked simulants from the observation.
when (str) – Name of the lifecycle phase the observation should happen. Valid values are: “time_step__prepare”, “time_step”, “time_step__cleanup”, or “collect_metrics”.
requires_attributes (list[str]) – The population attributes that are required to compute the observation.
**kwargs (Any) – Additional keyword arguments to be passed to the observation’s constructor.
-
CONFIGURATION_DEFAULTS: