Skip to content

Commit

Permalink
Clarify the use of Gym wrappers with make_vec_env (#2079)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
pstahlhofen and araffin authored Feb 7, 2025
1 parent b8b2d30 commit c5c29a3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
20 changes: 20 additions & 0 deletions docs/guide/vec_envs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <stable_baselines3.common.env_util.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
------

Expand Down
3 changes: 2 additions & 1 deletion docs/misc/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

0 comments on commit c5c29a3

Please sign in to comment.