Skip to content

Commit 0dba116

Browse files
authored
Upgraded Gymnasium to 1.0.0 and NumPy to 2.0.0+ (#453)
1 parent a6cfc0e commit 0dba116

File tree

14 files changed

+98
-97
lines changed

14 files changed

+98
-97
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ jobs:
1717
--build-arg PYTHON_VERSION=${{ matrix.python-version }} \
1818
--tag minigrid-docker .
1919
- name: Run tests
20-
run: docker run minigrid-docker pytest
20+
run: docker run minigrid-docker pytest --ignore tests/test_wfc
2121
- name: Run doctest
2222
run: docker run minigrid-docker pytest --doctest-modules minigrid/

.github/workflows/pre-commit.yml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
# https://pre-commit.com
22
# This GitHub Action assumes that the repo contains a valid .pre-commit-config.yaml file.
3-
name: pre-commit
4-
on: [pull_request, push]
3+
name: Run pre-commit
4+
on:
5+
pull_request:
6+
push:
7+
branches: [master]
58

69
permissions:
7-
contents: read
10+
contents: read # to fetch code (actions/checkout)
811

912
jobs:
1013
pre-commit:
1114
runs-on: ubuntu-latest
1215
steps:
13-
- uses: actions/checkout@v2
14-
- uses: actions/setup-python@v2
16+
- uses: actions/checkout@v4
17+
- uses: actions/setup-python@v5
1518
- run: pip install pre-commit
1619
- run: pre-commit --version
17-
- run: pre-commit install
1820
- run: pre-commit run --all-files

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,6 @@ repos:
4848
language: node
4949
pass_filenames: false
5050
types: [python]
51-
additional_dependencies: ["pyright"]
51+
additional_dependencies: ["pyright@1.1.383"]
5252
args:
5353
- --project=pyproject.toml

minigrid/__init__.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,7 @@
77
from minigrid.core.world_object import Wall
88
from minigrid.envs.wfc.config import WFC_PRESETS, register_wfc_presets
99

10-
__version__ = "2.3.1"
11-
12-
13-
try:
14-
import sys
15-
16-
from farama_notifications import notifications
17-
18-
if "minigrid" in notifications and __version__ in notifications["minigrid"]:
19-
print(notifications["minigrid"][__version__], file=sys.stderr)
20-
except Exception: # nosec
21-
pass
10+
__version__ = "3.0.0"
2211

2312

2413
def register_minigrid_envs():
@@ -1133,3 +1122,16 @@ def register_minigrid_envs():
11331122
id="BabyAI-BossLevelNoUnlock-v0",
11341123
entry_point="minigrid.envs.babyai:BossLevelNoUnlock",
11351124
)
1125+
1126+
1127+
register_minigrid_envs()
1128+
1129+
try:
1130+
import sys
1131+
1132+
from farama_notifications import notifications
1133+
1134+
if "minigrid" in notifications and __version__ in notifications["minigrid"]:
1135+
print(notifications["minigrid"][__version__], file=sys.stderr)
1136+
except Exception: # nosec
1137+
pass

minigrid/envs/babyai/core/verifier.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ def find_matching_objs(self, env, use_location=True):
109109
the location of the object. e.g. A ball that was on "your right" initially will still be tracked as being "on
110110
your right" when you move.
111111
"""
112+
env = env.unwrapped
112113

113114
if use_location:
114115
self.obj_set = []

minigrid/envs/crossing.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ def __init__(
9393
):
9494
self.num_crossings = num_crossings
9595
self.obstacle_type = obstacle_type
96+
self.goal_position = None
9697

9798
if obstacle_type == Lava:
9899
mission_space = MissionSpace(mission_func=self._gen_mission_lava)
@@ -133,6 +134,7 @@ def _gen_grid(self, width, height):
133134

134135
# Place a goal square in the bottom-right corner
135136
self.put_obj(Goal(), width - 2, height - 2)
137+
self.goal_position = (width - 2, height - 2)
136138

137139
# Place obstacles (lava or walls)
138140
v, h = object(), object() # singleton `vertical` and `horizontal` objects

minigrid/manual_control.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def start(self):
3636

3737
def step(self, action: Actions):
3838
_, reward, terminated, truncated, _ = self.env.step(action)
39-
print(f"step={self.env.step_count}, reward={reward:.2f}")
39+
print(f"step={self.env.unwrapped.step_count}, reward={reward:.2f}")
4040

4141
if terminated:
4242
print("terminated!")

minigrid/wrappers.py

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,20 @@ class ReseedWrapper(Wrapper):
2424
>>> from minigrid.wrappers import ReseedWrapper
2525
>>> env = gym.make("MiniGrid-Empty-5x5-v0")
2626
>>> _ = env.reset(seed=123)
27-
>>> [env.np_random.integers(10) for i in range(10)]
27+
>>> [env.np_random.integers(10).item() for i in range(10)]
2828
[0, 6, 5, 0, 9, 2, 2, 1, 3, 1]
2929
>>> env = ReseedWrapper(env, seeds=[0, 1], seed_idx=0)
3030
>>> _, _ = env.reset()
31-
>>> [env.np_random.integers(10) for i in range(10)]
31+
>>> [env.np_random.integers(10).item() for i in range(10)]
3232
[8, 6, 5, 2, 3, 0, 0, 0, 1, 8]
3333
>>> _, _ = env.reset()
34-
>>> [env.np_random.integers(10) for i in range(10)]
34+
>>> [env.np_random.integers(10).item() for i in range(10)]
3535
[4, 5, 7, 9, 0, 1, 8, 9, 2, 3]
3636
>>> _, _ = env.reset()
37-
>>> [env.np_random.integers(10) for i in range(10)]
37+
>>> [env.np_random.integers(10).item() for i in range(10)]
3838
[8, 6, 5, 2, 3, 0, 0, 0, 1, 8]
3939
>>> _, _ = env.reset()
40-
>>> [env.np_random.integers(10) for i in range(10)]
40+
>>> [env.np_random.integers(10).item() for i in range(10)]
4141
[4, 5, 7, 9, 0, 1, 8, 9, 2, 3]
4242
"""
4343

