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
Initializes a MetricsLogger instance.
Merges n stats_dicts and logs result by merging on the time axis with existing stats.
Compiles all current values and throughputs into a single dictionary.
Deletes the given
keyfrom this metrics logger's stats.Returns the current state of
selfas a dict.Logs all leafs of a possibly nested dict of values or Stats objects to this logger.
Measures and logs a time delta value under
keywhen used with a with-block.Logs a new value or item under a (possibly nested) key to the logger.
Returns the reduced values found in this MetricsLogger.
Performs
peek()on any leaf element of an arbitrarily nested Stats struct.Reduces all logged values based on their settings and returns a result dict.
Resets all data stored in this MetricsLogger.
Sets the state of
selfto the givenstate.