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 check

  • wrapper_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, 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 (Optional[int]) – the initial seed for the random number generator

  • start_index (int) – start rank index

  • monitor_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 the AtariWrapper

  • env_kwargs (Optional[Dict[str, Any]]) – Optional keyword argument to pass to the env constructor

  • vec_env_cls (Union[DummyVecEnv, SubprocVecEnv, None]) – A custom VecEnv class constructor. Default: None.

  • vec_env_kwargs (Optional[Dict[str, Any]]) – Keyword arguments to pass to the VecEnv class constructor.

  • monitor_kwargs (Optional[Dict[str, Any]]) – Keyword arguments to pass to the Monitor 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, 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 (Union[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 (Optional[int]) – the initial seed for the random number generator

  • start_index (int) – start rank index

  • monitor_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. Note: the wrapper specified by this parameter will be applied after the Monitor wrapper. 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 (Optional[Dict[str, Any]]) – Optional keyword argument to pass to the env constructor

  • vec_env_cls (Optional[Type[Union[DummyVecEnv, SubprocVecEnv]]]) – A custom VecEnv class constructor. Default: None.

  • vec_env_kwargs (Optional[Dict[str, Any]]) – Keyword arguments to pass to the VecEnv class constructor.

  • monitor_kwargs (Optional[Dict[str, Any]]) – Keyword arguments to pass to the Monitor class constructor.

  • wrapper_kwargs (Optional[Dict[str, Any]]) – Keyword arguments to pass to the Wrapper 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 unwrap

  • wrapper_class (Type[Wrapper]) – Wrapper to look for

Return type

Optional[Wrapper]

Returns

Environment unwrapped till wrapper_class if it has been wrapped with it