class_docstr: A sampler worker for Task Embedding Algorithm.
  
  In addition to DefaultWorker, this worker adds one-hot task id to env_info,
  and adds latent and latent infos to agent_info.
  
  Args:
      seed (int): The seed to use to intialize random number generators.
      max_episode_length (int or float): The maximum length of episodes to
          sample. 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.
  
  One-hot task id is saved in env_infos['task_onehot']. Latent is saved
  in agent_infos['latent']. Latent infos are saved in
  agent_infos['latent_info_name'], where info_name is the original latent
  info name.
  
  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",".","One-hot","task","id","is","saved","in","env_infos","[","'task_onehot","'","]",".","Latent","is","saved","in","agent_infos","[","'latent","'","]",".","Latent","infos","are","saved","in","agent_infos","[","'latent_info_name","'","]",",","where","info_name","is","the","original","latent","info","name",".","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.
  
      One-hot task id is saved in env_infos['task_onehot']. Latent is saved
      in agent_infos['latent']. Latent infos are saved in
      agent_infos['latent_info_name'], where info_name is the original latent
      info name.
  
      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 = []
  
      latents = self._latents
      self._latents = []
      tasks = self._tasks
      self._tasks = []
  
      agent_infos = self._agent_infos
      self._agent_infos = defaultdict(list)
      latent_infos = self._latent_infos
      self._latent_infos = defaultdict(list)
      episode_infos = self._episode_infos
      self._episode_infos = defaultdict(list)
      for k, v in latent_infos.items():
          latent_infos[k] = np.asarray(v)
      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)
      for k, v in episode_infos.items():
          episode_infos[k] = np.asarray(v)
      env_infos["task_onehot"] = np.asarray(tasks)
      agent_infos["latent"] = np.asarray(latents)
      for k, v in latent_infos.items():
          agent_infos["latent_{}".format(k)] = 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=(env_infos),
          agent_infos=dict(agent_infos),
          lengths=np.asarray(lengths, dtype="i"),
      )
  
file_path: garage/src/garage/tf/algos/te.py
imports: from collections import defaultdict
  import numpy
  from garage import EpisodeBatch, StepType
  from garage.sampler import DefaultWorker
label_desc: Use image node_id 4 for calling the TaskEmbeddingWorker obj's underlying member method code with example usage: obj.collect_episode() and returns: EpisodeBatch