From 60bebb02edc81d0dbf542698d8dd67b33203a557 Mon Sep 17 00:00:00 2001 From: ariel Date: Tue, 5 Dec 2023 01:47:59 +0100 Subject: [PATCH] Change end-of-episode truncation to termination in Car Racing. Bump env version --- gymnasium/envs/__init__.py | 2 +- gymnasium/envs/box2d/car_racing.py | 7 +++---- gymnasium/utils/play.py | 2 +- gymnasium/wrappers/stateful_observation.py | 2 +- gymnasium/wrappers/transform_observation.py | 8 ++++---- gymnasium/wrappers/vector/vectorize_observation.py | 8 ++++---- tests/envs/registration/test_make.py | 2 +- tests/envs/test_env_implementation.py | 2 +- tests/wrappers/test_resize_observation.py | 4 ++-- tests/wrappers/vector/test_vector_wrappers.py | 6 +++--- 10 files changed, 21 insertions(+), 22 deletions(-) diff --git a/gymnasium/envs/__init__.py b/gymnasium/envs/__init__.py index 507d075b4..6e6af3467 100644 --- a/gymnasium/envs/__init__.py +++ b/gymnasium/envs/__init__.py @@ -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, diff --git a/gymnasium/envs/box2d/car_racing.py b/gymnasium/envs/box2d/car_racing.py index 5044bb400..64eec81bc 100644 --- a/gymnasium/envs/box2d/car_racing.py +++ b/gymnasium/envs/box2d/car_racing.py @@ -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 @@ -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 diff --git a/gymnasium/utils/play.py b/gymnasium/utils/play.py index 7c461691b..92a0dcfbf 100644 --- a/gymnasium/utils/play.py +++ b/gymnasium/utils/play.py @@ -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]), diff --git a/gymnasium/wrappers/stateful_observation.py b/gymnasium/wrappers/stateful_observation.py index 6f211d72f..47c6ebe82 100644 --- a/gymnasium/wrappers/stateful_observation.py +++ b/gymnasium/wrappers/stateful_observation.py @@ -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) diff --git a/gymnasium/wrappers/transform_observation.py b/gymnasium/wrappers/transform_observation.py index 9d8c3a51d..6cedc03fd 100644 --- a/gymnasium/wrappers/transform_observation.py +++ b/gymnasium/wrappers/transform_observation.py @@ -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) @@ -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) @@ -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)) @@ -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)) diff --git a/gymnasium/wrappers/vector/vectorize_observation.py b/gymnasium/wrappers/vector/vectorize_observation.py index c0b8f6331..f89ac89e1 100644 --- a/gymnasium/wrappers/vector/vectorize_observation.py +++ b/gymnasium/wrappers/vector/vectorize_observation.py @@ -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) @@ -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) @@ -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) @@ -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) diff --git a/tests/envs/registration/test_make.py b/tests/envs/registration/test_make.py index 9cf0072e2..b313449c1 100644 --- a/tests/envs/registration/test_make.py +++ b/tests/envs/registration/test_make.py @@ -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( diff --git a/tests/envs/test_env_implementation.py b/tests/envs/test_env_implementation.py index 312b4e78e..96dffb91b 100644 --- a/tests/envs/test_env_implementation.py +++ b/tests/envs/test_env_implementation.py @@ -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 diff --git a/tests/wrappers/test_resize_observation.py b/tests/wrappers/test_resize_observation.py index 233612930..c78c3a4e9 100644 --- a/tests/wrappers/test_resize_observation.py +++ b/tests/wrappers/test_resize_observation.py @@ -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 ) @@ -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, ()) diff --git a/tests/wrappers/vector/test_vector_wrappers.py b/tests/wrappers/vector/test_vector_wrappers.py index cf0db8b69..051aea005 100644 --- a/tests/wrappers/vector/test_vector_wrappers.py +++ b/tests/wrappers/vector/test_vector_wrappers.py @@ -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