Skip to content

Commit f6489c3

Browse files
Updated gymnasium to be equivalent to gym v26.2 (#36)
1 parent dc60cdc commit f6489c3

21 files changed

+190
-13
lines changed

Diff for: .github/workflows/build.yml

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
name: build
22
on: [pull_request, push]
33

4+
permissions:
5+
contents: read # to fetch code (actions/checkout)
6+
47
jobs:
58
build:
69
runs-on: ubuntu-latest

Diff for: .github/workflows/pre-commit.yml

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ on:
55
pull_request:
66
push:
77
branches: [master]
8+
9+
permissions:
10+
contents: read # to fetch code (actions/checkout)
11+
812
jobs:
913
pre-commit:
1014
runs-on: ubuntu-latest

Diff for: gymnasium/envs/box2d/bipedal_walker.py

+8
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,14 @@ def step(self, action: np.ndarray):
608608
return np.array(state, dtype=np.float32), reward, terminated, False, {}
609609

610610
def render(self):
611+
if self.render_mode is None:
612+
gym.logger.warn(
613+
"You are calling render method without specifying any render mode. "
614+
"You can specify the render_mode at initialization, "
615+
f'e.g. gym("{self.spec.id}", render_mode="rgb_array")'
616+
)
617+
return
618+
611619
try:
612620
import pygame
613621
from pygame import gfxdraw

Diff for: gymnasium/envs/box2d/car_racing.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,15 @@ def step(self, action: Union[np.ndarray, int]):
569569
return self.state, step_reward, terminated, truncated, {}
570570

571571
def render(self):
572-
return self._render(self.render_mode)
572+
if self.render_mode is None:
573+
gym.logger.warn(
574+
"You are calling render method without specifying any render mode. "
575+
"You can specify the render_mode at initialization, "
576+
f'e.g. gym("{self.spec.id}", render_mode="rgb_array")'
577+
)
578+
return
579+
else:
580+
return self._render(self.render_mode)
573581

574582
def _render(self, mode: str):
575583
assert mode in self.metadata["render_modes"]

Diff for: gymnasium/envs/box2d/lunar_lander.py

+8
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,14 @@ def step(self, action):
602602
return np.array(state, dtype=np.float32), reward, terminated, False, {}
603603

604604
def render(self):
605+
if self.render_mode is None:
606+
gym.logger.warn(
607+
"You are calling render method without specifying any render mode. "
608+
"You can specify the render_mode at initialization, "
609+
f'e.g. gym("{self.spec.id}", render_mode="rgb_array")'
610+
)
611+
return
612+
605613
try:
606614
import pygame
607615
from pygame import gfxdraw

Diff for: gymnasium/envs/classic_control/acrobot.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
import numpy as np
55
from numpy import cos, pi, sin
66

7+
import gymnasium as gym
78
from gymnasium import Env, spaces
9+
from gymnasium.envs.classic_control import utils
810
from gymnasium.error import DependencyNotInstalled
911

1012
__copyright__ = "Copyright 2013, RLPy http://acl.mit.edu/RLPy"
@@ -20,7 +22,6 @@
2022

2123
# SOURCE:
2224
# https://github.com/rlpy/rlpy/blob/master/rlpy/Domains/Acrobot.py
23-
from gymnasium.envs.classic_control import utils
2425

2526

2627
class AcrobotEnv(Env):
@@ -280,6 +281,14 @@ def _dsdt(self, s_augmented):
280281
return dtheta1, dtheta2, ddtheta1, ddtheta2, 0.0
281282

282283
def render(self):
284+
if self.render_mode is None:
285+
gym.logger.warn(
286+
"You are calling render method without specifying any render mode. "
287+
"You can specify the render_mode at initialization, "
288+
f'e.g. gym("{self.spec.id}", render_mode="rgb_array")'
289+
)
290+
return
291+
283292
try:
284293
import pygame
285294
from pygame import gfxdraw

Diff for: gymnasium/envs/classic_control/cartpole.py

+8
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,14 @@ def reset(
209209
return np.array(self.state, dtype=np.float32), {}
210210

211211
def render(self):
212+
if self.render_mode is None:
213+
gym.logger.warn(
214+
"You are calling render method without specifying any render mode. "
215+
"You can specify the render_mode at initialization, "
216+
f'e.g. gym("{self.spec.id}", render_mode="rgb_array")'
217+
)
218+
return
219+
212220
try:
213221
import pygame
214222
from pygame import gfxdraw

Diff for: gymnasium/envs/classic_control/continuous_mountain_car.py

+8
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,14 @@ def _height(self, xs):
193193
return np.sin(3 * xs) * 0.45 + 0.55
194194

195195
def render(self):
196+
if self.render_mode is None:
197+
gym.logger.warn(
198+
"You are calling render method without specifying any render mode. "
199+
"You can specify the render_mode at initialization, "
200+
f'e.g. gym("{self.spec.id}", render_mode="rgb_array")'
201+
)
202+
return
203+
196204
try:
197205
import pygame
198206
from pygame import gfxdraw

Diff for: gymnasium/envs/classic_control/mountain_car.py

+8
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,14 @@ def _height(self, xs):
170170
return np.sin(3 * xs) * 0.45 + 0.55
171171

172172
def render(self):
173+
if self.render_mode is None:
174+
gym.logger.warn(
175+
"You are calling render method without specifying any render mode. "
176+
"You can specify the render_mode at initialization, "
177+
f'e.g. gym("{self.spec.id}", render_mode="rgb_array")'
178+
)
179+
return
180+
173181
try:
174182
import pygame
175183
from pygame import gfxdraw

Diff for: gymnasium/envs/classic_control/pendulum.py

+8
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,14 @@ def _get_obs(self):
167167
return np.array([np.cos(theta), np.sin(theta), thetadot], dtype=np.float32)
168168

169169
def render(self):
170+
if self.render_mode is None:
171+
gym.logger.warn(
172+
"You are calling render method without specifying any render mode. "
173+
"You can specify the render_mode at initialization, "
174+
f'e.g. gym("{self.spec.id}", render_mode="rgb_array")'
175+
)
176+
return
177+
170178
try:
171179
import pygame
172180
from pygame import gfxdraw

Diff for: gymnasium/envs/toy_text/blackjack.py

+8
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,14 @@ def reset(
191191
return self._get_obs(), {}
192192

193193
def render(self):
194+
if self.render_mode is None:
195+
gym.logger.warn(
196+
"You are calling render method without specifying any render mode. "
197+
"You can specify the render_mode at initialization, "
198+
f'e.g. gym("{self.spec.id}", render_mode="rgb_array")'
199+
)
200+
return
201+
194202
try:
195203
import pygame
196204
except ImportError:

Diff for: gymnasium/envs/toy_text/cliffwalking.py

+9
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import numpy as np
77

8+
import gymnasium as gym
89
from gymnasium import Env, spaces
910
from gymnasium.envs.toy_text.utils import categorical_sample
1011
from gymnasium.error import DependencyNotInstalled
@@ -163,6 +164,14 @@ def reset(self, *, seed: Optional[int] = None, options: Optional[dict] = None):
163164
return int(self.s), {"prob": 1}
164165

165166
def render(self):
167+
if self.render_mode is None:
168+
gym.logger.warn(
169+
"You are calling render method without specifying any render mode. "
170+
"You can specify the render_mode at initialization, "
171+
f'e.g. gym("{self.spec.id}", render_mode="rgb_array")'
172+
)
173+
return
174+
166175
if self.render_mode == "ansi":
167176
return self._render_text()
168177
else:

Diff for: gymnasium/envs/toy_text/frozen_lake.py

+9
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import numpy as np
77

8+
import gymnasium as gym
89
from gymnasium import Env, spaces, utils
910
from gymnasium.envs.toy_text.utils import categorical_sample
1011
from gymnasium.error import DependencyNotInstalled
@@ -268,6 +269,14 @@ def reset(
268269
return int(self.s), {"prob": 1}
269270

270271
def render(self):
272+
if self.render_mode is None:
273+
gym.logger.warn(
274+
"You are calling render method without specifying any render mode. "
275+
"You can specify the render_mode at initialization, "
276+
f'e.g. gym("{self.spec.id}", render_mode="rgb_array")'
277+
)
278+
return
279+
271280
if self.render_mode == "ansi":
272281
return self._render_text()
273282
else: # self.render_mode in {"human", "rgb_array"}:

Diff for: gymnasium/envs/toy_text/taxi.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import numpy as np
77

8+
import gymnasium as gym
89
from gymnasium import Env, spaces, utils
910
from gymnasium.envs.toy_text.utils import categorical_sample
1011
from gymnasium.error import DependencyNotInstalled
@@ -279,7 +280,14 @@ def reset(
279280
return int(self.s), {"prob": 1.0, "action_mask": self.action_mask(self.s)}
280281

281282
def render(self):
282-
if self.render_mode == "ansi":
283+
if self.render_mode is None:
284+
gym.logger.warn(
285+
"You are calling render method without specifying any render mode. "
286+
"You can specify the render_mode at initialization, "
287+
f'e.g. gym("{self.spec.id}", render_mode="rgb_array")'
288+
)
289+
return
290+
elif self.render_mode == "ansi":
283291
return self._render_text()
284292
else: # self.render_mode in {"human", "rgb_array"}:
285293
return self._render_gui(self.render_mode)

Diff for: gymnasium/spaces/graph.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ class GraphInstance(NamedTuple):
1414
"""A Graph space instance.
1515
1616
* nodes (np.ndarray): an (n x ...) sized array representing the features for n nodes, (...) must adhere to the shape of the node space.
17-
* edges (Optional[np.ndarray]): an (m x ...) sized array representing the features for m nodes, (...) must adhere to the shape of the edge space.
18-
* edge_links (Optional[np.ndarray]): an (m x 2) sized array of ints representing the two nodes that each edge connects.
17+
* edges (Optional[np.ndarray]): an (m x ...) sized array representing the features for m edges, (...) must adhere to the shape of the edge space.
18+
* edge_links (Optional[np.ndarray]): an (m x 2) sized array of ints representing the indices of the two nodes that each edge connects.
1919
"""
2020

2121
nodes: np.ndarray

Diff for: gymnasium/vector/async_vector_env.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -566,9 +566,10 @@ def _worker(index, env_fn, pipe, parent_pipe, shared_memory, error_queue):
566566
info,
567567
) = env.step(data)
568568
if terminated or truncated:
569-
old_observation = observation
569+
old_observation, old_info = observation, info
570570
observation, info = env.reset()
571571
info["final_observation"] = old_observation
572+
info["final_info"] = old_info
572573
pipe.send(((observation, reward, terminated, truncated, info), True))
573574
elif command == "seed":
574575
env.seed(data)
@@ -636,10 +637,10 @@ def _worker_shared_memory(index, env_fn, pipe, parent_pipe, shared_memory, error
636637
info,
637638
) = env.step(data)
638639
if terminated or truncated:
639-
old_observation = observation
640+
old_observation, old_info = observation, info
640641
observation, info = env.reset()
641642
info["final_observation"] = old_observation
642-
643+
info["final_info"] = old_info
643644
write_to_shared_memory(
644645
observation_space, index, observation, shared_memory
645646
)

Diff for: gymnasium/vector/sync_vector_env.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,10 @@ def step_wait(self):
150150
) = env.step(action)
151151

152152
if self._terminateds[i] or self._truncateds[i]:
153-
old_observation = observation
153+
old_observation, old_info = observation, info
154154
observation, info = env.reset()
155155
info["final_observation"] = old_observation
156+
info["final_info"] = old_info
156157
observations.append(observation)
157158
infos = self._add_info(infos, info, i)
158159
self.observations = concatenate(

Diff for: gymnasium/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VERSION = "0.26.1"
1+
VERSION = "0.26.2"

Diff for: gymnasium/wrappers/atari_preprocessing.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ def __init__(
9898
np.empty(env.observation_space.shape, dtype=np.uint8),
9999
]
100100

101-
self.ale = env.unwrapped.ale
102101
self.lives = 0
103102
self.game_over = False
104103

@@ -112,6 +111,11 @@ def __init__(
112111
low=_low, high=_high, shape=_shape, dtype=_obs_dtype
113112
)
114113

114+
@property
115+
def ale(self):
116+
"""Make ale as a class property to avoid serialization error."""
117+
return self.env.unwrapped.ale
118+
115119
def step(self, action):
116120
"""Applies the preprocessing for an :meth:`env.step`."""
117121
total_reward, terminated, truncated, info = 0.0, False, False, {}

Diff for: setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"box2d": ["box2d-py==2.3.5", "pygame==2.1.0", "swig==4.*"],
1919
"classic_control": ["pygame==2.1.0"],
2020
"mujoco_py": ["mujoco_py<2.2,>=2.1"],
21-
"mujoco": ["mujoco==2.2.0", "imageio>=2.14.1"],
21+
"mujoco": ["mujoco==2.2", "imageio>=2.14.1"],
2222
"toy_text": ["pygame==2.1.0"],
2323
"other": ["lz4>=3.1.0", "opencv-python>=3.0", "matplotlib>=3.0", "moviepy>=1.0.0"],
2424
}

0 commit comments

Comments
 (0)