class_docstr: Actor.
  
  The actor manages interactions between a policy and an environment. Users
  should configure the metrics and summaries for a specific task like evaluation
  or data collection.
  
  The main point of access for users is  the `run` method. This will iterate
  over either n `steps_per_run` or `episodes_per_run`. At least one of
  `steps_per_run` or `episodes_per_run` must be provided.
class_docstr_tok: ["Actor",".","The","actor","manages","interactions","between","a","policy","and","an","environment",".","Users","should","configure","the","metrics","and","summaries","for","a","specific","task","like","evaluation","or","data","collection",".","The","main","point","of","access","for","users","is","the","`","run","`","method",".","This","will","iterate","over","either","n","`","steps_per_run","`","or","`","episodes_per_run","`",".","At","least","one","of","`","steps_per_run","`","or","`","episodes_per_run","`","must","be","provided","."]
docstr: Initializes an Actor.
  
  Args:
    env: An instance of either a tf or py environment. Note the policy, and
      observers should match the tf/pyness of the env.
    policy: An instance of a policy used to interact with the environment.
    train_step: A scalar tf.int64 `tf.Variable` which will keep track of the
      number of train steps. This is used for artifacts created like
      summaries.
    steps_per_run: Number of steps to evaluated per run call. See below.
    episodes_per_run: Number of episodes evaluated per run call.
    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.
    info_observers: A list of observers that are notified after every step in
      the environment. Each observer is a callable(info).
    metrics: A list of metric observers that output a scaler.
    reference_metrics: Optional list of metrics for which other metrics are
      plotted against. As an example passing in a metric that tracks number of
      environment episodes will result in having summaries of all other
      metrics over this value. Note summaries against the train_step are done
      by default. If you want reference_metrics to be updated make sure they
      are also added to the metrics list.
    image_metrics: A list of metric observers that output an image.
    summary_dir: Path used for summaries. If no path is provided no summaries
      are written.
    summary_interval: How often summaries are written.
    end_episode_on_boundary: This parameter should be False when using
      transition observers and be True when using trajectory observers. It is
      used in py_driver.
    name: Name for the actor used as a prefix to generated summaries.
