class_docstr: The rollout generation is bound to a single worker environment by implementing it as a Wrapper class.
class_docstr_tok: ["The","rollout","generation","is","bound","to","a","single","worker","environment","by","implementing","it","as","a","Wrapper","class","."]
docstr: Use the passed policy to step the environment until it is done.
  
  This method does not return any results, query the episode statistics instead to process the results.
  
  :param policy: Multi-step policy encapsulating the policy networks
docstr_tok: ["Use","the","passed","policy","to","step","the","environment","until","it","is","done",".","This","method","does","not","return","any","results",",","query","the","episode","statistics","instead","to","process","the","results",".",":","param","policy",":","Multi-step","policy","encapsulating","the","policy","networks"]
code: def rollout(self, policy: Union[Policy, TorchModel]) -> None:
      """Use the passed policy to step the environment until it is done.
  
      This method does not return any results, query the episode statistics instead to process the results.
  
      :param policy: Multi-step policy encapsulating the policy networks
      """
      observation = self.reset()
  
      start_time = time.time()
  
      for _ in itertools.count():
          if self.abort:
              raise ESAbortException()
  
          with torch.no_grad():
              action = policy.compute_action(
                  observation=observation,
                  actor_id=self.actor_id(),
                  maze_state=self.get_maze_state()
                  if policy.needs_state()
                  else None,
                  env=self if policy.needs_env() else None,
                  deterministic=False,
              )
  
          observation, reward, done, _ = self.step(
              convert_to_numpy(action, cast=None, in_place=False)
          )
  
          if done:
              break
  
      # reset makes the episode stats available
      self.reset()
  
      logger.debug(
          f"Rollout took {(time.time() - start_time) :.1f} seconds"
      )
  
imports: import itertools
  import logging
  import time
  from typing import TypeVar, Union
  import numpy
  import torch
  from maze.core.agent.policy import Policy
  from maze.core.agent.torch_model import TorchModel
  from maze.core.env.structured_env import StructuredEnv
  from maze.core.log_stats.log_stats import LogStatsLevel
  from maze.core.log_stats.log_stats_env import LogStatsEnv
  from maze.core.wrappers.wrapper import Wrapper
  from maze.perception.perception_utils import convert_to_numpy
  from maze.train.trainers.es.distributed.es_distributed_rollouts import ESRolloutResult
  from maze.train.trainers.es.es_shared_noise_table import SharedNoiseTable
  from maze.train.trainers.es.es_utils import get_flat_parameters, set_flat_parameters
label_desc: Use image node_id 4 for calling the ESRolloutWorkerWrapper obj's underlying member method code with example usage: obj.rollout(policy) without return types