class_docstr: Manages all the learning details needed when training an agent.
  
  These include:
    * Using distribution strategies correctly
    * Summaries
    * Checkpoints
    * Minimizing entering/exiting TF context:
        Especially in the case of TPUs scheduling a single TPU program to
        perform multiple train steps is critical for performance.
    * Generalizes the train call to be done correctly across CPU, GPU, or TPU
      executions managed by DistributionStrategies. This uses `strategy.run` and
      then makes sure to do a reduce operation over the `LossInfo` returned by
      the agent.
class_docstr_tok: ["Manages","all","the","learning","details","needed","when","training","an","agent",".","These","include",":","*","Using","distribution","strategies","correctly","*","Summaries","*","Checkpoints","*","Minimizing","entering\/exiting","TF","context",":","Especially","in","the","case","of","TPUs","scheduling","a","single","TPU","program","to","perform","multiple","train","steps","is","critical","for","performance",".","*","Generalizes","the","train","call","to","be","done","correctly","across","CPU",",","GPU",",","or","TPU","executions","managed","by","DistributionStrategies",".","This","uses","`","strategy.run","`","and","then","makes","sure","to","do","a","reduce","operation","over","the","`","LossInfo","`","returned","by","the","agent","."]
docstr: Runs `iterations` iterations of training.
  
  Args:
    iterations: Number of train iterations to perform per call to run. The
      iterations will be evaluated in a tf.while loop created by autograph.
      Final aggregated losses will be returned.
    iterator: The iterator to the dataset to use for training. If not
      specified, `self._experience_iterator` is used.
    parallel_iterations: Maximum number of train iterations to allow running
      in parallel. This value is forwarded directly to the training tf.while
      loop.
  
  Returns:
    The total loss computed before running the final step.
docstr_tok: ["Runs","`","iterations","`","iterations","of","training",".","Args",":","iterations",":","Number","of","train","iterations","to","perform","per","call","to","run",".","The","iterations","will","be","evaluated","in","a","tf.while","loop","created","by","autograph",".","Final","aggregated","losses","will","be","returned",".","iterator",":","The","iterator","to","the","dataset","to","use","for","training",".","If","not","specified",",","`","self._experience_iterator","`","is","used",".","parallel_iterations",":","Maximum","number","of","train","iterations","to","allow","running","in","parallel",".","This","value","is","forwarded","directly","to","the","training","tf.while","loop",".","Returns",":","The","total","loss","computed","before","running","the","final","step","."]
code: def run(self, iterations=1, iterator=None, parallel_iterations=10):
      """Runs `iterations` iterations of training.
  
      Args:
        iterations: Number of train iterations to perform per call to run. The
          iterations will be evaluated in a tf.while loop created by autograph.
          Final aggregated losses will be returned.
        iterator: The iterator to the dataset to use for training. If not
          specified, `self._experience_iterator` is used.
        parallel_iterations: Maximum number of train iterations to allow running
          in parallel. This value is forwarded directly to the training tf.while
          loop.
  
      Returns:
        The total loss computed before running the final step.
      """
      assert iterations >= 1, (
          "Iterations must be greater or equal to 1, was %d"
          % iterations
      )
  
      def _summary_record_if():
          if self.summary_interval:
              return tf.math.equal(
                  self.train_step % tf.constant(self.summary_interval),
                  0,
              )
          else:
              return tf.constant(False)
  
      with self.train_summary_writer.as_default(), common.soft_device_placement(), tf.compat.v2.summary.record_if(
          _summary_record_if
      ), self.strategy.scope():
          iterator = iterator or self._experience_iterator
          loss_info = self._train(
              tf.constant(iterations), iterator, parallel_iterations
          )
  
          train_step_val = self.train_step.numpy()
          for trigger in self.triggers:
              trigger(train_step_val)
  
          return loss_info
  
file_path: agents/tf_agents/train/learner.py
imports: import os
  from typing import Any, Optional, Tuple
  from absl import logging
  import gin
  import tensorflow.compat.v2
  from tf_agents.agents import tf_agent
  from tf_agents.specs import tensor_spec
  from tf_agents.train import interval_trigger
  from tf_agents.typing import types
  from tf_agents.utils import common
label_desc: Use image node_id 4 for calling the Learner obj's underlying member method code with example usage: obj.run(iterations, iterator, parallel_iterations) and returns: loss_info, tf, tf