
    ni                         S r SSKrSSKrSSKJrJrJrJrJr  SSK	r	\	R                   " S S\R                  5      5       r " S S\5      r " S S	\5      rg)
a  The metric reporting system used in our env.

In the gym environment, there are many variables or quantities that can help
researchers to debug, evaluate policy performance. Such quantities may
include: Motor torques for quadrupeds, even when they are controlled in
POSITION mode; Distance to walls while a wheeled robot is navigating the
indoor environment. Often, these metrics are private variables (or can only be
computed from private variables). To expose the user interested metrics
outside the environment's observations, we designed this Metric system that
can be invoked in any modules (robot, tasks, sensors) inside the gym env.
    N)AnyCallableDictSequenceTextc                   (    \ rS rSrSrSrSrSrSrSr	g)	MetricScope   zThe supported scope of metrics.)   )   )   )    N)
__name__
__module____qualname____firstlineno____doc__PERFORMANCEDEBUGSAFETY	STATISTIC__static_attributes__r       j/home/james-whalen/.local/lib/python3.13/site-packages/pybullet_envs/minitaur/envs_v2/evaluation/metric.pyr	   r	      s    '+ % & )r   r	   c                   n    \ rS rSrSrS\S\S\\\	   /\	4   S\\\	   /\
\\	4   4   4S jrS\	4S	 jrS
rg)
MetricCore#   z4Aggregates values of interest to compute statistics.namescopesingle_ep_aggregatormulti_ep_aggregatorc                 X    UR                   S-   U-   U l        X0l        X@l        / U l        g)a  Initializes the class.

Args:
  name: The name of the metric, for example "motor_torques",
    "distance_to_wall", etc. The full name of the metric will have scope
    name in the prefix, i.e. "scope/name".
  scope: The scope of this metric. Most metric should be for DEBUG purpose.
    The scope name will be added to the final name of metric in this way:
      "scope/name", which is standarded format for Tensorboard to group
      named variables.
  single_ep_aggregator: The function to process all aggregated metric
    values. The derived MetricReporter (see below) will implements
    reset_episode() which clears the episode data, and will be called during
    env.reset().
  multi_ep_aggregator: The functions to process multi-episode metric values.
    We assume the inputs to the functions is a list of per episode metric
    values, i.e. each element of the list is the output from the
    single_ep_aggregator.
/N)r   _name_single_ep_aggregator_multi_ep_aggregator_episode_data)selfr   r    r!   r"   s        r   __init__MetricCore.__init__&   s-    4 c!D(DJ!5 3Dr   metric_valuec                 :    U R                   R                  U5        g)zrStores the reported metric in the internal buffer.

Args:
  metric_value: The metric we are interested to report.
N)r(   append)r)   r,   s     r   reportMetricCore.reportE   s     	l+r   )r(   r'   r%   r&   N)r   r   r   r   r   r   r	   r   r   r   r   r*   r/   r   r   r   r   r   r   #   sd    <  %hsm_c%9:	
 $Xc]OT$)_$DE>, ,r   r   c                   h    \ rS rSrSrS\\\\   4   4S jr	S\\\\   4   S\\\4   4S jr
S rSrg	)
MetricReporterN   z;Reports the metric using the provided aggregator functions.returnc                 v    U R                   (       a'  U R                  U R                  U R                   5      0$ 0 $ )zeProcesses and returns episode metric values.

Returns:
  Aggregated metrics for the current episode.
)r(   r%   r&   r)   s    r   get_episode_metric!MetricReporter.get_episode_metricQ   s2     jj$44T5G5GHIIir   episodic_metricc                     U R                   U;  a#  [        R                  " SU R                   5        0 $ 0 nU R                  XR                      5      R	                  5        H  u  p4XBU R                   S-   U-   '   M     U$ )a  Processes the aggregated metrics over many episodes.

Will not be affected by reset_episode, since we take multi-episode data as
inputs.

Args:
  episodic_metric: The per episode metrics. We expect the inputs to contain
    the same key as self._name, and that the value is a list of metric
    values computed using self.get_episode_metrc().

Returns:
  The processed multi-episode metrics.
z>The inputs does not contain the key for the current metric: %s_)r%   loggingwarningr'   items)r)   r9   outputskeyvals        r   get_multi_ep_metric"MetricReporter.get_multi_ep_metric\   s|     zz(oo
J
** iG--

#%%*UW-(+djj3$%- Nr   c                     / U l         g)z}Clears the episode data stored.

Will be invoked during env.reset(). This will effect how get_episode_metric
gets computed.

Nr(   r6   s    r   reset_episodeMetricReporter.reset_episodev   s     Dr   rE   N)r   r   r   r   r   r   r   r   r   r7   rB   rF   r   r   r   r   r2   r2   N   sO    C	$tXc]':"; 	!$"56;?c	?4r   r2   )r   enumr<   typingr   r   r   r   r   ginconstants_from_enumEnumr	   objectr   r2   r   r   r   <module>rN      sY   
   6 6 
 $))  (, (,V/Z /r   