Skip to content

Commit

Permalink
deprecate built in wrappers for supersuit
Browse files Browse the repository at this point in the history
  • Loading branch information
jkterry1 committed Jul 29, 2021
1 parent bc76034 commit 3133e99
Show file tree
Hide file tree
Showing 15 changed files with 35 additions and 12 deletions.
6 changes: 6 additions & 0 deletions 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:
Expand Down
3 changes: 2 additions & 1 deletion 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
Expand Down Expand Up @@ -67,6 +67,7 @@ def __init__(
)
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
Expand Down
3 changes: 2 additions & 1 deletion gym/wrappers/clip_action.py
@@ -1,5 +1,5 @@
import numpy as np

import warnings
from gym import ActionWrapper
from gym.spaces import Box

Expand All @@ -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):
Expand Down
3 changes: 2 additions & 1 deletion gym/wrappers/filter_observation.py
@@ -1,5 +1,5 @@
import copy

import warnings
from gym import spaces
from gym import ObservationWrapper

Expand All @@ -26,6 +26,7 @@ def __init__(self, env, filter_keys=None):
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()

Expand Down
2 changes: 2 additions & 0 deletions gym/wrappers/flatten_observation.py
@@ -1,5 +1,6 @@
import gym.spaces as spaces
from gym import ObservationWrapper
import warnings


class FlattenObservation(ObservationWrapper):
Expand All @@ -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)
3 changes: 2 additions & 1 deletion 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

Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion 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

Expand All @@ -15,6 +15,7 @@ def __init__(self, env, keep_dim=False):
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(
Expand Down
6 changes: 3 additions & 3 deletions 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
Expand Down Expand Up @@ -54,6 +52,8 @@ def __init__(
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):
Expand Down
3 changes: 2 additions & 1 deletion gym/wrappers/record_episode_statistics.py
@@ -1,6 +1,6 @@
import time
from collections import deque

import warnings
import gym


Expand All @@ -14,6 +14,7 @@ def __init__(self, env, deque_size=100):
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)
Expand Down
3 changes: 2 additions & 1 deletion gym/wrappers/rescale_action.py
@@ -1,5 +1,5 @@
import numpy as np

import warnings
import gym
from gym import spaces

Expand All @@ -19,6 +19,7 @@ def __init__(self, env, a, b):
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
Expand Down
3 changes: 2 additions & 1 deletion gym/wrappers/resize_observation.py
@@ -1,5 +1,5 @@
import numpy as np

import warnings
from gym.spaces import Box
from gym import ObservationWrapper

Expand All @@ -12,6 +12,7 @@ def __init__(self, env, shape):
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:]
Expand Down
3 changes: 2 additions & 1 deletion 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

Expand All @@ -17,6 +17,7 @@ def __init__(self, env):
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)
Expand Down
2 changes: 2 additions & 0 deletions 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:
Expand Down
2 changes: 2 additions & 0 deletions gym/wrappers/transform_observation.py
@@ -1,4 +1,5 @@
from gym import ObservationWrapper
import warnings


class TransformObservation(ObservationWrapper):
Expand All @@ -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):
Expand Down
2 changes: 2 additions & 0 deletions gym/wrappers/transform_reward.py
@@ -1,4 +1,5 @@
from gym import RewardWrapper
import warnings


class TransformReward(RewardWrapper):
Expand All @@ -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):
Expand Down

0 comments on commit 3133e99

Please sign in to comment.