Environments Utils¶
-
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 (
Type
[Env
]) – Environment to checkwrapper_class (
Type
[Wrapper
]) – Wrapper class to look for
- Return type
bool
- Returns
True if environment has been wrapped with
wrapper_class
.
-
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.- Parameters
env_id (
Union
[str
,Type
[Env
]]) – the environment ID or the environment classn_envs (
int
) – the number of environments you wish to have in parallelseed (
Optional
[int
]) – the initial seed for the random number generatorstart_index (
int
) – start rank indexmonitor_dir (
Optional
[str
]) – 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 (
Optional
[Dict
[str
,Any
]]) – Optional keyword argument to pass to theAtariWrapper
env_kwargs (
Optional
[Dict
[str
,Any
]]) – Optional keyword argument to pass to the env constructorvec_env_cls (
Union
[DummyVecEnv
,SubprocVecEnv
,None
]) – A customVecEnv
class constructor. Default: None.vec_env_kwargs (
Optional
[Dict
[str
,Any
]]) – Keyword arguments to pass to theVecEnv
class constructor.monitor_kwargs (
Optional
[Dict
[str
,Any
]]) – Keyword arguments to pass to theMonitor
class constructor.
- Return type
VecEnv
- Returns
The wrapped environment
-
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)[source]¶ Create a wrapped, monitored
VecEnv
. By default it uses aDummyVecEnv
which is usually faster than aSubprocVecEnv
.- Parameters
env_id (
Union
[str
,Type
[Env
]]) – the environment ID or the environment classn_envs (
int
) – the number of environments you wish to have in parallelseed (
Optional
[int
]) – the initial seed for the random number generatorstart_index (
int
) – start rank indexmonitor_dir (
Optional
[str
]) – 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 (
Optional
[Callable
[[Env
],Env
]]) – Additional wrapper to use on the environment. This can also be a function with single argument that wraps the environment in many things.env_kwargs (
Optional
[Dict
[str
,Any
]]) – Optional keyword argument to pass to the env constructorvec_env_cls (
Optional
[Type
[Union
[DummyVecEnv
,SubprocVecEnv
]]]) – A customVecEnv
class constructor. Default: None.vec_env_kwargs (
Optional
[Dict
[str
,Any
]]) – Keyword arguments to pass to theVecEnv
class constructor.monitor_kwargs (
Optional
[Dict
[str
,Any
]]) – Keyword arguments to pass to theMonitor
class constructor.
- Return type
VecEnv
- Returns
The wrapped environment
-
stable_baselines3.common.env_util.
unwrap_wrapper
(env, wrapper_class)[source]¶ Retrieve a
VecEnvWrapper
object by recursively searching.- Parameters
env (
Env
) – Environment to unwrapwrapper_class (
Type
[Wrapper
]) – Wrapper to look for
- Return type
Optional
[Wrapper
]- Returns
Environment unwrapped till
wrapper_class
if it has been wrapped with it