ray.rllib.utils.metrics.metrics_logger.MetricsLogger#

class ray.rllib.utils.metrics.metrics_logger.MetricsLogger(root=False, stats_cls_lookup: ~typing.Dict[str, ~typing.Type[~ray.rllib.utils.metrics.stats.base.StatsBase]] | None = {'ema': <class 'ray.rllib.utils.metrics.stats.ema.EmaStats'>, 'item': <class 'ray.rllib.utils.metrics.stats.item.ItemStats'>, 'item_series': <class 'ray.rllib.utils.metrics.stats.item_series.ItemSeriesStats'>, 'lifetime_sum': <class 'ray.rllib.utils.metrics.stats.lifetime_sum.LifetimeSumStats'>, 'max': <class 'ray.rllib.utils.metrics.stats.max.MaxStats'>, 'mean': <class 'ray.rllib.utils.metrics.stats.mean.MeanStats'>, 'min': <class 'ray.rllib.utils.metrics.stats.min.MinStats'>, 'percentiles': <class 'ray.rllib.utils.metrics.stats.percentiles.PercentilesStats'>, 'sum': <class 'ray.rllib.utils.metrics.stats.sum.SumStats'>})[source]#

A generic class collecting and reducing metrics.

Use this API to log and merge metrics. Metrics should be logged in parallel components with MetricsLogger.log_value(). RLlib will then aggregate metrics, reduce them and report them.

The MetricsLogger supports logging anything that has a corresponding reduction method. These are defined natively in the Stats classes, which are used to log the metrics. Please take a look ray.rllib.utils.metrics.metrics_logger.DEFAULT_STATS_CLS_LOOKUP for the available reduction methods. You can provide your own reduce methods by extending ray.rllib.utils.metrics.metrics_logger.DEFAULT_STATS_CLS_LOOKUP and passing it to AlgorithmConfig.logging().

Notes on architecture: In our docstrings we make heavy use of the phrase ‘parallel components’. This pertains to the architecture of the logging system, where we have one ‘root’ MetricsLogger that is used to aggregate all metrics of n parallel (‘non-root’) MetricsLoggers that are used to log metrics for each parallel component. A parallel component is typically a single Learner, an EnvRunner, or a ConnectorV2 or any other component of which more than one instance is running in parallel. We also allow intermediate MetricsLoggers that are no root MetricsLogger but are used to aggregate metrics. They are therefore neither root nor leaf.

PublicAPI (alpha): This API is in alpha and may change before becoming stable.

Methods

__init__

Initializes a MetricsLogger instance.

aggregate

Merges n stats_dicts and logs result by merging on the time axis with existing stats.

compile

Compiles all current values and throughputs into a single dictionary.

delete

Deletes the given key from this metrics logger's stats.

get_state

Returns the current state of self as a dict.

log_dict

Logs all leafs of a possibly nested dict of values or Stats objects to this logger.

log_time

Measures and logs a time delta value under key when used with a with-block.

log_value

Logs a new value or item under a (possibly nested) key to the logger.

peek

Returns the reduced values found in this MetricsLogger.

peek_results

Performs peek() on any leaf element of an arbitrarily nested Stats struct.

reduce

Reduces all logged values based on their settings and returns a result dict.

reset

Resets all data stored in this MetricsLogger.

set_state

Sets the state of self to the given state.