docstr_tok: ["Initializes","an","Actor",".","Args",":","env",":","An","instance","of","either","a","tf","or","py","environment",".","Note","the","policy",",","and","observers","should","match","the","tf\/pyness","of","the","env",".","policy",":","An","instance","of","a","policy","used","to","interact","with","the","environment",".","train_step",":","A","scalar","tf.int64","`","tf.Variable","`","which","will","keep","track","of","the","number","of","train","steps",".","This","is","used","for","artifacts","created","like","summaries",".","steps_per_run",":","Number","of","steps","to","evaluated","per","run","call",".","See","below",".","episodes_per_run",":","Number","of","episodes","evaluated","per","run","call",".","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",".","info_observers",":","A","list","of","observers","that","are","notified","after","every","step","in","the","environment",".","Each","observer","is","a","callable","(","info",")",".","metrics",":","A","list","of","metric","observers","that","output","a","scaler",".","reference_metrics",":","Optional","list","of","metrics","for","which","other","metrics","are","plotted","against",".","As","an","example","passing","in","a","metric","that","tracks","number","of","environment","episodes","will","result","in","having","summaries","of","all","other","metrics","over","this","value",".","Note","summaries","against","the","train_step","are","done","by","default",".","If","you","want","reference_metrics","to","be","updated","make","sure","they","are","also","added","to","the","metrics","list",".","image_metrics",":","A","list","of","metric","observers","that","output","an","image",".","summary_dir",":","Path","used","for","summaries",".","If","no","path","is","provided","no","summaries","are","written",".","summary_interval",":","How","often","summaries","are","written",".","end_episode_on_boundary",":","This","parameter","should","be","False","when","using","transition","observers","and","be","True","when","using","trajectory","observers",".","It","is","used","in","py_driver",".","name",":","Name","for","the","actor","used","as","a","prefix","to","generated","summaries","."]
code: def __init__(
      self,
      env,
      policy,
      train_step,
      steps_per_run=None,
      episodes_per_run=None,
      observers=None,
      transition_observers=None,
      info_observers=None,
      metrics=None,
      reference_metrics=None,
      image_metrics=None,
      summary_dir=None,
      summary_interval=1000,
      end_episode_on_boundary=True,
      name="",
  ):
      """Initializes an Actor.
  
      Args:
        env: An instance of either a tf or py environment. Note the policy, and
          observers should match the tf/pyness of the env.
        policy: An instance of a policy used to interact with the environment.
        train_step: A scalar tf.int64 `tf.Variable` which will keep track of the
          number of train steps. This is used for artifacts created like
          summaries.
        steps_per_run: Number of steps to evaluated per run call. See below.
        episodes_per_run: Number of episodes evaluated per run call.
        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.
        info_observers: A list of observers that are notified after every step in
          the environment. Each observer is a callable(info).
        metrics: A list of metric observers that output a scaler.
        reference_metrics: Optional list of metrics for which other metrics are
          plotted against. As an example passing in a metric that tracks number of
          environment episodes will result in having summaries of all other
          metrics over this value. Note summaries against the train_step are done
          by default. If you want reference_metrics to be updated make sure they
          are also added to the metrics list.
        image_metrics: A list of metric observers that output an image.
        summary_dir: Path used for summaries. If no path is provided no summaries
          are written.
        summary_interval: How often summaries are written.
        end_episode_on_boundary: This parameter should be False when using
          transition observers and be True when using trajectory observers. It is
          used in py_driver.
        name: Name for the actor used as a prefix to generated summaries.
      """
      self._env = env
      self._policy = policy
      self._train_step = train_step
      self._observers = observers or []
      # Create a copy of the list to avoid modifying the user provided list.
      self._observers = list(self._observers)
      self._metrics = metrics or []
      self._image_metrics = image_metrics or []
      self._observers.extend(self._metrics + self._image_metrics)
      self._reference_metrics = reference_metrics or []
      # Make sure metrics are not repeated.
      self._observers = list(set(self._observers))
      self._transition_observers = list(transition_observers or [])
      self._info_observers = list(info_observers or [])
  
      self._write_summaries = bool(
          summary_dir
      )  # summary_dir is not None
  
      if self._write_summaries:
          self._summary_writer = tf.summary.create_file_writer(
              summary_dir, flush_millis=10000
          )
      else:
          self._summary_writer = tf.summary.create_noop_writer()
  
      self._summary_interval = summary_interval
      # In order to write summaries at `train_step=0` as well.
      self._last_summary = -summary_interval
  
      self._name = name
  
      if isinstance(env, py_environment.PyEnvironment):
          self._driver = py_driver.PyDriver(
              env,
              policy,
              self._observers,
              transition_observers=self._transition_observers,
              info_observers=self._info_observers,
              max_steps=steps_per_run,
              max_episodes=episodes_per_run,
              end_episode_on_boundary=end_episode_on_boundary,
          )
      elif isinstance(env, tf_environment.TFEnvironment):
          raise ValueError("Actor doesn't support TFEnvironments yet.")
      else:
          raise ValueError("Unknown environment type.")
  
      self.reset()
  
imports: import os
  from absl import logging
  import gin
  import tensorflow.compat.v2
  from tf_agents.drivers import py_driver
  from tf_agents.environments import py_environment
  from tf_agents.environments import tf_environment
  from tf_agents.metrics import py_metrics
  from tf_agents.utils import common
label_desc: Use image node_id 1 to create a new Actor object from inherited base classes: object with example: obj = Actor(env, policy, train_step, steps_per_run, episodes_per_run, observers, transition_observers, info_observers, metrics, reference_metrics, image_metrics, summary_dir, summary_interval, end_episode_on_boundary, name)