class_docstr: Behavioral Cloning.
  
  Based on Model-Free Imitation Learning with Policy Optimization:
      https://arxiv.org/abs/1605.08478
  
  Args:
      env_spec (EnvSpec): Specification of environment.
      learner (garage.torch.Policy): Policy to train.
      batch_size (int): Size of optimization batch.
      source (Policy or Generator[TimeStepBatch]): Expert to clone. If a
          policy is passed, will set `.policy` to source and use the trainer
          to sample from the policy.
      sampler (garage.sampler.Sampler): Sampler. If source is a policy, a
          sampler is required for sampling.
      policy_optimizer (torch.optim.Optimizer): Optimizer to be used to
          optimize the policy.
      policy_lr (float): Learning rate of the policy optimizer.
      loss (str): Which loss function to use. Must be either 'log_prob' or
          'mse'. If set to 'log_prob' (the default), `learner` must be a
          `garage.torch.StochasticPolicy`.
      minibatches_per_epoch (int): Number of minibatches per epoch.
      name (str): Name to use for logging.
  
  Raises:
      ValueError: If learner` is not a
          `garage.torch.StochasticPolicy` and loss is 'log_prob'.
class_docstr_tok: ["Behavioral","Cloning",".","Based","on","Model-Free","Imitation","Learning","with","Policy","Optimization",":","https",":","\/\/arxiv.org\/abs\/1605.08478","Args",":","env_spec","(","EnvSpec",")",":","Specification","of","environment",".","learner","(","garage.torch.Policy",")",":","Policy","to","train",".","batch_size","(","int",")",":","Size","of","optimization","batch",".","source","(","Policy","or","Generator","[","TimeStepBatch","]",")",":","Expert","to","clone",".","If","a","policy","is","passed",",","will","set","`",".policy","`","to","source","and","use","the","trainer","to","sample","from","the","policy",".","sampler","(","garage.sampler.Sampler",")",":","Sampler",".","If","source","is","a","policy",",","a","sampler","is","required","for","sampling",".","policy_optimizer","(","torch.optim.Optimizer",")",":","Optimizer","to","be","used","to","optimize","the","policy",".","policy_lr","(","float",")",":","Learning","rate","of","the","policy","optimizer",".","loss","(","str",")",":","Which","loss","function","to","use",".","Must","be","either","'log_prob","'","or","'mse","'",".","If","set","to","'log_prob","'","(","the","default",")",",","`","learner","`","must","be","a","`","garage.torch.StochasticPolicy","`",".","minibatches_per_epoch","(","int",")",":","Number","of","minibatches","per","epoch",".","name","(","str",")",":","Name","to","use","for","logging",".","Raises",":","ValueError",":","If","learner","`","is","not","a","`","garage.torch.StochasticPolicy","`","and","loss","is","'log_prob","'","."]
docstr: Obtain samples from self._source.
  
  Args:
      trainer (Trainer): Experiment trainer, which may be used to
          obtain samples.
      epoch (int): The current epoch.
  
  Returns:
      TimeStepBatch: Batch of samples.
docstr_tok: ["Obtain","samples","from","self._source",".","Args",":","trainer","(","Trainer",")",":","Experiment","trainer",",","which","may","be","used","to","obtain","samples",".","epoch","(","int",")",":","The","current","epoch",".","Returns",":","TimeStepBatch",":","Batch","of","samples","."]
code: def _obtain_samples(self, trainer, epoch):
      """Obtain samples from self._source.
  
      Args:
          trainer (Trainer): Experiment trainer, which may be used to
              obtain samples.
          epoch (int): The current epoch.
  
      Returns:
          TimeStepBatch: Batch of samples.
  
      """
      if isinstance(self._source, Policy):
          batch = trainer.obtain_episodes(epoch)
          log_performance(epoch, batch, 1.0, prefix="Expert")
          return batch
      else:
          batches = []
          while (
              sum(len(batch.actions) for batch in batches)
              < self._batch_size
          ):
              batches.append(next(self._source))
          return TimeStepBatch.concatenate(*batches)
  
file_path: garage/src/garage/torch/algos/bc.py
imports: import itertools
  from dowel import tabular
  import numpy
  import torch
  from garage import _Default, log_performance, make_optimizer, obtain_evaluation_episodes, TimeStepBatch
  from garage.np.algos.rl_algorithm import RLAlgorithm
  from garage.np.policies import Policy
  from garage.sampler import Sampler
  from garage.torch import np_to_torch
label_desc: Use image node_id 4 for calling the BC obj's underlying member method code with example usage: obj._obtain_samples(trainer, epoch) and returns: batch, TimeStepBatch