class_docstr: Large-scale implementation of Evolution Strategies in Ray.
class_docstr_tok: ["Large-scale","implementation","of","Evolution","Strategies","in","Ray","."]
code: def _collect_results(self, theta_id, min_episodes, min_timesteps):
      num_episodes, num_timesteps = 0, 0
      results = []
      while (
          num_episodes < min_episodes or num_timesteps < min_timesteps
      ):
          logger.info(
              "Collected {} episodes {} timesteps so far this iter".format(
                  num_episodes, num_timesteps
              )
          )
          rollout_ids = self.workers.foreach_worker(
              func=lambda w: w.do_rollouts(ray.get(theta_id)),
              local_worker=False,
          )
          # Get the results of the rollouts.
          for result in rollout_ids:
              results.append(result)
              # Update the number of episodes and the number of timesteps
              # keeping in mind that result.noisy_lengths is a list of lists,
              # where the inner lists have length 2.
              num_episodes += sum(
                  len(pair) for pair in result.noisy_lengths
              )
              num_timesteps += sum(
                  sum(pair) for pair in result.noisy_lengths
              )
  
      return results, num_episodes, num_timesteps
  
imports: import logging
  import random
  import time
  from collections import namedtuple
  from typing import Dict, List, Optional
  import numpy
  from rllib_es.es import optimizers, utils
  from rllib_es.es.es_tf_policy import ESTFPolicy, rollout
  import ray
  from ray.rllib.algorithms import Algorithm
  from ray.rllib.algorithms.algorithm_config import AlgorithmConfig, NotProvided
  from ray.rllib.env.env_context import EnvContext
  from ray.rllib.evaluation.worker_set import WorkerSet
  from ray.rllib.policy.sample_batch import DEFAULT_POLICY_ID
  from ray.rllib.utils import FilterManager
  from ray.rllib.utils.actor_manager import FaultAwareApply
  from ray.rllib.utils.annotations import override
  from ray.rllib.utils.deprecation import Deprecated
  from ray.rllib.utils.metrics import NUM_AGENT_STEPS_SAMPLED, NUM_AGENT_STEPS_TRAINED, NUM_ENV_STEPS_SAMPLED, NUM_ENV_STEPS_TRAINED
  from ray.rllib.utils.torch_utils import set_torch_seed
  from ray.rllib.utils.typing import PolicyID
label_desc: Use image node_id 10 for calling the ES obj's underlying member method code with example usage: obj._collect_results(theta_id, min_episodes, min_timesteps) and returns: results,  num_episodes,  num_timesteps