class_docstr: Initialize a worker.
  
  Args:
      seed (int): The seed to use to intialize random number generators.
      max_episode_length (int or float): The maximum length of episodes which
          will be sampled. Can be (floating point) infinity.
      worker_number (int): The number of the worker where this update is
          occurring. This argument is used to set a different seed for each
          worker.
  
  Attributes:
      agent (Policy or None): The worker's agent.
      env (Environment or None): The worker's environment.
class_docstr_tok: ["Initialize","a","worker",".","Args",":","seed","(","int",")",":","The","seed","to","use","to","intialize","random","number","generators",".","max_episode_length","(","int","or","float",")",":","The","maximum","length","of","episodes","which","will","be","sampled",".","Can","be","(","floating","point",")","infinity",".","worker_number","(","int",")",":","The","number","of","the","worker","where","this","update","is","occurring",".","This","argument","is","used","to","set","a","different","seed","for","each","worker",".","Attributes",":","agent","(","Policy","or","None",")",":","The","worker","'s","agent",".","env","(","Environment","or","None",")",":","The","worker","'s","environment","."]
docstr: Collect the current episode, clearing the internal buffer.
  
  Returns:
      EpisodeBatch: A batch of the episodes completed since the last call
          to collect_episode().
docstr_tok: ["Collect","the","current","episode",",","clearing","the","internal","buffer",".","Returns",":","EpisodeBatch",":","A","batch","of","the","episodes","completed","since","the","last","call","to","collect_episode","(",")","."]
code: def collect_episode(self):
      """Collect the current episode, clearing the internal buffer.
  
      Returns:
          EpisodeBatch: A batch of the episodes completed since the last call
              to collect_episode().
  
      """
      observations = self._observations
      self._observations = []
      last_observations = self._last_observations
      self._last_observations = []
  
      actions = []
      rewards = []
      env_infos = defaultdict(list)
      step_types = []
  
      for es in self._env_steps:
          actions.append(es.action)
          rewards.append(es.reward)
          step_types.append(es.step_type)
          for k, v in es.env_info.items():
              env_infos[k].append(v)
      self._env_steps = []
  
      agent_infos = self._agent_infos
      self._agent_infos = defaultdict(list)
      for k, v in agent_infos.items():
          agent_infos[k] = np.asarray(v)
  
      for k, v in env_infos.items():
          env_infos[k] = np.asarray(v)
  
      episode_infos = self._episode_infos
      self._episode_infos = defaultdict(list)
      for k, v in episode_infos.items():
          episode_infos[k] = np.asarray(v)
  
      lengths = self._lengths
      self._lengths = []
      return EpisodeBatch(
          env_spec=self.env.spec,
          episode_infos=episode_infos,
          observations=np.asarray(observations),
          last_observations=np.asarray(last_observations),
          actions=np.asarray(actions),
          rewards=np.asarray(rewards),
          step_types=np.asarray(step_types, dtype=StepType),
          env_infos=dict(env_infos),
          agent_infos=dict(agent_infos),
          lengths=np.asarray(lengths, dtype="i"),
      )
  
file_path: garage/src/garage/sampler/default_worker.py
imports: from collections import defaultdict
  import numpy
  from garage import EpisodeBatch, StepType
  from garage.experiment import deterministic
  from garage.sampler import _apply_env_update
  from garage.sampler.worker import Worker
label_desc: Use image node_id 7 for calling the DefaultWorker obj's underlying member method code with example usage: obj.collect_episode() and returns: EpisodeBatch