Environments Utils — Stable Baselines3 2.8.0a1 documentation (original) (raw)
stable_baselines3.common.env_util.is_wrapped(env, wrapper_class)[source]
Check if a given environment has been wrapped with a given wrapper.
Parameters:
- env (Env) – Environment to check
- wrapper_class (type [ Wrapper ]) – Wrapper class to look for
Returns:
True if environment has been wrapped with wrapper_class.
Return type:
bool
stable_baselines3.common.env_util.make_atari_env(env_id, n_envs=1, seed=None, start_index=0, monitor_dir=None, wrapper_kwargs=None, env_kwargs=None, vec_env_cls=None, vec_env_kwargs=None, monitor_kwargs=None)[source]
Create a wrapped, monitored VecEnv for Atari. It is a wrapper around make_vec_env that includes common preprocessing for Atari games.
Note
By default, the AtariWrapper uses terminal_on_life_loss=True, which causesenv.reset() to perform a no-op step instead of truly resetting when the environment terminates due to a loss of life (but not game over). To ensure reset() always resets the env, pass wrapper_kwargs=dict(terminal_on_life_loss=False).
Parameters:
- env_id (str | Callable [ [ ... ] , Env ]) – either the env ID, the env class or a callable returning an env
- n_envs (int) – the number of environments you wish to have in parallel
- seed (int | None) – the initial seed for the random number generator
- start_index (int) – start rank index
- monitor_dir (str | None) – Path to a folder where the monitor files will be saved. If None, no file will be written, however, the env will still be wrapped in a Monitor wrapper to provide additional information about training.
- wrapper_kwargs (dict [ str , Any ] | None) – Optional keyword argument to pass to the
AtariWrapper - env_kwargs (dict [ str , Any ] | None) – Optional keyword argument to pass to the env constructor
- vec_env_cls (type _[_DummyVecEnv] | type _[_SubprocVecEnv] | None) – A custom
VecEnvclass constructor. Default: None. - vec_env_kwargs (dict [ str , Any ] | None) – Keyword arguments to pass to the
VecEnvclass constructor. - monitor_kwargs (dict [ str , Any ] | None) – Keyword arguments to pass to the
Monitorclass constructor.
Returns:
The wrapped environment
Return type:
stable_baselines3.common.env_util.make_vec_env(env_id, n_envs=1, seed=None, start_index=0, monitor_dir=None, wrapper_class=None, env_kwargs=None, vec_env_cls=None, vec_env_kwargs=None, monitor_kwargs=None, wrapper_kwargs=None)[source]
Create a wrapped, monitored VecEnv. By default it uses a DummyVecEnv which is usually faster than a SubprocVecEnv.
Parameters:
- env_id (str | Callable [ [ ... ] , Env ]) – either the env ID, the env class or a callable returning an env
- n_envs (int) – the number of environments you wish to have in parallel
- seed (int | None) – the initial seed for the random number generator
- start_index (int) – start rank index
- monitor_dir (str | None) – Path to a folder where the monitor files will be saved. If None, no file will be written, however, the env will still be wrapped in a Monitor wrapper to provide additional information about training.
- wrapper_class (Callable [ [ Env ] , Env ] | None) – Additional wrapper to use on the environment. This can also be a function with single argument that wraps the environment in many things. Note: the wrapper specified by this parameter will be applied after the
Monitorwrapper. if some cases (e.g. with TimeLimit wrapper) this can lead to undesired behavior. See here for more details: https://github.com/DLR-RM/stable-baselines3/issues/894 - env_kwargs (dict [ str , Any ] | None) – Optional keyword argument to pass to the env constructor
- vec_env_cls (type _[_DummyVecEnv | SubprocVecEnv] | None) – A custom
VecEnvclass constructor. Default: None. - vec_env_kwargs (dict [ str , Any ] | None) – Keyword arguments to pass to the
VecEnvclass constructor. - monitor_kwargs (dict [ str , Any ] | None) – Keyword arguments to pass to the
Monitorclass constructor. - wrapper_kwargs (dict [ str , Any ] | None) – Keyword arguments to pass to the
Wrapperclass constructor.
Returns:
The wrapped environment
Return type:
stable_baselines3.common.env_util.unwrap_wrapper(env, wrapper_class)[source]
Retrieve a VecEnvWrapper object by recursively searching.
Parameters:
- env (Env) – Environment to unwrap
- wrapper_class (type [ Wrapper ]) – Wrapper to look for
Returns:
Environment unwrapped till wrapper_class if it has been wrapped with it
Return type:
Wrapper | None