Skip to content

Commit

Permalink
Change end-of-episode truncation to termination in Car Racing. Bump e…
Browse files Browse the repository at this point in the history
…nv version
  • Loading branch information
RedTachyon committed Dec 5, 2023
1 parent 2790321 commit 60bebb0
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 22 deletions.
2 changes: 1 addition & 1 deletion gymnasium/envs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
)

register(
id="CarRacing-v2",
id="CarRacing-v3",
entry_point="gymnasium.envs.box2d.car_racing:CarRacing",
max_episode_steps=1000,
reward_threshold=900,
Expand Down
7 changes: 3 additions & 4 deletions gymnasium/envs/box2d/car_racing.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ class CarRacing(gym.Env, EzPickle):
```
## Version History
- v2: Change truncation to termination when finishing the lap (1.0.0)
- v1: Change track completion logic and add domain randomization (0.24.0)
- v0: Original version
Expand Down Expand Up @@ -563,10 +564,8 @@ def step(self, action: Union[np.ndarray, int]):
step_reward = self.reward - self.prev_reward
self.prev_reward = self.reward
if self.tile_visited_count == len(self.track) or self.new_lap:
# Truncation due to finishing lap
# This should not be treated as a failure
# but like a timeout
truncated = True
# Termination due to finishing lap
terminated = True
x, y = self.car.hull.position
if abs(x) > PLAYFIELD or abs(y) > PLAYFIELD:
terminated = True
Expand Down
2 changes: 1 addition & 1 deletion gymnasium/utils/play.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def play(
Example:
>>> from gymnasium.utils.play import play
>>> play(gym.make("CarRacing-v2", render_mode="rgb_array"), # doctest: +SKIP
>>> play(gym.make("CarRacing-v3", render_mode="rgb_array"), # doctest: +SKIP
... keys_to_action={
... "w": np.array([0, 0.7, 0]),
... "a": np.array([-1, 0, 0]),
Expand Down
2 changes: 1 addition & 1 deletion gymnasium/wrappers/stateful_observation.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ class FrameStackObservation(
Example:
>>> import gymnasium as gym
>>> from gymnasium.wrappers import FrameStackObservation
>>> env = gym.make("CarRacing-v2")
>>> env = gym.make("CarRacing-v3")
>>> env = FrameStackObservation(env, 4)
>>> env.observation_space
Box(0, 255, (4, 96, 96, 3), uint8)
Expand Down
8 changes: 4 additions & 4 deletions gymnasium/wrappers/transform_observation.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ class FlattenObservation(
Example:
>>> import gymnasium as gym
>>> from gymnasium.wrappers import FlattenObservation
>>> env = gym.make("CarRacing-v2")
>>> env = gym.make("CarRacing-v3")
>>> env.observation_space.shape
(96, 96, 3)
>>> env = FlattenObservation(env)
Expand Down Expand Up @@ -264,7 +264,7 @@ class GrayscaleObservation(
Example:
>>> import gymnasium as gym
>>> from gymnasium.wrappers import GrayscaleObservation
>>> env = gym.make("CarRacing-v2")
>>> env = gym.make("CarRacing-v3")
>>> env.observation_space.shape
(96, 96, 3)
>>> grayscale_env = GrayscaleObservation(env)
Expand Down Expand Up @@ -342,7 +342,7 @@ class ResizeObservation(
Example:
>>> import gymnasium as gym
>>> from gymnasium.wrappers import ResizeObservation
>>> env = gym.make("CarRacing-v2")
>>> env = gym.make("CarRacing-v3")
>>> env.observation_space.shape
(96, 96, 3)
>>> resized_env = ResizeObservation(env, (32, 32))
Expand Down Expand Up @@ -413,7 +413,7 @@ class ReshapeObservation(
Example:
>>> import gymnasium as gym
>>> from gymnasium.wrappers import ReshapeObservation
>>> env = gym.make("CarRacing-v2")
>>> env = gym.make("CarRacing-v3")
>>> env.observation_space.shape
(96, 96, 3)
>>> reshape_env = ReshapeObservation(env, (24, 4, 96, 1, 3))
Expand Down
8 changes: 4 additions & 4 deletions gymnasium/wrappers/vector/vectorize_observation.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ class FlattenObservation(VectorizeTransformObservation):
Example:
>>> import gymnasium as gym
>>> envs = gym.make_vec("CarRacing-v2", num_envs=3, vectorization_mode="sync")
>>> envs = gym.make_vec("CarRacing-v3", num_envs=3, vectorization_mode="sync")
>>> obs, info = envs.reset(seed=123)
>>> obs.shape
(3, 96, 96, 3)
Expand All @@ -237,7 +237,7 @@ class GrayscaleObservation(VectorizeTransformObservation):
Example:
>>> import gymnasium as gym
>>> envs = gym.make_vec("CarRacing-v2", num_envs=3, vectorization_mode="sync")
>>> envs = gym.make_vec("CarRacing-v3", num_envs=3, vectorization_mode="sync")
>>> obs, info = envs.reset(seed=123)
>>> obs.shape
(3, 96, 96, 3)
Expand Down Expand Up @@ -265,7 +265,7 @@ class ResizeObservation(VectorizeTransformObservation):
Example:
>>> import gymnasium as gym
>>> envs = gym.make_vec("CarRacing-v2", num_envs=3, vectorization_mode="sync")
>>> envs = gym.make_vec("CarRacing-v3", num_envs=3, vectorization_mode="sync")
>>> obs, info = envs.reset(seed=123)
>>> obs.shape
(3, 96, 96, 3)
Expand All @@ -291,7 +291,7 @@ class ReshapeObservation(VectorizeTransformObservation):
Example:
>>> import gymnasium as gym
>>> envs = gym.make_vec("CarRacing-v2", num_envs=3, vectorization_mode="sync")
>>> envs = gym.make_vec("CarRacing-v3", num_envs=3, vectorization_mode="sync")
>>> obs, info = envs.reset(seed=123)
>>> obs.shape
(3, 96, 96, 3)
Expand Down
2 changes: 1 addition & 1 deletion tests/envs/registration/test_make.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def test_make_human_rendering(register_rendering_testing_envs):
TypeError,
match=re.escape("got an unexpected keyword argument 'render'"),
):
gym.make("CarRacing-v2", render="human")
gym.make("CarRacing-v3", render="human")

# This test checks that a user can create an environment without the metadata including the render mode
with pytest.warns(
Expand Down
2 changes: 1 addition & 1 deletion tests/envs/test_env_implementation.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_carracing_domain_randomize():
CarRacing DomainRandomize should have different colours at every reset.
However, it should have same colours when `options={"randomize": False}` is given to reset.
"""
env: CarRacing = gym.make("CarRacing-v2", domain_randomize=True).unwrapped
env: CarRacing = gym.make("CarRacing-v3", domain_randomize=True).unwrapped

road_color = env.road_color
bg_color = env.bg_color
Expand Down
4 changes: 2 additions & 2 deletions tests/wrappers/test_resize_observation.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def test_resize_observation_wrapper(env):

@pytest.mark.parametrize("shape", ((10, 10), (20, 20), (60, 60), (100, 100)))
def test_resize_shapes(shape: tuple[int, int]):
env = ResizeObservation(gym.make("CarRacing-v2"), shape)
env = ResizeObservation(gym.make("CarRacing-v3"), shape)
assert env.observation_space == Box(
low=0, high=255, shape=shape + (3,), dtype=np.uint8
)
Expand All @@ -58,7 +58,7 @@ def test_resize_shapes(shape: tuple[int, int]):


def test_invalid_input():
env = gym.make("CarRacing-v2")
env = gym.make("CarRacing-v3")

with pytest.raises(AssertionError):
ResizeObservation(env, ())
Expand Down
6 changes: 3 additions & 3 deletions tests/wrappers/vector/test_vector_wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ def custom_environments():
(
("CustomDictEnv-v0", "FilterObservation", {"filter_keys": ["a"]}),
("CartPole-v1", "FlattenObservation", {}),
("CarRacing-v2", "GrayscaleObservation", {}),
("CarRacing-v2", "ResizeObservation", {"shape": (35, 45)}),
("CarRacing-v2", "ReshapeObservation", {"shape": (96, 48, 6)}),
("CarRacing-v3", "GrayscaleObservation", {}),
("CarRacing-v3", "ResizeObservation", {"shape": (35, 45)}),
("CarRacing-v3", "ReshapeObservation", {"shape": (96, 48, 6)}),
("CartPole-v1", "RescaleObservation", {"min_obs": 0, "max_obs": 1}),
("CartPole-v1", "DtypeObservation", {"dtype": np.int32}),
# ("CartPole-v1", "RenderObservation", {}), # not implemented
Expand Down

0 comments on commit 60bebb0

Please sign in to comment.