@@ -325,7 +325,7 @@ def __init__(self, env, tile_size=8):
325325
)
326326

327327
def observation(self, obs):
328-
rgb_img = self.get_frame(
328+
rgb_img = self.unwrapped.get_frame(
329329
highlight=self.unwrapped.highlight, tile_size=self.tile_size
330330
)
331331

@@ -374,7 +374,9 @@ def __init__(self, env, tile_size=8):
374374
)
375375

376376
def observation(self, obs):
377-
rgb_img_partial = self.get_frame(tile_size=self.tile_size, agent_pov=True)
377+
rgb_img_partial = self.unwrapped.get_frame(
378+
tile_size=self.tile_size, agent_pov=True
379+
)
378380

379381
return {**obs, "image": rgb_img_partial}
380382

@@ -403,7 +405,11 @@ def __init__(self, env):
403405
new_image_space = spaces.Box(
404406
low=0,
405407
high=255,
406-
shape=(self.env.width, self.env.height, 3), # number of cells
408+
shape=(
409+
self.env.unwrapped.width,
410+
self.env.unwrapped.height,
411+
3,
412+
), # number of cells
407413
dtype="uint8",
408414
)
409415

@@ -680,7 +686,7 @@ class DirectionObsWrapper(ObservationWrapper):
680686
>>> env = gym.make("MiniGrid-LavaCrossingS11N5-v0")
681687
>>> env_obs = DirectionObsWrapper(env, type="slope")
682688
>>> obs, _ = env_obs.reset()
683-
>>> obs['goal_direction']
689+
>>> obs['goal_direction'].item()
684690
1.0
685691
"""
686692

@@ -696,21 +702,21 @@ def reset(
696702

697703
if not self.goal_position:
698704
self.goal_position = [
699-
x for x, y in enumerate(self.grid.grid) if isinstance(y, Goal)
705+
x for x, y in enumerate(self.unwrapped.grid.grid) if isinstance(y, Goal)
700706
]
701707
# in case there are multiple goals , needs to be handled for other env types
702708
if len(self.goal_position) >= 1:
703709
self.goal_position = (
704-
int(self.goal_position[0] / self.height),
705-
self.goal_position[0] % self.width,
710+
int(self.goal_position[0] / self.unwrapped.height),
711+
self.goal_position[0] % self.unwrapped.width,
706712
)
707713

708714
return self.observation(obs), info
709715

710716
def observation(self, obs):
711717
slope = np.divide(
712-
self.goal_position[1] - self.agent_pos[1],
713-
self.goal_position[0] - self.agent_pos[0],
718+
self.goal_position[1] - self.unwrapped.agent_pos[1],
719+
self.goal_position[0] - self.unwrapped.agent_pos[0],
714720
)
715721

716722
if self.type == "angle":
@@ -746,7 +752,11 @@ def __init__(self, env):
746752
new_image_space = spaces.Box(
747753
low=0,
748754
high=max(OBJECT_TO_IDX.values()),
749-
shape=(self.env.width, self.env.height, 3), # number of cells
755+
shape=(
756+
self.env.unwrapped.width,
757+
self.env.unwrapped.height,
758+
3,
759+
), # number of cells
750760
dtype="uint8",
751761
)
752762
self.observation_space = spaces.Dict(
@@ -755,10 +765,13 @@ def __init__(self, env):
755765

756766
def observation(self, obs):
757767
objects = np.array(
758-
[OBJECT_TO_IDX[o.type] if o is not None else -1 for o in self.grid.grid]
768+
[
769+
OBJECT_TO_IDX[o.type] if o is not None else -1
770+
for o in self.unwrapped.grid.grid
771+
]
759772
)
760-
agent_pos = self.env.agent_pos
761-
ncol, nrow = self.width, self.height
773+
agent_pos = self.env.unwrapped.agent_pos
774+
ncol, nrow = self.unwrapped.width, self.unwrapped.height
762775
grid = np.mgrid[:ncol, :nrow]
763776
_objects = np.transpose(objects.reshape(1, nrow, ncol), (0, 2, 1))
764777

@@ -849,9 +862,9 @@ def __init__(self, env, no_death_types: tuple[str, ...], death_cost: float = -1.
849862
def step(self, action):
850863
# In Dynamic-Obstacles, obstacles move after the agent moves,
851864
# so we need to check for collision before self.env.step()
852-
front_cell = self.grid.get(*self.front_pos)
865+
front_cell = self.unwrapped.grid.get(*self.unwrapped.front_pos)
853866
going_to_death = (
854-
action == self.actions.forward
867+
action == self.unwrapped.actions.forward
855868
and front_cell is not None
856869
and front_cell.type in self.no_death_types
857870
)
@@ -860,7 +873,7 @@ def step(self, action):
860873

861874
# We also check if the agent stays in death cells (e.g., lava)
862875
# without moving
863-
current_cell = self.grid.get(*self.agent_pos)
876+
current_cell = self.unwrapped.grid.get(*self.unwrapped.agent_pos)
864877
in_death = current_cell is not None and current_cell.type in self.no_death_types
865878

866879
if terminated and (going_to_death or in_death):

pyproject.toml

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ authors = [{ name = "Farama Foundation", email = "[email protected]" }]
1313
license = { text = "MIT License" }
1414
keywords = ["Memory, Environment, Agent, RL, Gymnasium"]
1515
classifiers = [
16-
"Development Status :: 4 - Beta", # change to `5 - Production/Stable` when ready
16+
"Development Status :: 4 - Beta", # change to `5 - Production/Stable` when ready
1717
"License :: OSI Approved :: MIT License",
1818
"Programming Language :: Python :: 3",
1919
"Programming Language :: Python :: 3.7",
@@ -24,33 +24,19 @@ classifiers = [
2424
'Intended Audience :: Science/Research',
2525
'Topic :: Scientific/Engineering :: Artificial Intelligence',
2626
]
27-
dependencies = [
28-
"numpy>=1.18.0",
29-
"gymnasium>=0.28.1",
30-
"pygame>=2.4.0",
31-
]
27+
dependencies = ["numpy>=1.18.0", "gymnasium>=0.28.1", "pygame>=2.4.0"]
3228
dynamic = ["version"]
3329

3430
[project.optional-dependencies]
35-
testing = [
36-
"pytest>=7.0.1",
37-
"pytest-mock>=3.10.0",
38-
"matplotlib>=3.0"
39-
]
40-
wfc = [
41-
"networkx",
42-
"imageio>=2.31.1",
43-
]
31+
testing = ["pytest>=7.0.1", "pytest-mock>=3.10.0", "matplotlib>=3.0"]
32+
wfc = ["networkx", "imageio>=2.31.1"]
4433

4534
[project.urls]
4635
Homepage = "https://farama.org"
4736
Repository = "https://minigrid.farama.org/"
4837
Documentation = "https://minigrid.farama.org/"
4938
"Bug Report" = "https://github.com/Farama-Foundation/Minigrid/issues"
5039

51-
[project.entry-points."gymnasium.envs"]
52-
__root__ = "minigrid.__init__:register_minigrid_envs"
53-
5440
[tool.setuptools]
5541
include-package-data = true
5642

@@ -60,24 +46,18 @@ include = ["minigrid*"]
6046
# Linters and Test tools #######################################################
6147

6248
[tool.black]
63-
safe = true
6449

6550
[tool.isort]
6651
atomic = true
6752
profile = "black"
6853
append_only = true
6954
src_paths = ["minigrid", "tests"]
70-
add_imports = [ "from __future__ import annotations" ]
55+
add_imports = ["from __future__ import annotations"]
7156

7257
[tool.pyright]
73-
include = [
74-
"minigrid/**",
75-
]
58+
include = ["minigrid/**"]
7659

77-
exclude = [
78-
"**/node_modules",
79-
"**/__pycache__",
80-
]
60+
exclude = ["**/node_modules", "**/__pycache__"]
8161

8262
strict = []
8363

@@ -98,8 +78,10 @@ reportPrivateUsage = "warning"
9878
reportUntypedFunctionDecorator = "none"
9979
reportMissingTypeStubs = false
10080
reportUnboundVariable = "warning"
101-
reportGeneralTypeIssues ="none"
81+
reportGeneralTypeIssues = "none"
10282
reportPrivateImportUsage = "none"
10383

10484
[tool.pytest.ini_options]
105-
filterwarnings = ['ignore:.*step API.*:DeprecationWarning'] # TODO: to be removed when old step API is removed
85+
filterwarnings = [
86+
'ignore:.*step API.*:DeprecationWarning',
87+
] # TODO: to be removed when old step API is removed

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
numpy>=1.18.0
2-
gymnasium>=0.26
1+
numpy>=2.0.0
2+
gymnasium>=1.0.0
33
pygame>=2.2.0

0 commit comments

Comments
 (0)