class_docstr: A driver that takes N episodes in an environment using a tf.while_loop.
  
  The while loop will run num_episodes in the environment, counting transitions
  that result in ending an episode.
  
  As environments run batched time_episodes, the counters for all batch elements
  are summed, and execution stops when the total exceeds num_episodes.
  
  This termination condition can be overridden in subclasses by implementing the
  self._loop_condition_fn() method.
class_docstr_tok: ["A","driver","that","takes","N","episodes","in","an","environment","using","a","tf.while_loop",".","The","while","loop","will","run","num_episodes","in","the","environment",",","counting","transitions","that","result","in","ending","an","episode",".","As","environments","run","batched","time_episodes",",","the","counters","for","all","batch","elements","are","summed",",","and","execution","stops","when","the","total","exceeds","num_episodes",".","This","termination","condition","can","be","overridden","in","subclasses","by","implementing","the","self._loop_condition_fn","(",")","method","."]
docstr: Takes episodes in the environment using the policy and update observers.
  
  If `time_step` and `policy_state` are not provided, `run` will reset the
  environment and request an initial state from the policy.
  
  **Note** about bias when using batched environments with `num_episodes`:
  When using `num_episodes != None`, a `run` step "finishes" collecting
  `num_episodes` have been completely collected (hit a boundary).
  When used in conjunction with environments that have variable-length
  episodes, this skews the distribution of collected episodes' lengths:
  short episodes are seen more frequently than long ones.
  As a result, running an `env` of `N > 1` batched environments
  with `num_episodes >= 1` is not the same as running an env with `1`
  environment with `num_episodes >= 1`.
  
  Args:
    time_step: optional initial time_step. If None, it will be obtained by
      resetting the environment. Elements should be shape [batch_size, ...].
    policy_state: optional initial state for the policy. If None, it will be
      obtained from the policy.get_initial_state().
    num_episodes: Optional number of episodes to take in the environment. If
      None it would use initial num_episodes.
    maximum_iterations: Optional maximum number of iterations of the while
      loop to run. If provided, the cond output is AND-ed with an additional
      condition ensuring the number of iterations executed is no greater than
      maximum_iterations.
  
  Returns:
    time_step: TimeStep named tuple with final observation, reward, etc.
    policy_state: Tensor with final step policy state.
docstr_tok: ["Takes","episodes","in","the","environment","using","the","policy","and","update","observers",".","If","`","time_step","`","and","`","policy_state","`","are","not","provided",",","`","run","`","will","reset","the","environment","and","request","an","initial","state","from","the","policy",".","*","*","Note","*","*","about","bias","when","using","batched","environments","with","`","num_episodes","`",":","When","using","`","num_episodes","!","=","None","`",",","a","`","run","`","step","``","finishes","''","collecting","`","num_episodes","`","have","been","completely","collected","(","hit","a","boundary",")",".","When","used","in","conjunction","with","environments","that","have","variable-length","episodes",",","this","skews","the","distribution","of","collected","episodes","'","lengths",":","short","episodes","are","seen","more","frequently","than","long","ones",".","As","a","result",",","running","an","`","env","`","of","`","N",">","1","`","batched","environments","with","`","num_episodes",">","=","1","`","is","not","the","same","as","running","an","env","with","`","1","`","environment","with","`","num_episodes",">","=","1","`",".","Args",":","time_step",":","optional","initial","time_step",".","If","None",",","it","will","be","obtained","by","resetting","the","environment",".","Elements","should","be","shape","[","batch_size",",","...","]",".","policy_state",":","optional","initial","state","for","the","policy",".","If","None",",","it","will","be","obtained","from","the","policy.get_initial_state","(",")",".","num_episodes",":","Optional","number","of","episodes","to","take","in","the","environment",".","If","None","it","would","use","initial","num_episodes",".","maximum_iterations",":","Optional","maximum","number","of","iterations","of","the","while","loop","to","run",".","If","provided",",","the","cond","output","is","AND-ed","with","an","additional","condition","ensuring","the","number","of","iterations","executed","is","no","greater","than","maximum_iterations",".","Returns",":","time_step",":","TimeStep","named","tuple","with","final","observation",",","reward",",","etc",".","policy_state",":","Tensor","with","final","step","policy","state","."]
code: def run(
      self,
      time_step=None,
      policy_state=None,
      num_episodes=None,
      maximum_iterations=None,
  ):
      """Takes episodes in the environment using the policy and update observers.
  
      If `time_step` and `policy_state` are not provided, `run` will reset the
      environment and request an initial state from the policy.
  
      **Note** about bias when using batched environments with `num_episodes`:
      When using `num_episodes != None`, a `run` step "finishes" collecting
      `num_episodes` have been completely collected (hit a boundary).
      When used in conjunction with environments that have variable-length
      episodes, this skews the distribution of collected episodes' lengths:
      short episodes are seen more frequently than long ones.
      As a result, running an `env` of `N > 1` batched environments
      with `num_episodes >= 1` is not the same as running an env with `1`
      environment with `num_episodes >= 1`.
  
      Args:
        time_step: optional initial time_step. If None, it will be obtained by
          resetting the environment. Elements should be shape [batch_size, ...].
        policy_state: optional initial state for the policy. If None, it will be
          obtained from the policy.get_initial_state().
        num_episodes: Optional number of episodes to take in the environment. If
          None it would use initial num_episodes.
        maximum_iterations: Optional maximum number of iterations of the while
          loop to run. If provided, the cond output is AND-ed with an additional
          condition ensuring the number of iterations executed is no greater than
          maximum_iterations.
  
      Returns:
        time_step: TimeStep named tuple with final observation, reward, etc.
        policy_state: Tensor with final step policy state.
      """
      return self._run_fn(
          time_step=time_step,
          policy_state=policy_state,
          num_episodes=num_episodes,
          maximum_iterations=maximum_iterations,
      )
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import gin
  import tensorflow
  from tf_agents.bandits.environments import bandit_py_environment
  from tf_agents.bandits.environments import bandit_tf_environment
  from tf_agents.drivers import driver
  from tf_agents.environments import tf_py_environment
  from tf_agents.trajectories import time_step
  from tf_agents.trajectories import trajectory
  from tf_agents.utils import common
  from tf_agents.utils import nest_utils
label_desc: Use image node_id 4 for calling the DynamicEpisodeDriver obj's underlying member method code with example usage: obj.run(time_step, policy_state, num_episodes, maximum_iterations) and returns: self