You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -139,7 +139,7 @@ for i in range(1000):
139
139
env.close()
140
140
```
141
141
142
-
Or just train a model with a one liner if [the environment is registered in Gym](https://github.com/openai/gym/wiki/Environments) and if [the policy is registered](https://stable-baselines3.readthedocs.io/en/master/guide/custom_policy.html):
142
+
Or just train a model with a one liner if [the environment is registered in Gymnasium](https://gymnasium.farama.org/tutorials/gymnasium_basics/environment_creation/#registering-envs) and if [the policy is registered](https://stable-baselines3.readthedocs.io/en/master/guide/custom_policy.html):
Copy file name to clipboardexpand all lines: docs/guide/custom_env.rst
+15-14
Original file line number
Diff line number
Diff line change
@@ -3,18 +3,19 @@
3
3
Using Custom Environments
4
4
==========================
5
5
6
-
To use the RL baselines with custom environments, they just need to follow the *gym* interface.
7
-
That is to say, your environment must implement the following methods (and inherits from OpenAI Gym Class):
6
+
To use the RL baselines with custom environments, they just need to follow the *gymnasium* `interface<https://gymnasium.farama.org/tutorials/gymnasium_basics/environment_creation/#sphx-glr-tutorials-gymnasium-basics-environment-creation-py>`_.
7
+
That is to say, your environment must implement the following methods (and inherits from Gym Class):
8
8
9
9
10
10
.. note::
11
-
If you are using images as input, the observation must be of type ``np.uint8`` and be contained in [0, 255].
12
-
By default, the observation is normalized by SB3 pre-processing (dividing by 255 to have values in [0, 1]) when using CNN policies.
13
-
Images can be either channel-first or channel-last.
11
+
12
+
If you are using images as input, the observation must be of type ``np.uint8`` and be contained in [0, 255].
13
+
By default, the observation is normalized by SB3 pre-processing (dividing by 255 to have values in [0, 1]) when using CNN policies.
14
+
Images can be either channel-first or channel-last.
14
15
15
16
If you want to use ``CnnPolicy`` or ``MultiInputPolicy`` with image-like observation (3D tensor) that are already normalized, you must pass ``normalize_images=False``
16
-
to the policy (using ``policy_kwargs`` parameter, ``policy_kwargs=dict(normalize_images=False)``)
17
-
and make sure your image is in the **channel-first** format.
17
+
to the policy (using ``policy_kwargs`` parameter, ``policy_kwargs=dict(normalize_images=False)``)
18
+
and make sure your image is in the **channel-first** format.
18
19
19
20
20
21
.. note::
@@ -34,7 +35,7 @@ That is to say, your environment must implement the following methods (and inher
34
35
classCustomEnv(gym.Env):
35
36
"""Custom Environment that follows gym interface."""
@@ -48,11 +49,11 @@ That is to say, your environment must implement the following methods (and inher
48
49
49
50
defstep(self, action):
50
51
...
51
-
return observation, reward, done, info
52
+
return observation, reward, terminated, truncated, info
52
53
53
-
defreset(self):
54
+
defreset(self, seed=None, options=None):
54
55
...
55
-
return observation# reward, done, info can't be included
56
+
return observation, info
56
57
57
58
defrender(self):
58
59
...
@@ -81,11 +82,11 @@ To check that your environment follows the Gym interface that SB3 supports, plea
81
82
# It will check your custom environment and output additional warnings if needed
82
83
check_env(env)
83
84
84
-
Gym also have its own `env checker <https://www.gymlibrary.ml/content/api/#checking-api-conformity>`_ but it checks a superset of what SB3 supports (SB3 does not support all Gym features).
85
+
Gymnasium also have its own `env checker <https://gymnasium.farama.org/api/utils/#gymnasium.utils.env_checker.check_env>`_ but it checks a superset of what SB3 supports (SB3 does not support all Gym features).
85
86
86
-
We have created a `colab notebook <https://colab.research.google.com/github/araffin/rl-tutorial-jnrr19/blob/master/5_custom_gym_env.ipynb>`_ for a concrete example on creating a custom environment along with an example of using it with Stable-Baselines3 interface.
87
+
We have created a `colab notebook <https://colab.research.google.com/github/araffin/rl-tutorial-jnrr19/blob/sb3/5_custom_gym_env.ipynb>`_ for a concrete example on creating a custom environment along with an example of using it with Stable-Baselines3 interface.
87
88
88
-
Alternatively, you may look at OpenAI Gym `built-in environments <https://www.gymlibrary.ml/>`_. However, the readers are cautioned as per OpenAI Gym `official wiki <https://github.com/openai/gym/wiki/FAQ>`_, its advised not to customize their built-in environments. It is better to copy and create new ones if you need to modify them.
89
+
Alternatively, you may look at Gymnasium `built-in environments <https://gymnasium.farama.org>`_.
89
90
90
91
Optionally, you can also register the environment with gym, that will allow you to create the RL agent in one line (and use ``gym.make()`` to instantiate the env):
0 commit comments