class_docstr: RL^2.
  
  Reference: https://arxiv.org/pdf/1611.02779.pdf.
  
  When sampling for RL^2, there are more than one environments to be
  sampled from. In the original implementation, within each task/environment,
  all episodes sampled will be concatenated into one single episode, and fed
  to the inner algorithm. Thus, returns and advantages are calculated across
  the episode.
  
  RL2Worker is required in sampling for RL2.
  See example/tf/rl2_ppo_halfcheetah.py for reference.
  
  User should not instantiate RL2 directly.
  Currently garage supports PPO and TRPO as inner algorithm. Refer to
  garage/tf/algos/rl2ppo.py and garage/tf/algos/rl2trpo.py.
  
  Args:
      env_spec (EnvSpec): Environment specification.
      episodes_per_trial (int): Used to calculate the max episode length for
          the inner algorithm.
      meta_batch_size (int): Meta batch size.
      task_sampler (TaskSampler): Task sampler.
      meta_evaluator (MetaEvaluator): Evaluator for meta-RL algorithms.
      n_epochs_per_eval (int): If meta_evaluator is passed, meta-evaluation
          will be performed every `n_epochs_per_eval` epochs.
      inner_algo_args (dict): Arguments for inner algorithm.
class_docstr_tok: ["RL^2",".","Reference",":","https",":","\/\/arxiv.org\/pdf\/1611.02779.pdf",".","When","sampling","for","RL^2",",","there","are","more","than","one","environments","to","be","sampled","from",".","In","the","original","implementation",",","within","each","task\/environment",",","all","episodes","sampled","will","be","concatenated","into","one","single","episode",",","and","fed","to","the","inner","algorithm",".","Thus",",","returns","and","advantages","are","calculated","across","the","episode",".","RL2Worker","is","required","in","sampling","for","RL2",".","See","example\/tf\/rl2_ppo_halfcheetah.py","for","reference",".","User","should","not","instantiate","RL2","directly",".","Currently","garage","supports","PPO","and","TRPO","as","inner","algorithm",".","Refer","to","garage\/tf\/algos\/rl2ppo.py","and","garage\/tf\/algos\/rl2trpo.py",".","Args",":","env_spec","(","EnvSpec",")",":","Environment","specification",".","episodes_per_trial","(","int",")",":","Used","to","calculate","the","max","episode","length","for","the","inner","algorithm",".","meta_batch_size","(","int",")",":","Meta","batch","size",".","task_sampler","(","TaskSampler",")",":","Task","sampler",".","meta_evaluator","(","MetaEvaluator",")",":","Evaluator","for","meta-RL","algorithms",".","n_epochs_per_eval","(","int",")",":","If","meta_evaluator","is","passed",",","meta-evaluation","will","be","performed","every","`","n_epochs_per_eval","`","epochs",".","inner_algo_args","(","dict",")",":","Arguments","for","inner","algorithm","."]
docstr: Concatenate episodes.
  
  The input list contains samples from different episodes but same
  task/environment. In RL^2, paths within each meta batch are all
  concatenate into a single path and fed to the policy.
  
  Args:
      episode_list (list[EpisodeBatch]): Input paths. All paths are from
          different episodes, but the same task/environment.
  
  Returns:
      EpisodeBatch: Concatenated episode from the same task/environment.
          Shape of values: :math:`[max_episode_length * episode_per_task,
          S^*]`
docstr_tok: ["Concatenate","episodes",".","The","input","list","contains","samples","from","different","episodes","but","same","task\/environment",".","In","RL^2",",","paths","within","each","meta","batch","are","all","concatenate","into","a","single","path","and","fed","to","the","policy",".","Args",":","episode_list","(","list","[","EpisodeBatch","]",")",":","Input","paths",".","All","paths","are","from","different","episodes",",","but","the","same","task\/environment",".","Returns",":","EpisodeBatch",":","Concatenated","episode","from","the","same","task\/environment",".","Shape","of","values",":",":","math",":","`","[","max_episode_length","*","episode_per_task",",","S^","*","]","`"]
code: def _concatenate_episodes(self, episode_list):
      """Concatenate episodes.
  
      The input list contains samples from different episodes but same
      task/environment. In RL^2, paths within each meta batch are all
      concatenate into a single path and fed to the policy.
  
      Args:
          episode_list (list[EpisodeBatch]): Input paths. All paths are from
              different episodes, but the same task/environment.
  
      Returns:
          EpisodeBatch: Concatenated episode from the same task/environment.
              Shape of values: :math:`[max_episode_length * episode_per_task,
              S^*]`
  
      """
      env_infos = {
          k: np.concatenate([b.env_infos[k] for b in episode_list])
          for k in episode_list[0].env_infos.keys()
      }
      agent_infos = {
          k: np.concatenate([b.agent_infos[k] for b in episode_list])
          for k in episode_list[0].agent_infos.keys()
      }
      episode_infos = {
          k: np.concatenate([b.episode_infos[k] for b in episode_list])
          for k in episode_list[0].episode_infos.keys()
      }
      actions = np.concatenate(
          [
              self._env_spec.action_space.flatten_n(ep.actions)
              for ep in episode_list
          ]
      )
  
      return EpisodeBatch(
          env_spec=episode_list[0].env_spec,
          episode_infos=episode_infos,
          observations=np.concatenate(
              [ep.observations for ep in episode_list]
          ),
          last_observations=episode_list[-1].last_observations,
          actions=actions,
          rewards=np.concatenate([ep.rewards for ep in episode_list]),
          env_infos=env_infos,
          agent_infos=agent_infos,
          step_types=np.concatenate(
              [ep.step_types for ep in episode_list]
          ),
          lengths=np.asarray(
              [sum([ep.lengths[0] for ep in episode_list])]
          ),
      )
  
imports: import abc
  import collections
  import akro
  from dowel import logger
  import numpy
  from garage import EnvSpec, EnvStep, EpisodeBatch, log_multitask_performance, StepType, Wrapper
  from garage.np.algos import MetaRLAlgorithm
  from garage.sampler import DefaultWorker
  from garage.tf.algos._rl2npo import RL2NPO
label_desc: Use image node_id 7 for calling the RL2 obj's underlying member method code with example usage: obj._concatenate_episodes(episode_list) and returns: EpisodeBatch