Skip to content

Commit 4d15c99

Browse files
authored
Remove reward_range (#1167)
1 parent b40a899 commit 4d15c99

File tree

3 files changed

+4
-11
lines changed

3 files changed

+4
-11
lines changed

docs/tutorials/gymnasium_basics/implementing_custom_wrappers.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def action(self, act):
8282
# ------------------------------------------------
8383
# Reward wrappers are used to transform the reward that is returned by an environment.
8484
# As for the previous wrappers, you need to specify that transformation by implementing the
85-
# :meth:`gymnasium.RewardWrapper.reward` method. Also, you might want to update the reward range of the wrapper.
85+
# :meth:`gymnasium.RewardWrapper.reward` method.
8686
#
8787
# Let us look at an example: Sometimes (especially when we do not have control over the reward
8888
# because it is intrinsic), we want to clip the reward to a range to gain some numerical stability.
@@ -96,7 +96,6 @@ def __init__(self, env, min_reward, max_reward):
9696
super().__init__(env)
9797
self.min_reward = min_reward
9898
self.max_reward = max_reward
99-
self.reward_range = (min_reward, max_reward)
10099

101100
def reward(self, r: SupportsFloat) -> SupportsFloat:
102101
return np.clip(r, self.min_reward, self.max_reward)
@@ -110,7 +109,7 @@ def reward(self, r: SupportsFloat) -> SupportsFloat:
110109
# Such wrappers can be implemented by inheriting from :class:`gymnasium.Wrapper`.
111110
#
112111
# - You can set a new action or observation space by defining ``self.action_space`` or ``self.observation_space`` in ``__init__``, respectively
113-
# - You can set new metadata and reward range by defining ``self.metadata`` and ``self.reward_range`` in ``__init__``, respectively
112+
# - You can set new metadata by defining ``self.metadata`` in ``__init__``
114113
# - You can override :meth:`gymnasium.Wrapper.step`, :meth:`gymnasium.Wrapper.render`, :meth:`gymnasium.Wrapper.close` etc.
115114
#
116115
# If you do this, you can access the environment that was passed

gymnasium/core.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,8 @@ class Wrapper(
289289
"""Wraps a :class:`gymnasium.Env` to allow a modular transformation of the :meth:`step` and :meth:`reset` methods.
290290
291291
This class is the base class of all wrappers to change the behavior of the underlying environment.
292-
Wrappers that inherit from this class can modify the :attr:`action_space`, :attr:`observation_space`,
293-
:attr:`reward_range` and :attr:`metadata` attributes, without changing the underlying environment's attributes.
292+
Wrappers that inherit from this class can modify the :attr:`action_space`, :attr:`observation_space`
293+
and :attr:`metadata` attributes, without changing the underlying environment's attributes.
294294
Moreover, the behavior of the :meth:`step` and :meth:`reset` methods can be changed by these wrappers.
295295
296296
Some attributes (:attr:`spec`, :attr:`render_mode`, :attr:`np_random`) will point back to the wrapper's environment
@@ -568,8 +568,6 @@ class RewardWrapper(Wrapper[ObsType, ActType, ObsType, ActType]):
568568
If you would like to apply a function to the reward that is returned by the base environment before
569569
passing it to learning code, you can simply inherit from :class:`RewardWrapper` and overwrite the method
570570
:meth:`reward` to implement that transformation.
571-
This transformation might change the :attr:`reward_range`; to specify the :attr:`reward_range` of your wrapper,
572-
you can simply define :attr:`self.reward_range` in :meth:`__init__`.
573571
"""
574572

575573
def __init__(self, env: Env[ObsType, ActType]):

gymnasium/envs/functional_jax_env.py

-4
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ def __init__(
2626
func_env: FuncEnv,
2727
metadata: dict[str, Any] | None = None,
2828
render_mode: str | None = None,
29-
reward_range: tuple[float, float] = (-float("inf"), float("inf")),
3029
spec: EnvSpec | None = None,
3130
):
3231
"""Initialize the environment from a FuncEnv."""
@@ -41,7 +40,6 @@ def __init__(
4140

4241
self.metadata = metadata
4342
self.render_mode = render_mode
44-
self.reward_range = reward_range
4543

4644
self.spec = spec
4745

@@ -112,7 +110,6 @@ def __init__(
112110
max_episode_steps: int = 0,
113111
metadata: dict[str, Any] | None = None,
114112
render_mode: str | None = None,
115-
reward_range: tuple[float, float] = (-float("inf"), float("inf")),
116113
spec: EnvSpec | None = None,
117114
):
118115
"""Initialize the environment from a FuncEnv."""
@@ -131,7 +128,6 @@ def __init__(
131128

132129
self.metadata = metadata
133130
self.render_mode = render_mode
134-
self.reward_range = reward_range
135131
self.spec = spec
136132
self.time_limit = max_episode_steps
137133

0 commit comments

Comments
 (0)