garage.sampler.on_policy_vectorized_sampler module

BatchSampler which uses VecEnvExecutor to run multiple environments.

class OnPolicyVectorizedSampler(algo, env, n_envs=None)[source]

Bases: garage.sampler.batch_sampler.BatchSampler

BatchSampler which uses VecEnvExecutor to run multiple environments.

Parameters:
  • algo (garage.np.algo.RLAlgorithm) – A garage algo object
  • env (gym.Env) – A gym/akro env object
  • n_envs (int) – Number of parallel environments used for sampling.
obtain_samples(itr, batch_size=None, whole_paths=True)[source]

Sample the policy for new trajectories.

Parameters:
  • itr (int) – Iteration number.
  • batch_size (int) – Number of samples to be collected. If None, it will be default [algo.max_path_length * n_envs].
  • whole_paths (bool) – Whether return all the paths or not. True by default. It’s possible for the paths to have total actual sample size larger than batch_size, and will be truncated if this flag is true.
Returns:

Sample paths, each path with key
  • observations: (numpy.ndarray)
  • actions: (numpy.ndarray)
  • rewards: (numpy.ndarray)
  • agent_infos: (dict)
  • env_infos: (dict)

Return type:

list[dict]

shutdown_worker()[source]

Shutdown workers.

start_worker()[source]

Start workers.