class_docstr: A driver that runs a TF policy in a TF environment.
class_docstr_tok: ["A","driver","that","runs","a","TF","policy","in","a","TF","environment","."]
docstr: A driver that runs a TF policy in a TF environment.
  
  **Note** about bias when using batched environments with `max_episodes`:
  When using `max_episodes != None`, a `run` step "finishes" when
  `max_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 `max_episodes >= 1` is not the same as running an env with `1`
  environment with `max_episodes >= 1`.
  
  Args:
    env: A tf_environment.Base environment.
    policy: A tf_policy.TFPolicy policy.
    observers: A list of observers that are notified after every step in the
      environment. Each observer is a callable(trajectory.Trajectory).
    transition_observers: A list of observers that are updated after every
      step in the environment. Each observer is a callable((TimeStep,
      PolicyStep, NextTimeStep)). The transition is shaped just as
      trajectories are for regular observers.
    max_steps: Optional maximum number of steps for each run() call. For
      batched or parallel environments, this is the maximum total number of
      steps summed across all environments. Also see below.  Default: 0.
    max_episodes: Optional maximum number of episodes for each run() call. For
      batched or parallel environments, this is the maximum total number of
      episodes summed across all environments. At least one of max_steps or
      max_episodes must be provided. If both are set, run() terminates when at
      least one of the conditions is satisfied.  Default: 0.
    disable_tf_function: If True the use of tf.function for the run method is
      disabled.
  
  Raises:
    ValueError: If both max_steps and max_episodes are None.
docstr_tok: ["A","driver","that","runs","a","TF","policy","in","a","TF","environment",".","*","*","Note","*","*","about","bias","when","using","batched","environments","with","`","max_episodes","`",":","When","using","`","max_episodes","!","=","None","`",",","a","`","run","`","step","``","finishes","''","when","`","max_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","`","max_episodes",">","=","1","`","is","not","the","same","as","running","an","env","with","`","1","`","environment","with","`","max_episodes",">","=","1","`",".","Args",":","env",":","A","tf_environment.Base","environment",".","policy",":","A","tf_policy.TFPolicy","policy",".","observers",":","A","list","of","observers","that","are","notified","after","every","step","in","the","environment",".","Each","observer","is","a","callable","(","trajectory.Trajectory",")",".","transition_observers",":","A","list","of","observers","that","are","updated","after","every","step","in","the","environment",".","Each","observer","is","a","callable","(","(","TimeStep",",","PolicyStep",",","NextTimeStep",")",")",".","The","transition","is","shaped","just","as","trajectories","are","for","regular","observers",".","max_steps",":","Optional","maximum","number","of","steps","for","each","run","(",")","call",".","For","batched","or","parallel","environments",",","this","is","the","maximum","total","number","of","steps","summed","across","all","environments",".","Also","see","below",".","Default",":","0.","max_episodes",":","Optional","maximum","number","of","episodes","for","each","run","(",")","call",".","For","batched","or","parallel","environments",",","this","is","the","maximum","total","number","of","episodes","summed","across","all","environments",".","At","least","one","of","max_steps","or","max_episodes","must","be","provided",".","If","both","are","set",",","run","(",")","terminates","when","at","least","one","of","the","conditions","is","satisfied",".","Default",":","0.","disable_tf_function",":","If","True","the","use","of","tf.function","for","the","run","method","is","disabled",".","Raises",":","ValueError",":","If","both","max_steps","and","max_episodes","are","None","."]
code: def __init__(
      self,
      env: tf_environment.TFEnvironment,
      policy: tf_policy.TFPolicy,
      observers: Sequence[Callable[[trajectory.Trajectory], Any]],
      transition_observers: Optional[
          Sequence[Callable[[trajectory.Transition], Any]]
      ] = None,
      max_steps: Optional[types.Int] = None,
      max_episodes: Optional[types.Int] = None,
      disable_tf_function: bool = False,
  ):
      """A driver that runs a TF policy in a TF environment.
  
      **Note** about bias when using batched environments with `max_episodes`:
      When using `max_episodes != None`, a `run` step "finishes" when
      `max_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 `max_episodes >= 1` is not the same as running an env with `1`
      environment with `max_episodes >= 1`.
  
      Args:
        env: A tf_environment.Base environment.
        policy: A tf_policy.TFPolicy policy.
        observers: A list of observers that are notified after every step in the
          environment. Each observer is a callable(trajectory.Trajectory).
        transition_observers: A list of observers that are updated after every
          step in the environment. Each observer is a callable((TimeStep,
          PolicyStep, NextTimeStep)). The transition is shaped just as
          trajectories are for regular observers.
        max_steps: Optional maximum number of steps for each run() call. For
          batched or parallel environments, this is the maximum total number of
          steps summed across all environments. Also see below.  Default: 0.
        max_episodes: Optional maximum number of episodes for each run() call. For
          batched or parallel environments, this is the maximum total number of
          episodes summed across all environments. At least one of max_steps or
          max_episodes must be provided. If both are set, run() terminates when at
          least one of the conditions is satisfied.  Default: 0.
        disable_tf_function: If True the use of tf.function for the run method is
          disabled.
  
      Raises:
        ValueError: If both max_steps and max_episodes are None.
      """
      common.check_tf1_allowed()
      max_steps = max_steps or 0
      max_episodes = max_episodes or 0
      if max_steps < 1 and max_episodes < 1:
          raise ValueError(
              "Either `max_steps` or `max_episodes` should be greater than 0."
          )
  
      super(TFDriver, self).__init__(
          env, policy, observers, transition_observers
      )
  
      self._max_steps = max_steps or np.inf
      self._max_episodes = max_episodes or np.inf
  
      if not disable_tf_function:
          self.run = common.function(self.run, autograph=True)
  
file_path: agents/tf_agents/drivers/tf_driver.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from typing import Any, Callable, Optional, Sequence, Tuple
  import numpy
  import tensorflow
  from tf_agents.drivers import driver
  from tf_agents.environments import tf_environment
  from tf_agents.policies import tf_policy
  from tf_agents.trajectories import time_step
  from tf_agents.trajectories import trajectory
  from tf_agents.typing import types
  from tf_agents.utils import common
label_desc: Use image node_id 1 to create a new TFDriver object from inherited base classes: driver with example: obj = TFDriver(env, policy, observers, transition_observers, max_steps, max_episodes, disable_tf_function)