Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added EzPickle support to all envs #924

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pettingzoo/classic/chess/chess.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
import numpy as np
from gymnasium import spaces
from gymnasium.error import DependencyNotInstalled
from gymnasium.utils import EzPickle

from pettingzoo import AECEnv
from pettingzoo.utils import wrappers
Expand All @@ -106,7 +107,7 @@ def env(render_mode=None):
return env


class raw_env(AECEnv):
class raw_env(AECEnv, EzPickle):
metadata = {
"render_modes": ["human", "ansi", "rgb_array"],
"name": "chess_v5",
Expand All @@ -115,6 +116,7 @@ class raw_env(AECEnv):
}

def __init__(self, render_mode=None):
EzPickle.__init__(self, render_mode)
super().__init__()

self.board = chess.Board()
Expand Down
4 changes: 3 additions & 1 deletion pettingzoo/classic/connect_four/connect_four.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
import numpy as np
import pygame
from gymnasium import spaces
from gymnasium.utils import EzPickle

from pettingzoo import AECEnv
from pettingzoo.utils import wrappers
Expand All @@ -90,7 +91,7 @@ def env(render_mode=None):
return env


class raw_env(AECEnv):
class raw_env(AECEnv, EzPickle):
metadata = {
"render_modes": ["human", "rgb_array"],
"name": "connect_four_v3",
Expand All @@ -99,6 +100,7 @@ class raw_env(AECEnv):
}

def __init__(self, render_mode=None):
EzPickle.__init__(self, render_mode)
super().__init__()
# 6 rows x 7 columns
# blank space = 0
Expand Down
4 changes: 3 additions & 1 deletion pettingzoo/classic/go/go.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
import numpy as np
import pygame
from gymnasium import spaces
from gymnasium.utils import EzPickle

from pettingzoo import AECEnv
from pettingzoo.utils import wrappers
Expand Down Expand Up @@ -142,7 +143,7 @@ def env(**kwargs):
return env


class raw_env(AECEnv):
class raw_env(AECEnv, EzPickle):
metadata = {
"render_modes": ["human", "rgb_array"],
"name": "go_v5",
Expand All @@ -153,6 +154,7 @@ class raw_env(AECEnv):
def __init__(
self, board_size: int = 19, komi: float = 7.5, render_mode: Optional[str] = None
):
EzPickle.__init__(self, board_size, komi, render_mode)
# board_size: a int, representing the board size (board has a board_size x board_size shape)
# komi: a float, representing points given to the second player.
super().__init__()
Expand Down
4 changes: 3 additions & 1 deletion pettingzoo/classic/rlcard_envs/leduc_holdem.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
"""

import gymnasium
from gymnasium.utils import EzPickle
from rlcard.utils.utils import print_card

from pettingzoo.utils import wrappers
Expand All @@ -103,7 +104,7 @@ def env(**kwargs):
return env


class raw_env(RLCardBase):
class raw_env(RLCardBase, EzPickle):
metadata = {
"render_modes": ["human"],
"name": "leduc_holdem_v4",
Expand All @@ -112,6 +113,7 @@ class raw_env(RLCardBase):
}

def __init__(self, num_players=2, render_mode=None):
EzPickle.__init__(self, num_players, render_mode)
super().__init__("leduc-holdem", num_players, (36,))
self.render_mode = render_mode

Expand Down
4 changes: 3 additions & 1 deletion pettingzoo/classic/rlcard_envs/rlcard_base.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import numpy as np
import rlcard
from gymnasium import spaces
from gymnasium.utils import EzPickle

from pettingzoo import AECEnv


class RLCardBase(AECEnv):
class RLCardBase(AECEnv, EzPickle):
def __init__(self, name, num_players, obs_shape):
EzPickle.__init__(self, name, num_players, obs_shape)
super().__init__()
self.name = name
self.num_players = num_players
Expand Down
4 changes: 3 additions & 1 deletion pettingzoo/classic/rlcard_envs/texas_holdem.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
import gymnasium
import numpy as np
import pygame
from gymnasium.utils import EzPickle

from pettingzoo.utils import wrappers

Expand Down Expand Up @@ -114,7 +115,7 @@ def env(**kwargs):
return env


class raw_env(RLCardBase):
class raw_env(RLCardBase, EzPickle):
metadata = {
"render_modes": ["human", "rgb_array"],
"name": "texas_holdem_v4",
Expand All @@ -123,6 +124,7 @@ class raw_env(RLCardBase):
}

def __init__(self, num_players=2, render_mode=None):
EzPickle.__init__(self, num_players, render_mode)
super().__init__("limit-holdem", num_players, (72,))
self.render_mode = render_mode

Expand Down
4 changes: 3 additions & 1 deletion pettingzoo/classic/rlcard_envs/texas_holdem_no_limit.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
import numpy as np
import pygame
from gymnasium import spaces
from gymnasium.utils import EzPickle

from pettingzoo.utils import wrappers

Expand Down Expand Up @@ -127,7 +128,7 @@ def env(**kwargs):
return env


class raw_env(RLCardBase):
class raw_env(RLCardBase, EzPickle):
metadata = {
"render_modes": ["human", "rgb_array"],
"name": "texas_holdem_no_limit_v6",
Expand All @@ -136,6 +137,7 @@ class raw_env(RLCardBase):
}

def __init__(self, num_players=2, render_mode=None):
EzPickle.__init__(self, num_players, render_mode)
super().__init__("no-limit-holdem", num_players, (54,))
self.observation_spaces = self._convert_to_dict(
[
Expand Down
4 changes: 3 additions & 1 deletion pettingzoo/classic/rps/rps.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
import numpy as np
import pygame
from gymnasium.spaces import Discrete
from gymnasium.utils import EzPickle

from pettingzoo import AECEnv
from pettingzoo.utils import agent_selector, wrappers
Expand Down Expand Up @@ -153,7 +154,7 @@ def env(**kwargs):
parallel_env = parallel_wrapper_fn(env)


class raw_env(AECEnv):
class raw_env(AECEnv, EzPickle):
"""Two-player environment for rock paper scissors.

Expandable environment to rock paper scissors lizard spock action_6 action_7 ...
Expand All @@ -168,6 +169,7 @@ class raw_env(AECEnv):
}

