diff --git a/gym/wrappers/README.md b/gym/wrappers/README.md index d5307a158..2db7cc1af 100644 --- a/gym/wrappers/README.md +++ b/gym/wrappers/README.md @@ -1,3 +1,9 @@ +# Deprecation + +While Gym's wrappers will continue to work for the foreseeable future due to the widespread dependence on them throughout the community, we are deprecating them and encourage users to use [SuperSuit](https://github.com/PettingZoo-Team/SuperSuit) instead. + +# Old Docs: + # Wrappers Wrappers are used to transform an environment in a modular way: diff --git a/gym/wrappers/atari_preprocessing.py b/gym/wrappers/atari_preprocessing.py index b3f4b0df6..bbf155d71 100644 --- a/gym/wrappers/atari_preprocessing.py +++ b/gym/wrappers/atari_preprocessing.py @@ -1,5 +1,5 @@ import numpy as np - +import warnings import gym from gym.spaces import Box from gym.wrappers import TimeLimit @@ -67,6 +67,7 @@ class AtariPreprocessing(gym.Wrapper): ) self.noop_max = noop_max assert env.unwrapped.get_action_meanings()[0] == "NOOP" + warnings.warn("Gym\'s internal preprocessing wrappers are now deprecated. While they will continue to work for the foreseeable future, we strongly recommend using SuperSuit instead: https://github.com/PettingZoo-Team/SuperSuit") self.frame_skip = frame_skip self.screen_size = screen_size diff --git a/gym/wrappers/clip_action.py b/gym/wrappers/clip_action.py index 7e6bc1bc0..cb9a1c28c 100644 --- a/gym/wrappers/clip_action.py +++ b/gym/wrappers/clip_action.py @@ -1,5 +1,5 @@ import numpy as np - +import warnings from gym import ActionWrapper from gym.spaces import Box @@ -9,6 +9,7 @@ class ClipAction(ActionWrapper): def __init__(self, env): assert isinstance(env.action_space, Box) + warnings.warn("Gym\'s internal preprocessing wrappers are now deprecated. While they will continue to work for the foreseeable future, we strongly recommend using SuperSuit instead: https://github.com/PettingZoo-Team/SuperSuit") super(ClipAction, self).__init__(env) def action(self, action): diff --git a/gym/wrappers/filter_observation.py b/gym/wrappers/filter_observation.py index ad624a3ee..c3c31c684 100644 --- a/gym/wrappers/filter_observation.py +++ b/gym/wrappers/filter_observation.py @@ -1,5 +1,5 @@ import copy - +import warnings from gym import spaces from gym import ObservationWrapper @@ -26,6 +26,7 @@ class FilterObservation(ObservationWrapper): assert isinstance( wrapped_observation_space, spaces.Dict ), "FilterObservationWrapper is only usable with dict observations." + warnings.warn("Gym\'s internal preprocessing wrappers are now deprecated. While they will continue to work for the foreseeable future, we strongly recommend using SuperSuit instead: https://github.com/PettingZoo-Team/SuperSuit") observation_keys = wrapped_observation_space.spaces.keys() diff --git a/gym/wrappers/flatten_observation.py b/gym/wrappers/flatten_observation.py index 9dca4da25..d19e57adc 100644 --- a/gym/wrappers/flatten_observation.py +++ b/gym/wrappers/flatten_observation.py @@ -1,5 +1,6 @@ import gym.spaces as spaces from gym import ObservationWrapper +import warnings class FlattenObservation(ObservationWrapper): @@ -8,6 +9,7 @@ class FlattenObservation(ObservationWrapper): def __init__(self, env): super(FlattenObservation, self).__init__(env) self.observation_space = spaces.flatten_space(env.observation_space) + warnings.warn("Gym\'s internal preprocessing wrappers are now deprecated. While they will continue to work for the foreseeable future, we strongly recommend using SuperSuit instead: https://github.com/PettingZoo-Team/SuperSuit") def observation(self, observation): return spaces.flatten(self.env.observation_space, observation) diff --git a/gym/wrappers/frame_stack.py b/gym/wrappers/frame_stack.py index c6c7786a8..b8fa0762e 100644 --- a/gym/wrappers/frame_stack.py +++ b/gym/wrappers/frame_stack.py @@ -1,6 +1,6 @@ from collections import deque import numpy as np - +import warnings from gym.spaces import Box from gym import Wrapper @@ -22,6 +22,7 @@ class LazyFrames(object): __slots__ = ("frame_shape", "dtype", "shape", "lz4_compress", "_frames") def __init__(self, frames, lz4_compress=False): + warnings.warn("Gym\'s internal preprocessing wrappers are now deprecated. While they will continue to work for the foreseeable future, we strongly recommend using SuperSuit instead: https://github.com/PettingZoo-Team/SuperSuit") self.frame_shape = tuple(frames[0].shape) self.shape = (len(frames),) + self.frame_shape self.dtype = frames[0].dtype diff --git a/gym/wrappers/gray_scale_observation.py b/gym/wrappers/gray_scale_observation.py index e2b7f2059..be455ecde 100644 --- a/gym/wrappers/gray_scale_observation.py +++ b/gym/wrappers/gray_scale_observation.py @@ -1,5 +1,5 @@ import numpy as np - +import warnings from gym.spaces import Box from gym import ObservationWrapper @@ -15,6 +15,7 @@ class GrayScaleObservation(ObservationWrapper): len(env.observation_space.shape) == 3 and env.observation_space.shape[-1] == 3 ) + warnings.warn("Gym\'s internal preprocessing wrappers are now deprecated. While they will continue to work for the foreseeable future, we strongly recommend using SuperSuit instead: https://github.com/PettingZoo-Team/SuperSuit") obs_shape = self.observation_space.shape[:2] if self.keep_dim: self.observation_space = Box( diff --git a/gym/wrappers/pixel_observation.py b/gym/wrappers/pixel_observation.py index 677c52f66..5267510b9 100644 --- a/gym/wrappers/pixel_observation.py +++ b/gym/wrappers/pixel_observation.py @@ -1,9 +1,7 @@ -"""An observation wrapper that augments observations by pixel values.""" - import collections from collections.abc import MutableMapping import copy - +import warnings import numpy as np from gym import spaces @@ -54,6 +52,8 @@ class PixelObservationWrapper(ObservationWrapper): assert render_mode == "rgb_array", render_mode render_kwargs[key]["mode"] = "rgb_array" + warnings.warn("Gym\'s internal preprocessing wrappers are now deprecated. While they will continue to work for the foreseeable future, we strongly recommend using SuperSuit instead: https://github.com/PettingZoo-Team/SuperSuit") + wrapped_observation_space = env.observation_space if isinstance(wrapped_observation_space, spaces.Box): diff --git a/gym/wrappers/record_episode_statistics.py b/gym/wrappers/record_episode_statistics.py index 54daf35d1..863dae292 100644 --- a/gym/wrappers/record_episode_statistics.py +++ b/gym/wrappers/record_episode_statistics.py @@ -1,6 +1,6 @@ import time from collections import deque - +import warnings import gym @@ -14,6 +14,7 @@ class RecordEpisodeStatistics(gym.Wrapper): self.episode_length = 0 self.return_queue = deque(maxlen=deque_size) self.length_queue = deque(maxlen=deque_size) + warnings.warn("Gym\'s internal preprocessing wrappers are now deprecated. While they will continue to work for the foreseeable future, we strongly recommend using SuperSuit instead: https://github.com/PettingZoo-Team/SuperSuit") def reset(self, **kwargs): observation = super(RecordEpisodeStatistics, self).reset(**kwargs) diff --git a/gym/wrappers/rescale_action.py b/gym/wrappers/rescale_action.py index 4200d9957..6a74b8610 100644 --- a/gym/wrappers/rescale_action.py +++ b/gym/wrappers/rescale_action.py @@ -1,5 +1,5 @@ import numpy as np - +import warnings import gym from gym import spaces @@ -19,6 +19,7 @@ class RescaleAction(gym.ActionWrapper): env.action_space, spaces.Box ), "expected Box action space, got {}".format(type(env.action_space)) assert np.less_equal(a, b).all(), (a, b) + warnings.warn("Gym\'s internal preprocessing wrappers are now deprecated. While they will continue to work for the foreseeable future, we strongly recommend using SuperSuit instead: https://github.com/PettingZoo-Team/SuperSuit") super(RescaleAction, self).__init__(env) self.a = np.zeros(env.action_space.shape, dtype=env.action_space.dtype) + a self.b = np.zeros(env.action_space.shape, dtype=env.action_space.dtype) + b diff --git a/gym/wrappers/resize_observation.py b/gym/wrappers/resize_observation.py index bbc54f67e..c16881199 100644 --- a/gym/wrappers/resize_observation.py +++ b/gym/wrappers/resize_observation.py @@ -1,5 +1,5 @@ import numpy as np - +import warnings from gym.spaces import Box from gym import ObservationWrapper @@ -12,6 +12,7 @@ class ResizeObservation(ObservationWrapper): if isinstance(shape, int): shape = (shape, shape) assert all(x > 0 for x in shape), shape + warnings.warn("Gym\'s internal preprocessing wrappers are now deprecated. While they will continue to work for the foreseeable future, we strongly recommend using SuperSuit instead: https://github.com/PettingZoo-Team/SuperSuit") self.shape = tuple(shape) obs_shape = self.shape + self.observation_space.shape[2:] diff --git a/gym/wrappers/time_aware_observation.py b/gym/wrappers/time_aware_observation.py index f9244dd25..8b0b864b2 100644 --- a/gym/wrappers/time_aware_observation.py +++ b/gym/wrappers/time_aware_observation.py @@ -1,5 +1,5 @@ import numpy as np - +import warnings from gym.spaces import Box from gym import ObservationWrapper @@ -17,6 +17,7 @@ class TimeAwareObservation(ObservationWrapper): super(TimeAwareObservation, self).__init__(env) assert isinstance(env.observation_space, Box) assert env.observation_space.dtype == np.float32 + warnings.warn("Gym\'s internal preprocessing wrappers are now deprecated. While they will continue to work for the foreseeable future, we strongly recommend using SuperSuit instead: https://github.com/PettingZoo-Team/SuperSuit") low = np.append(self.observation_space.low, 0.0) high = np.append(self.observation_space.high, np.inf) self.observation_space = Box(low, high, dtype=np.float32) diff --git a/gym/wrappers/time_limit.py b/gym/wrappers/time_limit.py index ee8cac96f..a0ef43dde 100644 --- a/gym/wrappers/time_limit.py +++ b/gym/wrappers/time_limit.py @@ -1,9 +1,11 @@ import gym +import warnings class TimeLimit(gym.Wrapper): def __init__(self, env, max_episode_steps=None): super(TimeLimit, self).__init__(env) + warnings.warn("Gym\'s internal preprocessing wrappers are now deprecated. While they will continue to work for the foreseeable future, we strongly recommend using SuperSuit instead: https://github.com/PettingZoo-Team/SuperSuit") if max_episode_steps is None and self.env.spec is not None: max_episode_steps = env.spec.max_episode_steps if self.env.spec is not None: diff --git a/gym/wrappers/transform_observation.py b/gym/wrappers/transform_observation.py index ade8f9357..5b56f8fab 100644 --- a/gym/wrappers/transform_observation.py +++ b/gym/wrappers/transform_observation.py @@ -1,4 +1,5 @@ from gym import ObservationWrapper +import warnings class TransformObservation(ObservationWrapper): @@ -21,6 +22,7 @@ class TransformObservation(ObservationWrapper): def __init__(self, env, f): super(TransformObservation, self).__init__(env) assert callable(f) + warnings.warn("Gym\'s internal preprocessing wrappers are now deprecated. While they will continue to work for the foreseeable future, we strongly recommend using SuperSuit instead: https://github.com/PettingZoo-Team/SuperSuit") self.f = f def observation(self, observation): diff --git a/gym/wrappers/transform_reward.py b/gym/wrappers/transform_reward.py index cd90c5ebf..be44abf76 100644 --- a/gym/wrappers/transform_reward.py +++ b/gym/wrappers/transform_reward.py @@ -1,4 +1,5 @@ from gym import RewardWrapper +import warnings class TransformReward(RewardWrapper): @@ -23,6 +24,7 @@ class TransformReward(RewardWrapper): def __init__(self, env, f): super(TransformReward, self).__init__(env) assert callable(f) + warnings.warn("Gym\'s internal preprocessing wrappers are now deprecated. While they will continue to work for the foreseeable future, we strongly recommend using SuperSuit instead: https://github.com/PettingZoo-Team/SuperSuit") self.f = f def reward(self, reward):