code: def compute(metrics, environment, policy, num_episodes=1):
      """Compute metrics using `policy` on the `environment`.
  
      Args:
        metrics: List of metrics to compute.
        environment: py_environment instance.
        policy: py_policy instance used to step the environment. A tf_policy can be
          used in_eager_mode.
        num_episodes: Number of episodes to compute the metrics over.
  
      Returns:
        A dictionary of results {metric_name: metric_value}
      """
      for metric in metrics:
          metric.reset()
  
      time_step = environment.reset()
      policy_state = policy.get_initial_state(environment.batch_size)
  
      driver = py_driver.PyDriver(
          environment,
          policy,
          observers=metrics,
          max_steps=None,
          max_episodes=num_episodes,
      )
      driver.run(time_step, policy_state)
  
      results = [(metric.name, metric.result()) for metric in metrics]
      return collections.OrderedDict(results)
  
file_path: agents/tf_agents/eval/metric_utils.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import collections
  from absl import logging
  import gin
  import tensorflow
  from tf_agents.drivers import dynamic_episode_driver
  from tf_agents.drivers import py_driver
  from tf_agents.metrics import py_metric
  from tf_agents.utils import common
label_desc: Use image node_id 2 for calling a global function with example usage: compute(metrics, environment, policy, num_episodes) and returns: collections