class_docstr: Sampler that runs workers in the main process.
  
  This is probably the simplest possible sampler. It's called the "Local"
  sampler because it runs everything in the same process and thread as where
  it was called from.
  
  The sampler need to be created either from a worker factory or from
  parameters which can construct a worker factory. See the __init__ method
  of WorkerFactory for the detail of these parameters.
  
  Args:
      agents (Policy or List[Policy]): Agent(s) to use to sample episodes.
          If a list is passed in, it must have length exactly
          `worker_factory.n_workers`, and will be spread across the
          workers.
      envs (Environment or List[Environment]): Environment from which
          episodes are sampled. If a list is passed in, it must have length
          exactly `worker_factory.n_workers`, and will be spread across the
          workers.
      worker_factory (WorkerFactory): Pickleable factory for creating
          workers. Should be transmitted to other processes / nodes where
          work needs to be done, then workers should be constructed
          there. Either this param or params after this are required to
          construct a sampler.
      max_episode_length(int): Params used to construct a worker factory.
          The maximum length episodes which will be sampled.
      is_tf_worker (bool): Whether it is workers for TFTrainer.
      seed(int): The seed to use to initialize random number generators.
      n_workers(int): The number of workers to use.
      worker_class(type): Class of the workers. Instances should implement
          the Worker interface.
      worker_args (dict or None): Additional arguments that should be passed
          to the worker.
class_docstr_tok: ["Sampler","that","runs","workers","in","the","main","process",".","This","is","probably","the","simplest","possible","sampler",".","It","'s","called","the","``","Local","''","sampler","because","it","runs","everything","in","the","same","process","and","thread","as","where","it","was","called","from",".","The","sampler","need","to","be","created","either","from","a","worker","factory","or","from","parameters","which","can","construct","a","worker","factory",".","See","the","__init__","method","of","WorkerFactory","for","the","detail","of","these","parameters",".","Args",":","agents","(","Policy","or","List","[","Policy","]",")",":","Agent","(","s",")","to","use","to","sample","episodes",".","If","a","list","is","passed","in",",","it","must","have","length","exactly","`","worker_factory.n_workers","`",",","and","will","be","spread","across","the","workers",".","envs","(","Environment","or","List","[","Environment","]",")",":","Environment","from","which","episodes","are","sampled",".","If","a","list","is","passed","in",",","it","must","have","length","exactly","`","worker_factory.n_workers","`",",","and","will","be","spread","across","the","workers",".","worker_factory","(","WorkerFactory",")",":","Pickleable","factory","for","creating","workers",".","Should","be","transmitted","to","other","processes","\/","nodes","where","work","needs","to","be","done",",","then","workers","should","be","constructed","there",".","Either","this","param","or","params","after","this","are","required","to","construct","a","sampler",".","max_episode_length","(","int",")",":","Params","used","to","construct","a","worker","factory",".","The","maximum","length","episodes","which","will","be","sampled",".","is_tf_worker","(","bool",")",":","Whether","it","is","workers","for","TFTrainer",".","seed","(","int",")",":","The","seed","to","use","to","initialize","random","number","generators",".","n_workers","(","int",")",":","The","number","of","workers","to","use",".","worker_class","(","type",")",":","Class","of","the","workers",".","Instances","should","implement","the","Worker","interface",".","worker_args","(","dict","or","None",")",":","Additional","arguments","that","should","be","passed","to","the","worker","."]
docstr: Collect at least a given number transitions (timesteps).
  
  Args:
      itr(int): The current iteration number. Using this argument is
          deprecated.
      num_samples (int): Minimum number of transitions / timesteps to
          sample.
      agent_update (object): Value which will be passed into the
          `agent_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.
      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.
  
  Returns:
      EpisodeBatch: The batch of collected episodes.
docstr_tok: ["Collect","at","least","a","given","number","transitions","(","timesteps",")",".","Args",":","itr","(","int",")",":","The","current","iteration","number",".","Using","this","argument","is","deprecated",".","num_samples","(","int",")",":","Minimum","number","of","transitions","\/","timesteps","to","sample",".","agent_update","(","object",")",":","Value","which","will","be","passed","into","the","`","agent_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",".","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",".","Returns",":","EpisodeBatch",":","The","batch","of","collected","episodes","."]
code: def obtain_samples(
      self, itr, num_samples, agent_update, env_update=None
  ):
      """Collect at least a given number transitions (timesteps).
  
      Args:
          itr(int): The current iteration number. Using this argument is
              deprecated.
          num_samples (int): Minimum number of transitions / timesteps to
              sample.
          agent_update (object): Value which will be passed into the
              `agent_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.
          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.
  
      Returns:
          EpisodeBatch: The batch of collected episodes.
  
      """
      self._update_workers(agent_update, env_update)
      batches = []
      completed_samples = 0
      while True:
          for worker in self._workers:
              batch = worker.rollout()
              completed_samples += len(batch.actions)
              batches.append(batch)
              if completed_samples >= num_samples:
                  samples = EpisodeBatch.concatenate(*batches)
                  self.total_env_steps += sum(samples.lengths)
                  return samples
  
file_path: garage/src/garage/sampler/local_sampler.py
imports: import copy
  import psutil
  from garage import EpisodeBatch
  from garage.experiment.deterministic import get_seed
  from garage.sampler.default_worker import DefaultWorker
  from garage.sampler.sampler import Sampler
  from garage.sampler.worker_factory import WorkerFactory
label_desc: Use image node_id 4 for calling the LocalSampler obj's underlying member method code with example usage: obj.obtain_samples(itr, num_samples, agent_update, env_update) and returns: samples