def __init__(self, num_actions=3, max_cycles=15, render_mode=None):
EzPickle.__init__(self, num_actions, max_cycles, render_mode)
self.max_cycles = max_cycles

# number of actions must be odd and greater than 3
Expand Down
4 changes: 3 additions & 1 deletion pettingzoo/classic/tictactoe/tictactoe.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
import gymnasium
import numpy as np
from gymnasium import spaces
from gymnasium.utils import EzPickle

from pettingzoo import AECEnv
from pettingzoo.utils import agent_selector, wrappers
Expand All @@ -90,7 +91,7 @@ def env(render_mode=None):
return env


class raw_env(AECEnv):
class raw_env(AECEnv, EzPickle):
metadata = {
"render_modes": ["human"],
"name": "tictactoe_v3",
Expand All @@ -99,6 +100,7 @@ class raw_env(AECEnv):
}

def __init__(self, render_mode=None):
EzPickle.__init__(self, render_mode)
super().__init__()
self.board = Board()

Expand Down
4 changes: 3 additions & 1 deletion pettingzoo/mpe/simple/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"""

import numpy as np
from gymnasium.utils import EzPickle

from pettingzoo.utils.conversions import parallel_wrapper_fn

Expand All @@ -51,8 +52,9 @@
from .._mpe_utils.simple_env import SimpleEnv, make_env


class raw_env(SimpleEnv):
class raw_env(SimpleEnv, EzPickle):
def __init__(self, max_cycles=25, continuous_actions=False, render_mode=None):
EzPickle.__init__(self, max_cycles, continuous_actions, render_mode)
scenario = Scenario()
world = scenario.make_world()
super().__init__(
Expand Down
5 changes: 4 additions & 1 deletion pettingzoo/sisl/waterworld/waterworld.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@

"""

from gymnasium.utils import EzPickle

from pettingzoo import AECEnv
from pettingzoo.utils import agent_selector, wrappers
from pettingzoo.utils.conversions import parallel_wrapper_fn
Expand All @@ -154,7 +156,7 @@ def env(**kwargs):
parallel_env = parallel_wrapper_fn(env)


class raw_env(AECEnv):
class raw_env(AECEnv, EzPickle):
metadata = {
"render_modes": ["human", "rgb_array"],
"name": "waterworld_v4",
Expand All @@ -163,6 +165,7 @@ class raw_env(AECEnv):
}

def __init__(self, *args, **kwargs):
EzPickle.__init__(self, *args, **kwargs)
super().__init__()
self.env = _env(*args, **kwargs)

Expand Down