code: def evaluate_for_n_episodes(
      n: int,
      env: EnvWrapper,
      agent: Agent,
      max_steps: Optional[int] = None,
      gammas: Sequence[float] = (1.0,),
      num_processes: int = 0,
  ) -> np.ndarray:
      """Return an np array A of shape n x len(gammas)
      where A[i, j] = ith episode evaluated with gamma=gammas[j].
      Runs environments on num_processes, via multiprocessing.Pool.
      """
      num_processes = min(num_processes, n)
  
      def evaluate_one_episode(
          mdp_id: int,
          env: EnvWrapper,
          agent: Agent,
          max_steps: Optional[int],
          gammas: Sequence[float],
      ) -> np.ndarray:
          rewards = np.empty((len(gammas),))
          trajectory = run_episode(
              env=env, agent=agent, mdp_id=mdp_id, max_steps=max_steps
          )
          for i_gamma, gamma in enumerate(gammas):
              rewards[i_gamma] = trajectory.calculate_cumulative_reward(
                  gamma
              )
          return rewards
  
      rewards = None
      if num_processes > 1:
          try:
              with mp.Pool(num_processes) as pool:
                  rewards = unwrap_function_outputs(
                      pool.map(
                          wrap_function_arguments(
                              evaluate_one_episode,
                              env=env,
                              agent=agent,
                              max_steps=max_steps,
                              gammas=gammas,
                          ),
                          range(n),
                      )
                  )
          except pickle.PickleError as e:
              # NOTE: Probably tried to perform mixed serialization of ScriptModule
              # and non-script modules. This isn't supported right now.
              logger.info(e)
              logger.info(
                  "This is probably from trying to serialize a TorchScript module, "
                  "wrapped in a non-script module. Mixed serialization is not supported."
              )
  
      # if we didn't run multiprocessing, or it failed, try single-processing instead.
      if rewards is None:
          rewards = []
          for i in range(n):
              rewards.append(
                  evaluate_one_episode(
                      mdp_id=i,
                      env=env,
                      agent=agent,
                      max_steps=max_steps,
                      gammas=gammas,
                  )
              )
  
      rewards = np.array(rewards)
      for i, gamma in enumerate(gammas):
          gamma_rewards = rewards[:, i]
          logger.info(
              f"For gamma={gamma}, average reward is {gamma_rewards.mean()}\n"
              f"Rewards list: {gamma_rewards}"
          )
      return rewards
  
file_path: ReAgent/reagent/gym/runners/gymrunner.py
imports: import logging
  import pickle
  from typing import Optional, Sequence
  import numpy
  import torch.multiprocessing
  from reagent.core.multiprocess_utils import unwrap_function_outputs, wrap_function_arguments
  from reagent.core.tensorboardX import SummaryWriterContext
  from reagent.gym.agents.agent import Agent
  from reagent.gym.envs import EnvWrapper
  from reagent.gym.types import Trajectory, Transition
label_desc: Use image node_id 2 for calling a global function with example usage: evaluate_for_n_episodes(n, env, agent, max_steps, gammas, num_processes) and returns: rewards, rewards