Skip to content

Commit

Permalink
Gymnasium dep (#814)
Browse files Browse the repository at this point in the history
  • Loading branch information
WillDudley authored Oct 7, 2022
1 parent 8fedeba commit 8fd6d0b
Show file tree
Hide file tree
Showing 59 changed files with 169 additions and 166 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Save time, add code.

**System Info**
Describe the characteristic of your environment:
* Describe how Gym was installed (pip, docker, source, ...)
* Describe how Gymnasium was installed (pip, docker, source, ...)
* Operating system:
* Python version:

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ In certain environments, it's a valid to assume that agents take their actions a

## SuperSuit

SuperSuit is a library that includes all commonly used wrappers in RL (frame stacking, observation, normalization, etc.) for PettingZoo and Gym environments with a nice API. We developed it in lieu of wrappers built into PettingZoo. https://github.com/Farama-Foundation/SuperSuit
SuperSuit is a library that includes all commonly used wrappers in RL (frame stacking, observation, normalization, etc.) for PettingZoo and Gymnasium environments with a nice API. We developed it in lieu of wrappers built into PettingZoo. https://github.com/Farama-Foundation/SuperSuit

## Environment Versioning

Expand Down
6 changes: 3 additions & 3 deletions docs/api/supersuit_wrappers.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Supersuit includes the following wrappers:

* `flatten_v0(env)` flattens observations into a 1D array.

* `frame_skip_v0(env, num_frames)` skips `num_frames` number of frames by reapplying old actions over and over. Observations skipped over are ignored. Rewards skipped over are accumulated. Like Gym Atari's frameskip parameter, `num_frames` can also be a tuple `(min_skip, max_skip)`, which indicates a range of possible skip lengths which are randomly chosen from (in single agent environments only).
* `frame_skip_v0(env, num_frames)` skips `num_frames` number of frames by reapplying old actions over and over. Observations skipped over are ignored. Rewards skipped over are accumulated. Like Gymnasium Atari's frameskip parameter, `num_frames` can also be a tuple `(min_skip, max_skip)`, which indicates a range of possible skip lengths which are randomly chosen from (in single agent environments only).

* `delay_observations_v0(env, delay)` Delays observation by `delay` frames. Before `delay` frames have been executed, the observation is all zeros. Along with frame_skip, this is the preferred way to implement reaction time for high FPS games.

Expand Down Expand Up @@ -103,7 +103,7 @@ Supersuit includes the following wrappers:
[//]: # (The following function performs this conversion.)

[//]: # ()
[//]: # (* `pettingzoo_env_to_vec_env_v0(env)`: Takes a PettingZoo ParallelEnv with the following assumptions: no agent death or generation, homogeneous action and observation spaces. Returns a gym vector environment where each "environment" in the vector represents one agent. An arbitrary PettingZoo parallel environment can be enforced to have these assumptions by wrapping it with the pad_action_space, pad_observations, and the black_death wrapper). This conversion to a vector environment can be used to train appropriate pettingzoo environments with standard single agent RL methods such as stable baselines's A2C out of box (example below).)
[//]: # (* `pettingzoo_env_to_vec_env_v0(env)`: Takes a PettingZoo ParallelEnv with the following assumptions: no agent death or generation, homogeneous action and observation spaces. Returns a gymnasium vector environment where each "environment" in the vector represents one agent. An arbitrary PettingZoo parallel environment can be enforced to have these assumptions by wrapping it with the pad_action_space, pad_observations, and the black_death wrapper). This conversion to a vector environment can be used to train appropriate pettingzoo environments with standard single agent RL methods such as stable baselines's A2C out of box (example below).)

[//]: # ()
[//]: # (You can also use the `concat_vec_envs_v0` functionality to train on several vector environments in parallel, forming a vector which looks like)
Expand Down Expand Up @@ -190,7 +190,7 @@ Supersuit includes the following wrappers:
[//]: # (* `observation_lambda_v0(env, observation_fn, observation_space_fn)` allows you to define arbitrary changes to the via `observation_fn(observation, obs_space) : observation`, and `observation_space_fn(obs_space) : obs_space`. For Box-Box transformations the space transformation will be inferred from `change_observation_fn` if `change_obs_space_fn=None` by passing the `high` and `low` bounds through the `observation_space_fn`. In multi-agent environments only, the lambda functions can optionally accept an `agent` parameter, which lets you know the agent name of the observation/observation space, e.g. `observation_fn(observation, obs_space, agent) : observation`.)

[//]: # ()
[//]: # (* `reward_lambda_v0(env, change_reward_fn)` allows you to make arbitrary changes to rewards by passing in a `change_reward_fn(reward) : reward` function. For Gym environments this is called every step to transform the returned reward. For AECEnv, this function is used to change each element in the rewards dictionary every step.)
[//]: # (* `reward_lambda_v0(env, change_reward_fn)` allows you to make arbitrary changes to rewards by passing in a `change_reward_fn(reward) : reward` function. For Gymnasium environments this is called every step to transform the returned reward. For AECEnv, this function is used to change each element in the rewards dictionary every step.)

[//]: # ()
[//]: # (### Lambda Function Examples)
Expand Down
12 changes: 6 additions & 6 deletions docs/code_examples/aec_rps.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import functools

import gym
import gymnasium
import numpy as np
from gym.spaces import Discrete
from gymnasium.spaces import Discrete

from pettingzoo import AECEnv
from pettingzoo.utils import agent_selector, wrappers
Expand Down Expand Up @@ -47,7 +47,7 @@ def env(render_mode=None):

class raw_env(AECEnv):
"""
The metadata holds environment constants. From gym, we inherit the "render_modes",
The metadata holds environment constants. From gymnasium, we inherit the "render_modes",
metadata which specifies which modes can be put into the render() method.
At least human mode should be supported.
The "name" metadata allows the environment to be pretty printed.
Expand All @@ -69,7 +69,7 @@ def __init__(self, render_mode=None):
zip(self.possible_agents, list(range(len(self.possible_agents))))
)

# Gym spaces are defined and documented here: https://gym.openai.com/docs/#spaces
# gymnasium spaces are defined and documented here: https://gymnasium.openai.com/docs/#spaces
self._action_spaces = {agent: Discrete(3) for agent in self.possible_agents}
self._observation_spaces = {
agent: Discrete(4) for agent in self.possible_agents
Expand All @@ -80,7 +80,7 @@ def __init__(self, render_mode=None):
# allows action space seeding to work as expected
@functools.lru_cache(maxsize=None)
def observation_space(self, agent):
# Gym spaces are defined and documented here: https://gym.openai.com/docs/#spaces
# gymnasium spaces are defined and documented here: https://gymnasium.openai.com/docs/#spaces
return Discrete(4)

@functools.lru_cache(maxsize=None)
Expand All @@ -93,7 +93,7 @@ def render(self):
up a graphical window, or open up some other display that a human can see and understand.
"""
if self.render_mode is None:
gym.logger.WARN(
gymnasium.logger.WARN(
"You are calling render method without specifying any render mode."
)
return
Expand Down
8 changes: 4 additions & 4 deletions docs/code_examples/parallel_rps.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import functools

import gym
from gym.spaces import Discrete
import gymnasium
from gymnasium.spaces import Discrete

from pettingzoo import ParallelEnv
from pettingzoo.utils import parallel_to_aec, wrappers
Expand Down Expand Up @@ -75,7 +75,7 @@ def __init__(self, render_mode=None):
# allows action space seeding to work as expected
@functools.lru_cache(maxsize=None)
def observation_space(self, agent):
# Gym spaces are defined and documented here: https://gym.openai.com/docs/#spaces
# gymnasium spaces are defined and documented here: https://gymnasium.openai.com/docs/#spaces
return Discrete(4)

@functools.lru_cache(maxsize=None)
Expand All @@ -88,7 +88,7 @@ def render(self):
up a graphical window, or open up some other display that a human can see and understand.
"""
if self.render_mode is None:
gym.logger.WARN(
gymnasium.logger.WARN(
"You are calling render method without specifying any render mode."
)
return
Expand Down
8 changes: 4 additions & 4 deletions docs/content/code-examples/aec_rps.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import functools

import numpy as np
from gym.spaces import Discrete
from gymnasium.spaces import Discrete

from pettingzoo import AECEnv
from pettingzoo.utils import agent_selector, wrappers
Expand Down Expand Up @@ -44,7 +44,7 @@ def env():

class raw_env(AECEnv):
"""
The metadata holds environment constants. From gym, we inherit the "render_modes",
The metadata holds environment constants. From gymnasium, we inherit the "render_modes",
metadata which specifies which modes can be put into the render() method.
At least human mode should be supported.
The "name" metadata allows the environment to be pretty printed.
Expand All @@ -66,7 +66,7 @@ def __init__(self):
zip(self.possible_agents, list(range(len(self.possible_agents))))
)

# Gym spaces are defined and documented here: https://gym.openai.com/docs/#spaces
# gymnasium spaces are defined and documented here: https://gymnasium.openai.com/docs/#spaces
self._action_spaces = {agent: Discrete(3) for agent in self.possible_agents}
self._observation_spaces = {
agent: Discrete(4) for agent in self.possible_agents
Expand All @@ -76,7 +76,7 @@ def __init__(self):
# allows action space seeding to work as expected
@functools.lru_cache(maxsize=None)
def observation_space(self, agent):
# Gym spaces are defined and documented here: https://gym.openai.com/docs/#spaces
# gymnasium spaces are defined and documented here: https://gymnasium.openai.com/docs/#spaces
return Discrete(4)

@functools.lru_cache(maxsize=None)
Expand Down
4 changes: 2 additions & 2 deletions docs/content/code-examples/parallel_rps.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import functools

from gym.spaces import Discrete
from gymnasium.spaces import Discrete

from pettingzoo import ParallelEnv
from pettingzoo.utils import parallel_to_aec, wrappers
Expand Down Expand Up @@ -71,7 +71,7 @@ def __init__(self):
# allows action space seeding to work as expected
@functools.lru_cache(maxsize=None)
def observation_space(self, agent):
# Gym spaces are defined and documented here: https://gym.openai.com/docs/#spaces
# gymnasium spaces are defined and documented here: https://gymnasium.openai.com/docs/#spaces
return Discrete(4)

@functools.lru_cache(maxsize=None)
Expand Down
2 changes: 1 addition & 1 deletion pettingzoo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@

os.environ["PYGAME_HIDE_SUPPORT_PROMPT"] = "hide"

__version__ = "1.21.0"
__version__ = "1.22.0"
13 changes: 7 additions & 6 deletions pettingzoo/atari/base_atari_env.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from pathlib import Path

import gym
import gymnasium
import multi_agent_ale_py
import numpy as np
from gym import spaces
from gym.utils import EzPickle, seeding
from gymnasium import spaces
from gymnasium.utils import EzPickle, seeding

from pettingzoo.utils import wrappers
from pettingzoo.utils.conversions import ( # noqa: F401
Expand Down Expand Up @@ -132,7 +132,7 @@ def __init__(
self.action_mapping = action_mapping

if obs_type == "ram":
observation_space = gym.spaces.Box(
observation_space = gymnasium.spaces.Box(
low=0, high=255, dtype=np.uint8, shape=(128,)
)
else:
Expand All @@ -153,7 +153,8 @@ def __init__(
self.possible_agents = self.agents[:]

self.action_spaces = {
agent: gym.spaces.Discrete(action_size) for agent in self.possible_agents
agent: gymnasium.spaces.Discrete(action_size)
for agent in self.possible_agents
}
self.observation_spaces = {
agent: observation_space for agent in self.possible_agents
Expand Down Expand Up @@ -240,7 +241,7 @@ def step(self, action_dict):

def render(self):
if self.render_mode is None:
gym.logger.WARN(
gymnasium.logger.WARN(
"You are calling render method without specifying any render mode."
)
return
Expand Down
14 changes: 8 additions & 6 deletions pettingzoo/butterfly/cooperative_pong/cooperative_pong.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@
"""

import gym
import gymnasium
import numpy as np
import pygame
from gym.utils import EzPickle, seeding
from gymnasium.utils import EzPickle, seeding

from pettingzoo import AECEnv
from pettingzoo.utils import wrappers
Expand Down Expand Up @@ -169,19 +169,21 @@ def __init__(
self.off_screen_penalty = off_screen_penalty

# define action and observation spaces
self.action_space = [gym.spaces.Discrete(3) for _ in range(self.num_agents)]
self.action_space = [
gymnasium.spaces.Discrete(3) for _ in range(self.num_agents)
]
original_shape = original_obs_shape(
self.s_width, self.s_height, kernel_window_length=kernel_window_length
)
original_color_shape = (original_shape[0], original_shape[1], 3)
self.observation_space = [
gym.spaces.Box(
gymnasium.spaces.Box(
low=0, high=255, shape=(original_color_shape), dtype=np.uint8
)
for _ in range(self.num_agents)
]
# define the global space of the environment or state
self.state_space = gym.spaces.Box(
self.state_space = gymnasium.spaces.Box(
low=0, high=255, shape=((self.s_height, self.s_width, 3)), dtype=np.uint8
)

Expand Down Expand Up @@ -262,7 +264,7 @@ def enable_render(self):

def render(self):
if self.render_mode is None:
gym.logger.WARN(
gymnasium.logger.WARN(
"You are calling render method without specifying any render mode."
)
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,12 @@
import sys
from itertools import repeat

import gym
import gymnasium
import numpy as np
import pygame
import pygame.gfxdraw
from gym.spaces import Box, Discrete
from gym.utils import EzPickle, seeding
from gymnasium.spaces import Box, Discrete
from gymnasium.utils import EzPickle, seeding

from pettingzoo import AECEnv
from pettingzoo.utils import agent_selector, wrappers
Expand Down Expand Up @@ -797,7 +797,7 @@ def draw(self):

def render(self):
if self.render_mode is None:
gym.logger.WARN(
gymnasium.logger.WARN(
"You are calling render method without specifying any render mode."
)
return
Expand Down
14 changes: 7 additions & 7 deletions pettingzoo/butterfly/pistonball/pistonball.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@

import math

import gym
import gymnasium
import numpy as np
import pygame
import pymunk
import pymunk.pygame_util
from gym.utils import EzPickle, seeding
from gymnasium.utils import EzPickle, seeding

from pettingzoo import AECEnv
from pettingzoo.utils import agent_selector, wrappers
Expand Down Expand Up @@ -191,7 +191,7 @@ def __init__(
zip(
self.agents,
[
gym.spaces.Box(
gymnasium.spaces.Box(
low=0,
high=255,
shape=(obs_height, self.piston_width * 3, 3),
Expand All @@ -206,14 +206,14 @@ def __init__(
self.action_spaces = dict(
zip(
self.agents,
[gym.spaces.Box(low=-1, high=1, shape=(1,))] * self.n_pistons,
[gymnasium.spaces.Box(low=-1, high=1, shape=(1,))] * self.n_pistons,
)
)
else:
self.action_spaces = dict(
zip(self.agents, [gym.spaces.Discrete(3)] * self.n_pistons)
zip(self.agents, [gymnasium.spaces.Discrete(3)] * self.n_pistons)
)
self.state_space = gym.spaces.Box(
self.state_space = gymnasium.spaces.Box(
low=0,
high=255,
shape=(self.screen_height, self.screen_width, 3),
Expand Down Expand Up @@ -598,7 +598,7 @@ def get_local_reward(self, prev_position, curr_position):

def render(self):
if self.render_mode is None:
gym.logger.WARN(
gymnasium.logger.WARN(
"You are calling render method without specifying any render mode."
)
return
Expand Down
6 changes: 3 additions & 3 deletions pettingzoo/classic/chess/chess.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@
"""

import chess
import gym
import gymnasium
import numpy as np
from gym import spaces
from gymnasium import spaces

from pettingzoo import AECEnv
from pettingzoo.utils import wrappers
Expand Down Expand Up @@ -246,7 +246,7 @@ def step(self, action):

def render(self):
if self.render_mode is None:
gym.logger.WARN(
gymnasium.logger.WARN(
"You are calling render method without specifying any render mode."
)
else:
Expand Down
6 changes: 3 additions & 3 deletions pettingzoo/classic/connect_four/connect_four.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@

import os

import gym
import gymnasium
import numpy as np
import pygame
from gym import spaces
from gymnasium import spaces

from pettingzoo import AECEnv
from pettingzoo.utils import wrappers
Expand Down Expand Up @@ -224,7 +224,7 @@ def reset(self, seed=None, return_info=False, options=None):

def render(self):
if self.render_mode is None:
gym.logger.WARN(
gymnasium.logger.WARN(
"You are calling render method without specifying any render mode."
)
return
Expand Down
Loading

0 comments on commit 8fd6d0b

Please sign in to comment.