code: def collect_episodes(
      workers: "WorkerSet",
      remote_worker_ids: Optional[List[int]] = None,
      timeout_seconds: int = 180,
  ) -> List[RolloutMetrics]:
      """Gathers new episodes metrics tuples from the given RolloutWorkers.
  
      Args:
          workers: WorkerSet.
          remote_worker_ids: Optional list of IDs of remote workers to collect
              metrics from.
          timeout_seconds: Timeout in seconds for collecting metrics from remote workers.
  
      Returns:
          List of RolloutMetrics.
      """
      # This will drop get_metrics() calls that are too slow.
      # We can potentially make this an asynchronous call if this turns
      # out to be a problem.
      metric_lists = workers.foreach_worker(
          lambda w: w.get_metrics(),
          local_worker=True,
          remote_worker_ids=remote_worker_ids,
          timeout_seconds=timeout_seconds,
      )
      if len(metric_lists) == 0:
          logger.warning("WARNING: collected no metrics.")
  
      episodes = []
      for metrics in metric_lists:
          episodes.extend(metrics)
  
      return episodes
  
file_path: ray/rllib/evaluation/metrics.py
imports: import collections
  import logging
  import numpy
  from typing import Any, Dict, List, Optional, TYPE_CHECKING
  from ray.rllib.policy.sample_batch import DEFAULT_POLICY_ID
  from ray.rllib.utils.annotations import DeveloperAPI
  from ray.rllib.utils.metrics.learner_info import LEARNER_STATS_KEY
  from ray.rllib.utils.typing import GradInfoDict, LearnerStatsDict, ResultDict
label_desc: Use image node_id 4 for calling a global function with example usage: collect_episodes(workers, remote_worker_ids, timeout_seconds) and returns: episodes