class_docstr: Base class of trainer.
  
  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.
  
  Note:
      For the use of any TensorFlow environments, policies and algorithms,
      please use TFTrainer().
  
  Examples:
      | # to train
      | trainer = Trainer()
      | env = Env(...)
      | policy = Policy(...)
      | algo = Algo(
      |         env=env,
      |         policy=policy,
      |         ...)
      | trainer.setup(algo, env)
      | trainer.train(n_epochs=100, batch_size=4000)
  
      | # to resume immediately.
      | trainer = Trainer()
      | trainer.restore(resume_from_dir)
      | trainer.resume()
  
      | # to resume with modified training arguments.
      | trainer = Trainer()
      | trainer.restore(resume_from_dir)
      | trainer.resume(n_epochs=20)
docstr: Obtain one batch of episodes.
  
  Args:
      itr (int): Index of iteration (epoch).
      batch_size (int): Number of steps in batch. This is a hint that the
          sampler may or may not respect.
      agent_update (object): Value which will be passed into the
          `agent_update_fn` before doing sampling episodes. If a list is
          passed in, it must have length exactly `factory.n_workers`, and
          will be spread across the workers.
      env_update (object): Value which will be passed into the
          `env_update_fn` before sampling episodes. If a list is passed
          in, it must have length exactly `factory.n_workers`, and will
          be spread across the workers.
  
  Raises:
      ValueError: If the trainer was initialized without a sampler, or
          batch_size wasn't provided here or to train.
  
  Returns:
      EpisodeBatch: Batch of episodes.
docstr_tok: ["Obtain","one","batch","of","episodes",".","Args",":","itr","(","int",")",":","Index","of","iteration","(","epoch",")",".","batch_size","(","int",")",":","Number","of","steps","in","batch",".","This","is","a","hint","that","the","sampler","may","or","may","not","respect",".","agent_update","(","object",")",":","Value","which","will","be","passed","into","the","`","agent_update_fn","`","before","doing","sampling","episodes",".","If","a","list","is","passed","in",",","it","must","have","length","exactly","`","factory.n_workers","`",",","and","will","be","spread","across","the","workers",".","env_update","(","object",")",":","Value","which","will","be","passed","into","the","`","env_update_fn","`","before","sampling","episodes",".","If","a","list","is","passed","in",",","it","must","have","length","exactly","`","factory.n_workers","`",",","and","will","be","spread","across","the","workers",".","Raises",":","ValueError",":","If","the","trainer","was","initialized","without","a","sampler",",","or","batch_size","was","n't","provided","here","or","to","train",".","Returns",":","EpisodeBatch",":","Batch","of","episodes","."]
code: def obtain_episodes(
      self, itr, batch_size=None, agent_update=None, env_update=None
  ):
      """Obtain one batch of episodes.
  
      Args:
          itr (int): Index of iteration (epoch).
          batch_size (int): Number of steps in batch. This is a hint that the
              sampler may or may not respect.
          agent_update (object): Value which will be passed into the
              `agent_update_fn` before doing sampling episodes. If a list is
              passed in, it must have length exactly `factory.n_workers`, and
              will be spread across the workers.
          env_update (object): Value which will be passed into the
              `env_update_fn` before sampling episodes. If a list is passed
              in, it must have length exactly `factory.n_workers`, and will
              be spread across the workers.
  
      Raises:
          ValueError: If the trainer was initialized without a sampler, or
              batch_size wasn't provided here or to train.
  
      Returns:
          EpisodeBatch: Batch of episodes.
  
      """
      if self._sampler is None:
          raise ValueError(
              "trainer was not initialized with `sampler`. "
              "the algo should have a `_sampler` field when"
              "`setup()` is called"
          )
      if batch_size is None and self._train_args.batch_size is None:
          raise ValueError(
              "trainer was not initialized with `batch_size`. "
              "Either provide `batch_size` to trainer.train, "
              " or pass `batch_size` to trainer.obtain_samples."
          )
      episodes = None
      if agent_update is None:
          policy = getattr(self._algo, "exploration_policy", None)
          if policy is None:
              # This field should exist, since self.make_sampler would have
              # failed otherwise.
              policy = self._algo.policy
          agent_update = policy.get_param_values()
      episodes = self._sampler.obtain_samples(
          itr,
          (batch_size or self._train_args.batch_size),
          agent_update=agent_update,
          env_update=env_update,
      )
      self._stats.total_env_steps += sum(episodes.lengths)
      return episodes
  
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 5 for calling the Trainer obj's underlying member method code with example usage: obj.obtain_episodes(itr, batch_size, agent_update, env_update) and returns: episodes