deprecate built in wrappers for supersuit

This commit is contained in:
Justin Terry
2021-07-28 22:21:47 -04:00
parent bc76034167
commit 3133e99a64
15 changed files with 35 additions and 12 deletions

View File

@@ -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:

View File

@@ -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

View File

@@ -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):

View File

@@ -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()

View File

@@ -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)

View File

@@ -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

View File

@@ -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(

View File

@@ -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):

View File

@@ -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)

View File

@@ -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

View File

@@ -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:]

View File

@@ -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)

View File

@@ -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:

View File

@@ -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):

View File

@@ -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):