From c5c29a32d961be692e08ff49c94d2485ac40cb8a Mon Sep 17 00:00:00 2001 From: Paul Stahlhofen <42074847+pstahlhofen@users.noreply.github.com> Date: Fri, 7 Feb 2025 12:04:48 +0100 Subject: [PATCH] Clarify the use of Gym wrappers with `make_vec_env` (#2079) * Added a note to the documentation of Vectorized Environments to show the possibility of wrapping sub-environments with `make_vec_env` (See #2075 ) * Add example --------- Co-authored-by: Antonin RAFFIN --- docs/guide/vec_envs.rst | 20 ++++++++++++++++++++ docs/misc/changelog.rst | 3 ++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/docs/guide/vec_envs.rst b/docs/guide/vec_envs.rst index c04001c7c..3fbaf9ee3 100644 --- a/docs/guide/vec_envs.rst +++ b/docs/guide/vec_envs.rst @@ -225,6 +225,26 @@ You can find below an example for extracting one key from the observation: env = VecExtractDictObs(env, key="observation") +.. note:: + When creating a vectorized environment, you can also specify ordinary gymnasium + wrappers to wrap each of the sub-environments. See the + :func:`make_vec_env ` + documentation for details. + Example: + + .. code-block:: python + + from gymnasium.wrappers import RescaleAction + from stable_baselines3.common.env_util import make_vec_env + + # Use gym wrapper for each sub-env of the VecEnv + wrapper_kwargs = dict(min_action=-1.0, max_action=1.0) + vec_env = make_vec_env( + "Pendulum-v1", n_envs=2, wrapper_class=RescaleAction, wrapper_kwargs=wrapper_kwargs + ) + + + VecEnv ------ diff --git a/docs/misc/changelog.rst b/docs/misc/changelog.rst index c7967a1e1..0a7b21db5 100644 --- a/docs/misc/changelog.rst +++ b/docs/misc/changelog.rst @@ -36,6 +36,7 @@ Others: Documentation: ^^^^^^^^^^^^^^ +- Clarify the use of Gym wrappers with ``make_vec_env`` in the section on Vectorized Environments (@pstahlhofen) Release 2.5.0 (2025-01-27) @@ -1782,4 +1783,4 @@ And all the contributors: @DavyMorgan @luizapozzobon @Bonifatius94 @theSquaredError @harveybellini @DavyMorgan @FieteO @jonasreiher @npit @WeberSamuel @troiganto @lutogniew @lbergmann1 @lukashass @BertrandDecoster @pseudo-rnd-thoughts @stefanbschneider @kyle-he @PatrickHelm @corentinlger @marekm4 @stagoverflow @rushitnshah @markscsmith @NickLucche @cschindlbeck @peteole @jak3122 @will-maclean -@brn-dev @jmacglashan @kplers @MarcDcls @chrisgao99 +@brn-dev @jmacglashan @kplers @MarcDcls @chrisgao99 @pstahlhofen