code: def log_multitask_performance(itr, batch, discount, name_map=None):
      r"""Log performance of episodes from multiple tasks.
  
      Args:
          itr (int): Iteration number to be logged.
          batch (EpisodeBatch): Batch of episodes. The episodes should have
              either the "task_name" or "task_id" `env_infos`. If the "task_name"
              is not present, then `name_map` is required, and should map from
              task id's to task names.
          discount (float): Discount used in computing returns.
          name_map (dict[int, str] or None): Mapping from task id's to task
              names. Optional if the "task_name" environment info is present.
              Note that if provided, all tasks listed in this map will be logged,
              even if there are no episodes present for them.
  
      Returns:
          numpy.ndarray: Undiscounted returns averaged across all tasks. Has
              shape :math:`(N \bullet [T])`.
  
      """
      eps_by_name = defaultdict(list)
      for eps in batch.split():
          task_name = "__unnamed_task__"
          if "task_name" in eps.env_infos:
              task_name = eps.env_infos["task_name"][0]
          elif "task_id" in eps.env_infos:
              name_map = {} if name_map is None else name_map
              task_id = eps.env_infos["task_id"][0]
              task_name = name_map.get(
                  task_id, "Task #{}".format(task_id)
              )
          eps_by_name[task_name].append(eps)
      if name_map is None:
          task_names = eps_by_name.keys()
      else:
          task_names = name_map.values()
      for task_name in task_names:
          if task_name in eps_by_name:
              episodes = eps_by_name[task_name]
              log_performance(
                  itr,
                  EpisodeBatch.concatenate(*episodes),
                  discount,
                  prefix=task_name,
              )
          else:
              with tabular.prefix(task_name + "/"):
                  tabular.record("Iteration", itr)
                  tabular.record("NumEpisodes", 0)
                  tabular.record("AverageDiscountedReturn", np.nan)
                  tabular.record("AverageReturn", np.nan)
                  tabular.record("StdReturn", np.nan)
                  tabular.record("MaxReturn", np.nan)
                  tabular.record("MinReturn", np.nan)
                  tabular.record("TerminationRate", np.nan)
                  tabular.record("SuccessRate", np.nan)
  
      return log_performance(
          itr, batch, discount=discount, prefix="Average"
      )
  
file_path: garage/src/garage/_functions.py
imports: from collections import defaultdict
  import time
  import click
  from dowel import tabular
  import numpy
  from garage import EpisodeBatch, StepType
  from garage.np import discount_cumsum, stack_tensor_dict_list
label_desc: Use image node_id 4 for calling a global function with example usage: log_multitask_performance(itr, batch, discount, name_map) and returns: log_performance