class_docstr: This class implements a trainer for TensorFlow algorithms.
  
  A trainer provides a default TensorFlow session using python context.
  This is useful for those experiment components (e.g. policy) that require a
  TensorFlow session during construction.
  
  Use trainer.setup(algo, env) to setup algorithm and environment for trainer
  and trainer.train() to start training.
  
  Args:
      snapshot_config (garage.experiment.SnapshotConfig): The snapshot
          configuration used by Trainer to create the snapshotter.
          If None, it will create one with default settings.
      sess (tf.Session): An optional TensorFlow session.
            A new session will be created immediately if not provided.
  
  Note:
      When resume via command line, new snapshots will be
      saved into the SAME directory if not specified.
  
      When resume programmatically, snapshot directory should be
      specify manually or through @wrap_experiment interface.
  
  Examples:
      # to train
      with TFTrainer() as trainer:
          env = gym.make('CartPole-v1')
          policy = CategoricalMLPPolicy(
              env_spec=env.spec,
              hidden_sizes=(32, 32))
          algo = TRPO(
              env=env,
              policy=policy,
              baseline=baseline,
              max_episode_length=100,
              discount=0.99,
              max_kl_step=0.01)
          trainer.setup(algo, env)
          trainer.train(n_epochs=100, batch_size=4000)
  
      # to resume immediately.
      with TFTrainer() as trainer:
          trainer.restore(resume_from_dir)
          trainer.resume()
  
      # to resume with modified training arguments.
      with TFTrainer() as trainer:
          trainer.restore(resume_from_dir)
          trainer.resume(n_epochs=20)
docstr: Set up trainer and sessions for algorithm and environment.
  
  This method saves algo and env within trainer and creates a sampler,
  and initializes all uninitialized variables in session.
  
  Note:
      After setup() is called all variables in session should have been
      initialized. setup() respects existing values in session so
      policy weights can be loaded before setup().
  
  Args:
      algo (RLAlgorithm): An algorithm instance.
      env (Environment): An environment instance.
docstr_tok: ["Set","up","trainer","and","sessions","for","algorithm","and","environment",".","This","method","saves","algo","and","env","within","trainer","and","creates","a","sampler",",","and","initializes","all","uninitialized","variables","in","session",".","Note",":","After","setup","(",")","is","called","all","variables","in","session","should","have","been","initialized",".","setup","(",")","respects","existing","values","in","session","so","policy","weights","can","be","loaded","before","setup","(",")",".","Args",":","algo","(","RLAlgorithm",")",":","An","algorithm","instance",".","env","(","Environment",")",":","An","environment","instance","."]
code: def setup(self, algo, env):
      """Set up trainer and sessions for algorithm and environment.
  
      This method saves algo and env within trainer and creates a sampler,
      and initializes all uninitialized variables in session.
  
      Note:
          After setup() is called all variables in session should have been
          initialized. setup() respects existing values in session so
          policy weights can be loaded before setup().
  
      Args:
          algo (RLAlgorithm): An algorithm instance.
          env (Environment): An environment instance.
  
      """
      self.initialize_tf_vars()
      logger.log(self.sess.graph)
      super().setup(algo, env)
  
imports: import copy
  import os
  import time
  import cloudpickle
  from dowel import logger, tabular
  from garage.experiment.deterministic import get_seed, set_seed
  from garage.experiment.experiment import dump_json
  from garage.experiment.snapshotter import Snapshotter
label_desc: Use image node_id 4 for calling the TFTrainer obj's underlying member method code with example usage: obj.setup(algo, env) without return types