garage.sampler.vec_worker module¶
Worker that “vectorizes” environments.
-
class
VecWorker
(*, seed, max_path_length, worker_number, n_envs=8)[source]¶ Bases:
garage.sampler.default_worker.DefaultWorker
Worker with a single policy and multiple environemnts.
Alternates between taking a single step in all environments and asking the policy for an action for every environment. This allows computing a batch of actions, which is generally much more efficient than computing a single action when using neural networks.
Parameters: - seed (int) – The seed to use to intialize random number generators.
- max_path_length (int or float) – The maximum length paths which will be sampled. Can be (floating point) infinity.
- worker_number (int) – The number of the worker this update is occurring in. This argument is used to set a different seed for each worker.
- n_envs (int) – Number of environment copies to use.
-
DEFAULT_N_ENVS
= 8¶
-
collect_rollout
()[source]¶ Collect all completed rollouts.
Returns: - A batch of the trajectories completed since
- the last call to collect_rollout().
Return type: garage.TrajectoryBatch
-
step_rollout
()[source]¶ Take a single time-step in the current rollout.
Returns: True iff at least one of the paths was completed. Return type: bool
-
update_agent
(agent_update)[source]¶ Update an agent, assuming it implements garage.Policy.
Parameters: agent_update (np.ndarray or dict or garage.Policy) – If a tuple, dict, or np.ndarray, these should be parameters to agent, which should have been generated by calling policy.get_param_values. Alternatively, a policy itself. Note that other implementations of Worker may take different types for this parameter.
-
update_env
(env_update)[source]¶ Use any non-None env_update as a new environment.
A simple env update function. If env_update is not None, it should be the complete new environment.
This allows changing environments by passing the new environment as env_update into obtain_samples.
Parameters: env_update (gym.Env or EnvUpdate or None) – The environment to replace the existing env with. Note that other implementations of Worker may take different types for this parameter.
Raises: TypeError
– If env_update is not one of the documented types.ValueError
– If the wrong number of updates is passed.