code: def custom_eval_function(algorithm, eval_workers):
      """Example of a custom evaluation function.
  
      Args:
          algorithm: Algorithm class to evaluate.
          eval_workers: Evaluation WorkerSet.
  
      Returns:
          metrics: Evaluation metrics dict.
      """
      # Set different env settings for each worker. Here we use the worker's
      # `worker_index` property.
      eval_workers.foreach_worker(
          func=lambda w: w.foreach_env(
              lambda env: env.set_corridor_length(
                  4 if w.worker_index == 1 else 7
              )
          )
      )
  
      for i in range(5):
          print("Custom evaluation round", i)
          # Calling .sample() runs exactly one episode per worker due to how the
          # eval workers are configured.
          eval_workers.foreach_worker(
              func=lambda w: w.sample(), local_worker=False
          )
  
      # Collect the accumulated episodes on the workers, and then summarize the
      # episode stats into a metrics dict.
      episodes = collect_episodes(
          workers=eval_workers, timeout_seconds=99999
      )
      # You can compute metrics from the episodes manually, or use the
      # convenient `summarize_episodes()` utility:
      metrics = summarize_episodes(episodes)
  
      # You can also put custom values in the metrics dict.
      metrics["foo"] = 1
      return metrics
  
file_path: ray/rllib/examples/custom_eval.py
imports: import argparse
  import os
  import ray
  from ray import air, tune
  from ray.rllib.algorithms.ppo import PPOConfig
  from ray.rllib.evaluation.metrics import collect_episodes, summarize_episodes
  from ray.rllib.examples.env.simple_corridor import SimpleCorridor
  from ray.rllib.utils.test_utils import check_learning_achieved
label_desc: Use image node_id 1 for calling a global function with example usage: custom_eval_function(algorithm, eval_workers) and returns: metrics