class_docstr: Runner for evaluating using a fixed number of episodes rather than steps.
  
  Also restricts data collection to a strict cap,
  following conventions in data-efficient RL research.
class_docstr_tok: ["Runner","for","evaluating","using","a","fixed","number","of","episodes","rather","than","steps",".","Also","restricts","data","collection","to","a","strict","cap",",","following","conventions","in","data-efficient","RL","research","."]
docstr: Runs the agent/environment loop until a desired number of steps.
  
  We terminate precisely when the desired number of steps has been reached,
  unlike some other implementations.
  
  Args:
    envs: environments to use in this phase.
    steps: int, how many steps to run in this phase (or None).
    max_episodes: int, maximum number of episodes to generate in this phase.
    statistics: `IterationStatistics` object which records the experimental
      results.
    run_mode_str: str, describes the run mode for this agent.
    needs_reset: bool, whether to reset all environments before starting.
    one_to_one: bool, whether to precisely match each episode in
      `max_episodes` to an environment in `envs`. True is faster but only
      works in some situations (e.g., evaluation).
    resume_state: bool, whether to have the agent resume its prior state for
      the current mode.
  
  Returns:
    Tuple containing the number of steps taken in this phase (int), the
    sum of
      returns (float), and the number of episodes performed (int).
docstr_tok: ["Runs","the","agent\/environment","loop","until","a","desired","number","of","steps",".","We","terminate","precisely","when","the","desired","number","of","steps","has","been","reached",",","unlike","some","other","implementations",".","Args",":","envs",":","environments","to","use","in","this","phase",".","steps",":","int",",","how","many","steps","to","run","in","this","phase","(","or","None",")",".","max_episodes",":","int",",","maximum","number","of","episodes","to","generate","in","this","phase",".","statistics",":","`","IterationStatistics","`","object","which","records","the","experimental","results",".","run_mode_str",":","str",",","describes","the","run","mode","for","this","agent",".","needs_reset",":","bool",",","whether","to","reset","all","environments","before","starting",".","one_to_one",":","bool",",","whether","to","precisely","match","each","episode","in","`","max_episodes","`","to","an","environment","in","`","envs","`",".","True","is","faster","but","only","works","in","some","situations","(","e.g.",",","evaluation",")",".","resume_state",":","bool",",","whether","to","have","the","agent","resume","its","prior","state","for","the","current","mode",".","Returns",":","Tuple","containing","the","number","of","steps","taken","in","this","phase","(","int",")",",","the","sum","of","returns","(","float",")",",","and","the","number","of","episodes","performed","(","int",")","."]
code: def _run_one_phase(
      self,
      envs,
      steps,
      max_episodes,
      statistics,
      run_mode_str,
      needs_reset=False,
      one_to_one=False,
      resume_state=None,
  ):
      """Runs the agent/environment loop until a desired number of steps.
  
      We terminate precisely when the desired number of steps has been reached,
      unlike some other implementations.
  
      Args:
        envs: environments to use in this phase.
        steps: int, how many steps to run in this phase (or None).
        max_episodes: int, maximum number of episodes to generate in this phase.
        statistics: `IterationStatistics` object which records the experimental
          results.
        run_mode_str: str, describes the run mode for this agent.
        needs_reset: bool, whether to reset all environments before starting.
        one_to_one: bool, whether to precisely match each episode in
          `max_episodes` to an environment in `envs`. True is faster but only
          works in some situations (e.g., evaluation).
        resume_state: bool, whether to have the agent resume its prior state for
          the current mode.
  
      Returns:
        Tuple containing the number of steps taken in this phase (int), the
        sum of
          returns (float), and the number of episodes performed (int).
      """
      step_count = 0
      num_episodes = 0
      sum_returns = 0.0
  
      (
          episode_lengths,
          episode_returns,
          state,
          envs,
      ) = self._run_parallel(
          episodes=max_episodes,
          envs=envs,
          one_to_one=one_to_one,
          needs_reset=needs_reset,
          resume_state=resume_state,
          max_steps=steps,
      )
  
      for episode_length, episode_return in zip(
          episode_lengths, episode_returns
      ):
          statistics.append(
              {
                  "{}_episode_lengths".format(
                      run_mode_str
                  ): episode_length,
                  "{}_episode_returns".format(
                      run_mode_str
                  ): episode_return,
              }
          )
          if run_mode_str == "train":
              # we use one extra frame at the starting
              self.num_steps += episode_length
          step_count += episode_length
          sum_returns += episode_return
          num_episodes += 1
          sys.stdout.flush()
          if self._summary_writer is not None:
              with self._summary_writer.as_default():
                  _ = (
                      tf.summary.scalar(
                          "train_episode_returns",
                          float(episode_return),
                          step=self.num_steps,
                      ),
                  )
                  _ = tf.summary.scalar(
                      "train_episode_lengths",
                      float(episode_length),
                      step=self.num_steps,
                  )
      return step_count, sum_returns, num_episodes, state, envs
  
imports: import functools
  import os
  import sys
  import time
  from absl import logging
  from dopamine.discrete_domains import atari_lib
  from dopamine.discrete_domains import iteration_statistics
  from dopamine.discrete_domains import run_experiment
  from dopamine.labs.atari_100k import normalization_utils
  from dopamine.metrics import collector_dispatcher
  from dopamine.metrics import statistics_instance
  import gin
  import jax
  import numpy
  import tensorflow
label_desc: Use image node_id 2 for calling the DataEfficientAtariRunner obj's underlying member method code with example usage: obj._run_one_phase(envs, steps, max_episodes, statistics, run_mode_str, needs_reset, one_to_one, resume_state) and returns: step_count,  sum_returns,  num_episodes,  state,  envs