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

MetricsLogger.peek(key: str | Tuple[str, ...] | None = None, default=None, compile: bool = True, throughput: bool = False) Any[source]#

Returns the reduced values found in this MetricsLogger.

Note that calling this method does NOT cause an actual underlying value list reduction, even though reduced values are being returned. It’ll keep all internal structures as-is. By default, this returns a single reduced value or, if the Stats object has no reduce method, a list of values. When when compile is False, the result is a list of one or more values.

Parameters:
  • key – The key/key sequence of the sub-structure of self, whose (reduced) values to return.

  • default – An optional default value in case key cannot be found in self. If default is not provided and key cannot be found, throws a KeyError.

  • compile – If True, the result is compiled into a single value if possible.

  • throughput – If True, the throughput is returned instead of the actual (reduced) value.

logger = MetricsLogger()
ema = 0.01

# Log some (EMA reduced) values.
key = ("some", "nested", "key", "sequence")
logger.log_value(key, 2.0, ema_coeff=ema)
logger.log_value(key, 3.0)

# Expected reduced value:
expected_reduced = (1.0 - ema) * 2.0 + ema * 3.0

# Peek at the (reduced) value under `key`.
check(logger.peek(key), expected_reduced)

# Peek at the (reduced) nested struct under ("some", "nested").
check(
    logger.peek(("some", "nested")),
    {"key": {"sequence": expected_reduced}},
)

# Log some more, check again.
logger.log_value(key, 4.0)
expected_reduced = (1.0 - ema) * expected_reduced + ema * 4.0
check(logger.peek(key=key), expected_reduced)
Returns:

The (reduced) values of the (possibly nested) sub-structure found under the given key or key sequence.