Skip to content

Commit c9e2957

Browse files
authored
Change end-of-episode in CarRacing to termination as opposed to truncation (#813)
1 parent 1a92702 commit c9e2957

12 files changed

+32
-30
lines changed

Diff for: docs/introduction/basic_usage.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ In order to wrap an environment, you must first initialize a base environment. T
127127
```python
128128
>>> import gymnasium as gym
129129
>>> from gymnasium.wrappers import FlattenObservation
130-
>>> env = gym.make("CarRacing-v2")
130+
>>> env = gym.make("CarRacing-v3")
131131
>>> env.observation_space.shape
132132
(96, 96, 3)
133133
>>> wrapped_env = FlattenObservation(env)
@@ -156,7 +156,7 @@ If you have a wrapped environment, and you want to get the unwrapped environment
156156

157157
```python
158158
>>> wrapped_env
159-
<FlattenObservation<TimeLimit<OrderEnforcing<PassiveEnvChecker<CarRacing<CarRacing-v2>>>>>>
159+
<FlattenObservation<TimeLimit<OrderEnforcing<PassiveEnvChecker<CarRacing<CarRacing-v3>>>>>>
160160
>>> wrapped_env.unwrapped
161161
<gymnasium.envs.box2d.car_racing.CarRacing object at 0x7f04efcb8850>
162162
```

Diff for: gymnasium/envs/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@
115115
)
116116

117117
register(
118-
id="CarRacing-v2",
118+
id="CarRacing-v3",
119119
entry_point="gymnasium.envs.box2d.car_racing:CarRacing",
120120
max_episode_steps=1000,
121121
reward_threshold=900,

Diff for: gymnasium/envs/box2d/car_racing.py

+10-8
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,9 @@ class CarRacing(gym.Env, EzPickle):
153153
154154
```python
155155
>>> import gymnasium as gym
156-
>>> env = gym.make("CarRacing-v2", render_mode="rgb_array", lap_complete_percent=0.95, domain_randomize=False, continuous=False)
156+
>>> env = gym.make("CarRacing-v3", render_mode="rgb_array", lap_complete_percent=0.95, domain_randomize=False, continuous=False)
157157
>>> env
158-
<TimeLimit<OrderEnforcing<PassiveEnvChecker<CarRacing<CarRacing-v2>>>>>
158+
<TimeLimit<OrderEnforcing<PassiveEnvChecker<CarRacing<CarRacing-v3>>>>>
159159
160160
```
161161
@@ -176,7 +176,7 @@ class CarRacing(gym.Env, EzPickle):
176176
177177
```python
178178
>>> import gymnasium as gym
179-
>>> env = gym.make("CarRacing-v2", domain_randomize=True)
179+
>>> env = gym.make("CarRacing-v3", domain_randomize=True)
180180
181181
# normal reset, this changes the colour scheme by default
182182
>>> obs, _ = env.reset()
@@ -190,6 +190,7 @@ class CarRacing(gym.Env, EzPickle):
190190
```
191191
192192
## Version History
193+
- v2: Change truncation to termination when finishing the lap (1.0.0)
193194
- v1: Change track completion logic and add domain randomization (0.24.0)
194195
- v0: Original version
195196
@@ -564,6 +565,7 @@ def step(self, action: Union[np.ndarray, int]):
564565
step_reward = 0
565566
terminated = False
566567
truncated = False
568+
info = {}
567569
if action is not None: # First step without action, called from reset()
568570
self.reward -= 0.1
569571
# We actually don't want to count fuel spent, we want car to be faster.
@@ -572,18 +574,18 @@ def step(self, action: Union[np.ndarray, int]):
572574
step_reward = self.reward - self.prev_reward
573575
self.prev_reward = self.reward
574576
if self.tile_visited_count == len(self.track) or self.new_lap:
575-
# Truncation due to finishing lap
576-
# This should not be treated as a failure
577-
# but like a timeout
578-
truncated = True
577+
# Termination due to finishing lap
578+
terminated = True
579+
info["lap_finished"] = True
579580
x, y = self.car.hull.position
580581
if abs(x) > PLAYFIELD or abs(y) > PLAYFIELD:
581582
terminated = True
583+
info["lap_finished"] = False
582584
step_reward = -100
583585

584586
if self.render_mode == "human":
585587
self.render()
586-
return self.state, step_reward, terminated, truncated, {}
588+
return self.state, step_reward, terminated, truncated, info
587589

588590
def render(self):
589591
if self.render_mode is None:

Diff for: gymnasium/utils/play.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ def play(
212212
>>> import gymnasium as gym
213213
>>> import numpy as np
214214
>>> from gymnasium.utils.play import play
215-
>>> play(gym.make("CarRacing-v2", render_mode="rgb_array"), # doctest: +SKIP
215+
>>> play(gym.make("CarRacing-v3", render_mode="rgb_array"), # doctest: +SKIP
216216
... keys_to_action={
217217
... "w": np.array([0, 0.7, 0], dtype=np.float32),
218218
... "a": np.array([-1, 0, 0], dtype=np.float32),

Diff for: gymnasium/wrappers/stateful_observation.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ class FrameStackObservation(
309309
Example:
310310
>>> import gymnasium as gym
311311
>>> from gymnasium.wrappers import FrameStackObservation
312-
>>> env = gym.make("CarRacing-v2")
312+
>>> env = gym.make("CarRacing-v3")
313313
>>> env = FrameStackObservation(env, stack_size=4)
314314
>>> env.observation_space
315315
Box(0, 255, (4, 96, 96, 3), uint8)

Diff for: gymnasium/wrappers/transform_observation.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ class FlattenObservation(
225225
Example:
226226
>>> import gymnasium as gym
227227
>>> from gymnasium.wrappers import FlattenObservation
228-
>>> env = gym.make("CarRacing-v2")
228+
>>> env = gym.make("CarRacing-v3")
229229
>>> env.observation_space.shape
230230
(96, 96, 3)
231231
>>> env = FlattenObservation(env)
@@ -267,7 +267,7 @@ class GrayscaleObservation(
267267
Example:
268268
>>> import gymnasium as gym
269269
>>> from gymnasium.wrappers import GrayscaleObservation
270-
>>> env = gym.make("CarRacing-v2")
270+
>>> env = gym.make("CarRacing-v3")
271271
>>> env.observation_space.shape
272272
(96, 96, 3)
273273
>>> grayscale_env = GrayscaleObservation(env)
@@ -345,7 +345,7 @@ class ResizeObservation(
345345
Example:
346346
>>> import gymnasium as gym
347347
>>> from gymnasium.wrappers import ResizeObservation
348-
>>> env = gym.make("CarRacing-v2")
348+
>>> env = gym.make("CarRacing-v3")
349349
>>> env.observation_space.shape
350350
(96, 96, 3)
351351
>>> resized_env = ResizeObservation(env, (32, 32))
@@ -416,7 +416,7 @@ class ReshapeObservation(
416416
Example:
417417
>>> import gymnasium as gym
418418
>>> from gymnasium.wrappers import ReshapeObservation
419-
>>> env = gym.make("CarRacing-v2")
419+
>>> env = gym.make("CarRacing-v3")
420420
>>> env.observation_space.shape
421421
(96, 96, 3)
422422
>>> reshape_env = ReshapeObservation(env, (24, 4, 96, 1, 3))

Diff for: gymnasium/wrappers/vector/vectorize_observation.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ class FlattenObservation(VectorizeTransformObservation):
213213
214214
Example:
215215
>>> import gymnasium as gym
216-
>>> envs = gym.make_vec("CarRacing-v2", num_envs=3, vectorization_mode="sync")
216+
>>> envs = gym.make_vec("CarRacing-v3", num_envs=3, vectorization_mode="sync")
217217
>>> obs, info = envs.reset(seed=123)
218218
>>> obs.shape
219219
(3, 96, 96, 3)
@@ -238,7 +238,7 @@ class GrayscaleObservation(VectorizeTransformObservation):
238238
239239
Example:
240240
>>> import gymnasium as gym
241-
>>> envs = gym.make_vec("CarRacing-v2", num_envs=3, vectorization_mode="sync")
241+
>>> envs = gym.make_vec("CarRacing-v3", num_envs=3, vectorization_mode="sync")
242242
>>> obs, info = envs.reset(seed=123)
243243
>>> obs.shape
244244
(3, 96, 96, 3)
@@ -266,7 +266,7 @@ class ResizeObservation(VectorizeTransformObservation):
266266
267267
Example:
268268
>>> import gymnasium as gym
269-
>>> envs = gym.make_vec("CarRacing-v2", num_envs=3, vectorization_mode="sync")
269+
>>> envs = gym.make_vec("CarRacing-v3", num_envs=3, vectorization_mode="sync")
270270
>>> obs, info = envs.reset(seed=123)
271271
>>> obs.shape
272272
(3, 96, 96, 3)
@@ -292,7 +292,7 @@ class ReshapeObservation(VectorizeTransformObservation):
292292
293293
Example:
294294
>>> import gymnasium as gym
295-
>>> envs = gym.make_vec("CarRacing-v2", num_envs=3, vectorization_mode="sync")
295+
>>> envs = gym.make_vec("CarRacing-v3", num_envs=3, vectorization_mode="sync")
296296
>>> obs, info = envs.reset(seed=123)
297297
>>> obs.shape
298298
(3, 96, 96, 3)

Diff for: tests/envs/registration/test_make.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ def test_make_human_rendering(register_rendering_testing_envs):
242242
TypeError,
243243
match=re.escape("got an unexpected keyword argument 'render'"),
244244
):
245-
gym.make("CarRacing-v2", render="human")
245+
gym.make("CarRacing-v3", render="human")
246246

247247
# This test checks that a user can create an environment without the metadata including the render mode
248248
with pytest.warns(

Diff for: tests/envs/test_env_implementation.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def test_carracing_domain_randomize():
5454
CarRacing DomainRandomize should have different colours at every reset.
5555
However, it should have same colours when `options={"randomize": False}` is given to reset.
5656
"""
57-
env: CarRacing = gym.make("CarRacing-v2", domain_randomize=True).unwrapped
57+
env: CarRacing = gym.make("CarRacing-v3", domain_randomize=True).unwrapped
5858

5959
road_color = env.road_color
6060
bg_color = env.bg_color

Diff for: tests/wrappers/test_normalize_observation.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def test_update_running_mean_property():
6868

6969
def test_normalize_obs_with_vector():
7070
def thunk():
71-
env = gym.make("CarRacing-v2")
71+
env = gym.make("CarRacing-v3")
7272
env = gym.wrappers.GrayscaleObservation(env)
7373
env = gym.wrappers.NormalizeObservation(env)
7474
return env

Diff for: tests/wrappers/test_resize_observation.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def test_resize_observation_wrapper(env):
4747

4848
@pytest.mark.parametrize("shape", ((10, 10), (20, 20), (60, 60), (100, 100)))
4949
def test_resize_shapes(shape: tuple[int, int]):
50-
env = ResizeObservation(gym.make("CarRacing-v2"), shape)
50+
env = ResizeObservation(gym.make("CarRacing-v3"), shape)
5151
assert env.observation_space == Box(
5252
low=0, high=255, shape=shape + (3,), dtype=np.uint8
5353
)
@@ -59,7 +59,7 @@ def test_resize_shapes(shape: tuple[int, int]):
5959

6060

6161
def test_invalid_input():
62-
env = gym.make("CarRacing-v2")
62+
env = gym.make("CarRacing-v3")
6363

6464
with pytest.raises(AssertionError):
6565
ResizeObservation(env, ())

Diff for: tests/wrappers/vector/test_vector_wrappers.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ def custom_environments():
4242
(
4343
("CustomDictEnv-v0", "FilterObservation", {"filter_keys": ["a"]}),
4444
("CartPole-v1", "FlattenObservation", {}),
45-
("CarRacing-v2", "GrayscaleObservation", {}),
46-
("CarRacing-v2", "ResizeObservation", {"shape": (35, 45)}),
47-
("CarRacing-v2", "ReshapeObservation", {"shape": (96, 48, 6)}),
45+
("CarRacing-v3", "GrayscaleObservation", {}),
46+
("CarRacing-v3", "ResizeObservation", {"shape": (35, 45)}),
47+
("CarRacing-v3", "ReshapeObservation", {"shape": (96, 48, 6)}),
4848
(
4949
"CartPole-v1",
5050
"RescaleObservation",
@@ -53,7 +53,7 @@ def custom_environments():
5353
"max_obs": np.array([1, np.inf, 1, np.inf]),
5454
},
5555
),
56-
("CarRacing-v2", "DtypeObservation", {"dtype": np.int32}),
56+
("CarRacing-v3", "DtypeObservation", {"dtype": np.int32}),
5757
# ("CartPole-v1", "RenderObservation", {}), # not implemented
5858
# ("CartPole-v1", "TimeAwareObservation", {}), # not implemented
5959
# ("CartPole-v1", "FrameStackObservation", {}), # not implemented

0 commit comments

Comments
 (0)