class_docstr: Train and evaluate DQN on Atari.
class_docstr_tok: ["Train","and","evaluate","DQN","on","Atari","."]
docstr: Run a single episode.
docstr_tok: ["Run","a","single","episode","."]
code: def _run_episode(self, sess, metric_observers, train=False):
      """Run a single episode."""
      env_steps = 0
      time_step = self._env.reset()
      while True:
          with self._collect_timer:
              time_step = self._collect_step(
                  time_step, metric_observers, train=train
              )
              env_steps += 1
  
          if self.game_over():
              break
          elif (
              train
              and self._env_steps_metric.result() % self._update_period
              == 0
          ):
              with self._train_timer:
                  total_loss = self._train_step_call()
                  global_step_val = sess.run(self._global_step)
              self._maybe_log(sess, global_step_val, total_loss)
              self._maybe_record_summaries(global_step_val)
  
      return env_steps
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import os
  from absl import app
  from absl import flags
  from absl import logging
  import gin
  import numpy
  import tensorflow
  from tf_agents.agents.categorical_dqn import categorical_dqn_agent
  from tf_agents.environments import batched_py_environment
  from tf_agents.environments import suite_atari
  from tf_agents.eval import metric_utils
  from tf_agents.metrics import py_metric
  from tf_agents.metrics import py_metrics
  from tf_agents.networks import categorical_q_network
  from tf_agents.networks import network
  from tf_agents.policies import epsilon_greedy_policy
  from tf_agents.policies import py_tf_policy
  from tf_agents.policies import random_py_policy
  from tf_agents.replay_buffers import py_hashed_replay_buffer
  from tf_agents.specs import tensor_spec
  from tf_agents.trajectories import policy_step
  from tf_agents.trajectories import time_step
  from tf_agents.trajectories import trajectory
  from tf_agents.utils import common
  from tf_agents.utils import timer
label_desc: Use image node_id 6 for calling the TrainEval obj's underlying member method code with example usage: obj._run_episode(sess, metric_observers, train) and returns: env_steps