class_docstr: Append a one-hot task representation to an environment.
  
  See TaskOnehotWrapper.wrap_env_list for the recommended way of creating
  this class.
  
  Args:
      env (Environment): The environment to wrap.
      task_index (int): The index of this task among the tasks.
      n_total_tasks (int): The number of total tasks.
class_docstr_tok: ["Append","a","one-hot","task","representation","to","an","environment",".","See","TaskOnehotWrapper.wrap_env_list","for","the","recommended","way","of","creating","this","class",".","Args",":","env","(","Environment",")",":","The","environment","to","wrap",".","task_index","(","int",")",":","The","index","of","this","task","among","the","tasks",".","n_total_tasks","(","int",")",":","The","number","of","total","tasks","."]
docstr: Wrap a list of environment constructors, giving each a one-hot.
  
  This function is useful if you want to avoid constructing any
  environments in the main experiment process, and are using a multi-task
  aware remote sampler (i.e. `~RaySampler`).
  
  For example:
  '''
  .. code-block:: python
  
      env_constructors = get_mt10_env_cons()
      wrapped = TaskOnehotWrapper.wrap_env_cons_list(env_constructors)
      env_updates = [NewEnvUpdate(wrapped_con)
                     for wrapped_con in wrapped]
      sampler = trainer.make_sampler(RaySampler, env=env_updates)
  '''
  
  
  Args:
      env_cons (list[Callable[Environment]]): List of environment
      constructor
          to wrap. Note that the order these constructors are passed in
          determines the value of their one-hot encoding. It is essential
          that this list is always in the same order, or the resulting
          encodings will be inconsistent.
  
  Returns:
      list[Callable[TaskOnehotWrapper]]: The wrapped environments.
docstr_tok: ["Wrap","a","list","of","environment","constructors",",","giving","each","a","one-hot",".","This","function","is","useful","if","you","want","to","avoid","constructing","any","environments","in","the","main","experiment","process",",","and","are","using","a","multi-task","aware","remote","sampler","(","i.e",".","`","~RaySampler","`",")",".","For","example",":","''","'","..","code-block",":",":","python","env_constructors","=","get_mt10_env_cons","(",")","wrapped","=","TaskOnehotWrapper.wrap_env_cons_list","(","env_constructors",")","env_updates","=","[","NewEnvUpdate","(","wrapped_con",")","for","wrapped_con","in","wrapped","]","sampler","=","trainer.make_sampler","(","RaySampler",",","env=env_updates",")","''","'","Args",":","env_cons","(","list","[","Callable","[","Environment","]","]",")",":","List","of","environment","constructor","to","wrap",".","Note","that","the","order","these","constructors","are","passed","in","determines","the","value","of","their","one-hot","encoding",".","It","is","essential","that","this","list","is","always","in","the","same","order",",","or","the","resulting","encodings","will","be","inconsistent",".","Returns",":","list","[","Callable","[","TaskOnehotWrapper","]","]",":","The","wrapped","environments","."]
code: def wrap_env_cons_list(cls, env_cons):
      """Wrap a list of environment constructors, giving each a one-hot.
  
      This function is useful if you want to avoid constructing any
      environments in the main experiment process, and are using a multi-task
      aware remote sampler (i.e. `~RaySampler`).
  
      For example:
      '''
      .. code-block:: python
  
          env_constructors = get_mt10_env_cons()
          wrapped = TaskOnehotWrapper.wrap_env_cons_list(env_constructors)
          env_updates = [NewEnvUpdate(wrapped_con)
                         for wrapped_con in wrapped]
          sampler = trainer.make_sampler(RaySampler, env=env_updates)
      '''
  
  
      Args:
          env_cons (list[Callable[Environment]]): List of environment
          constructor
              to wrap. Note that the order these constructors are passed in
              determines the value of their one-hot encoding. It is essential
              that this list is always in the same order, or the resulting
              encodings will be inconsistent.
  
      Returns:
          list[Callable[TaskOnehotWrapper]]: The wrapped environments.
  
      """
      n_total_tasks = len(env_cons)
      wrapped = []
      for i, con in enumerate(env_cons):
          # Manually capture this value of i by introducing a new scope.
          wrapped.append(
              lambda i=i, con=con: cls(
                  con(), task_index=i, n_total_tasks=n_total_tasks
              )
          )
      return wrapped
  
file_path: garage/src/garage/envs/task_onehot_wrapper.py
imports: import akro
  import numpy
  from garage import EnvSpec, EnvStep, Wrapper
label_desc: Use image node_id 8 for calling the TaskOnehotWrapper obj's underlying member method code with example usage: obj.wrap_env_cons_list(cls, env_cons) and returns: wrapped