From c582fc4d6748959ded1ecaf4085045daf852aaa7 Mon Sep 17 00:00:00 2001 From: Bolun <36321182+BolunDai0216@users.noreply.github.com> Date: Mon, 22 Jul 2024 07:52:15 -0400 Subject: [PATCH 01/11] updated citation to neurips23 version --- CITATION.cff | 9 ++++++--- README.md | 10 +++++----- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/CITATION.cff b/CITATION.cff index 7fdcfaab6..ed0763a75 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -45,7 +45,10 @@ preferred-citation: given-names: Pablo Samuel - family-names: Terry given-names: Jordan - journal: CoRR - title: Minigrid - volume: abs/2306.13831 + title: "Minigrid & Miniworld: Modular & Customizable Reinforcement Learning Environments for Goal-Oriented Tasks" + type: inproceedings year: 2023 + conference: + name: "Neural Information Processing Systems (NeurIPS)" + publisher: + name: "Proceedings of the Conference on Neural Information Processing Systems (NeurIPS)" diff --git a/README.md b/README.md index 677c1cf75..7fad2cddb 100644 --- a/README.md +++ b/README.md @@ -43,11 +43,11 @@ The original `gym-minigrid` environments were created as part of work done at [M To cite this project please use: ```bibtex -@article{MinigridMiniworld23, - author = {Maxime Chevalier-Boisvert and Bolun Dai and Mark Towers and Rodrigo de Lazcano and Lucas Willems and Salem Lahlou and Suman Pal and Pablo Samuel Castro and Jordan Terry}, - title = {Minigrid \& Miniworld: Modular \& Customizable Reinforcement Learning Environments for Goal-Oriented Tasks}, - journal = {CoRR}, - volume = {abs/2306.13831}, +@inproceedings{MinigridMiniworld23, + author = {Maxime Chevalier{-}Boisvert and Bolun Dai and Mark Towers and Rodrigo Perez{-}Vicente and Lucas Willems and Salem Lahlou and Suman Pal and Pablo Samuel Castro and Jordan Terry}, + title = {Minigrid {\&} Miniworld: Modular {\&} Customizable Reinforcement Learning Environments for Goal-Oriented Tasks}, + booktitle = {Advances in Neural Information Processing Systems 36, New Orleans, LA, USA}, + month = {December}, year = {2023}, } ``` From b9ec97f7a8fd89b5153a9f247042d6b61fb6a56f Mon Sep 17 00:00:00 2001 From: Bolun <36321182+BolunDai0216@users.noreply.github.com> Date: Mon, 22 Jul 2024 07:53:23 -0400 Subject: [PATCH 02/11] updated doc citation to neurips23 version --- docs/index.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/index.md b/docs/index.md index 6b2ea9b36..95a9e1a72 100644 --- a/docs/index.md +++ b/docs/index.md @@ -41,11 +41,11 @@ env.close() To cite this project please use: ```bibtex -@article{MinigridMiniworld23, - author = {Maxime Chevalier-Boisvert and Bolun Dai and Mark Towers and Rodrigo de Lazcano and Lucas Willems and Salem Lahlou and Suman Pal and Pablo Samuel Castro and Jordan Terry}, - title = {Minigrid \& Miniworld: Modular \& Customizable Reinforcement Learning Environments for Goal-Oriented Tasks}, - journal = {CoRR}, - volume = {abs/2306.13831}, +@inproceedings{MinigridMiniworld23, + author = {Maxime Chevalier{-}Boisvert and Bolun Dai and Mark Towers and Rodrigo Perez{-}Vicente and Lucas Willems and Salem Lahlou and Suman Pal and Pablo Samuel Castro and Jordan Terry}, + title = {Minigrid {\&} Miniworld: Modular {\&} Customizable Reinforcement Learning Environments for Goal-Oriented Tasks}, + booktitle = {Advances in Neural Information Processing Systems 36, New Orleans, LA, USA}, + month = {December}, year = {2023}, } ``` From d3deb45fb6309b50c874c596d2d07b4a5140613e Mon Sep 17 00:00:00 2001 From: Bolun <36321182+BolunDai0216@users.noreply.github.com> Date: Mon, 22 Jul 2024 07:59:30 -0400 Subject: [PATCH 03/11] reformatted code --- minigrid/core/world_object.py | 1 - minigrid/envs/babyai/core/levelgen.py | 1 + minigrid/envs/babyai/core/roomgrid_level.py | 1 + minigrid/envs/babyai/core/verifier.py | 1 + minigrid/envs/babyai/goto.py | 1 + minigrid/envs/babyai/open.py | 1 + minigrid/envs/babyai/other.py | 1 + minigrid/envs/babyai/pickup.py | 1 + minigrid/envs/babyai/putnext.py | 1 + minigrid/envs/babyai/unlock.py | 1 + minigrid/envs/blockedunlockpickup.py | 1 - minigrid/envs/crossing.py | 1 - minigrid/envs/distshift.py | 1 - minigrid/envs/doorkey.py | 1 - minigrid/envs/fetch.py | 1 - minigrid/envs/fourrooms.py | 1 - minigrid/envs/keycorridor.py | 1 - minigrid/envs/lavagap.py | 1 - minigrid/envs/lockedroom.py | 1 - minigrid/envs/memory.py | 1 - minigrid/envs/multiroom.py | 1 - minigrid/envs/obstructedmaze.py | 1 - minigrid/envs/putnear.py | 1 - minigrid/envs/redbluedoors.py | 1 - minigrid/envs/unlock.py | 1 - minigrid/envs/unlockpickup.py | 1 - minigrid/envs/wfc/wfclogic/adjacency.py | 1 + minigrid/envs/wfc/wfclogic/control.py | 1 + minigrid/envs/wfc/wfclogic/solver.py | 1 + minigrid/envs/wfc/wfclogic/tiles.py | 1 + minigrid/envs/wfc/wfclogic/utilities.py | 1 + minigrid/wrappers.py | 6 +++--- tests/test_wfc/test_wfc_adjacency.py | 1 + tests/test_wfc/test_wfc_tiles.py | 1 + tests/utils.py | 1 + 35 files changed, 20 insertions(+), 20 deletions(-) diff --git a/minigrid/core/world_object.py b/minigrid/core/world_object.py index de4e550b3..a1fe01911 100644 --- a/minigrid/core/world_object.py +++ b/minigrid/core/world_object.py @@ -25,7 +25,6 @@ class WorldObj: - """ Base class for grid world objects """ diff --git a/minigrid/envs/babyai/core/levelgen.py b/minigrid/envs/babyai/core/levelgen.py index f99c2e32c..fc30b9894 100644 --- a/minigrid/envs/babyai/core/levelgen.py +++ b/minigrid/envs/babyai/core/levelgen.py @@ -1,6 +1,7 @@ """ Copied and adapted from https://github.com/mila-iqia/babyai """ + from __future__ import annotations from minigrid.core.constants import COLOR_NAMES diff --git a/minigrid/envs/babyai/core/roomgrid_level.py b/minigrid/envs/babyai/core/roomgrid_level.py index 7de73c6d3..6a6c9c557 100644 --- a/minigrid/envs/babyai/core/roomgrid_level.py +++ b/minigrid/envs/babyai/core/roomgrid_level.py @@ -1,6 +1,7 @@ """ Copied and adapted from https://github.com/mila-iqia/babyai """ + from __future__ import annotations from minigrid.core.roomgrid import RoomGrid diff --git a/minigrid/envs/babyai/core/verifier.py b/minigrid/envs/babyai/core/verifier.py index 260ff949e..fac7c7e8f 100644 --- a/minigrid/envs/babyai/core/verifier.py +++ b/minigrid/envs/babyai/core/verifier.py @@ -1,6 +1,7 @@ """ Copied and adapted from https://github.com/mila-iqia/babyai """ + from __future__ import annotations import os diff --git a/minigrid/envs/babyai/goto.py b/minigrid/envs/babyai/goto.py index 4f5435a2e..2a94e3cac 100644 --- a/minigrid/envs/babyai/goto.py +++ b/minigrid/envs/babyai/goto.py @@ -2,6 +2,7 @@ Copied and adapted from https://github.com/mila-iqia/babyai. Levels described in the Baby AI ICLR 2019 submission, with the `Go to` instruction. """ + from __future__ import annotations from minigrid.envs.babyai.core.levelgen import LevelGen diff --git a/minigrid/envs/babyai/open.py b/minigrid/envs/babyai/open.py index 443295598..3c2a3ea73 100644 --- a/minigrid/envs/babyai/open.py +++ b/minigrid/envs/babyai/open.py @@ -2,6 +2,7 @@ Copied and adapted from https://github.com/mila-iqia/babyai. Levels described in the Baby AI ICLR 2019 submission, with the `Open` instruction. """ + from __future__ import annotations from minigrid.core.constants import COLOR_NAMES diff --git a/minigrid/envs/babyai/other.py b/minigrid/envs/babyai/other.py index 57e2c2430..c912f215a 100644 --- a/minigrid/envs/babyai/other.py +++ b/minigrid/envs/babyai/other.py @@ -2,6 +2,7 @@ Copied and adapted from https://github.com/mila-iqia/babyai. Levels described in the Baby AI ICLR 2019 submission, with different instructions than those in other files. """ + from __future__ import annotations from minigrid.envs.babyai.core.roomgrid_level import RoomGridLevel diff --git a/minigrid/envs/babyai/pickup.py b/minigrid/envs/babyai/pickup.py index 7a7c83935..3a1fe1b86 100644 --- a/minigrid/envs/babyai/pickup.py +++ b/minigrid/envs/babyai/pickup.py @@ -2,6 +2,7 @@ Copied and adapted from https://github.com/mila-iqia/babyai. Levels described in the Baby AI ICLR 2019 submission, with the `Pick up` instruction. """ + from __future__ import annotations from minigrid.envs.babyai.core.levelgen import LevelGen diff --git a/minigrid/envs/babyai/putnext.py b/minigrid/envs/babyai/putnext.py index 081d02f76..4b28a2c8f 100644 --- a/minigrid/envs/babyai/putnext.py +++ b/minigrid/envs/babyai/putnext.py @@ -2,6 +2,7 @@ Copied and adapted from https://github.com/mila-iqia/babyai. Levels described in the Baby AI ICLR 2019 submission, with the `Put Next` instruction. """ + from __future__ import annotations from minigrid.envs.babyai.core.roomgrid_level import RoomGridLevel diff --git a/minigrid/envs/babyai/unlock.py b/minigrid/envs/babyai/unlock.py index a2510f006..1848f09aa 100644 --- a/minigrid/envs/babyai/unlock.py +++ b/minigrid/envs/babyai/unlock.py @@ -2,6 +2,7 @@ Copied and adapted from https://github.com/mila-iqia/babyai. Levels described in the Baby AI ICLR 2019 submission, with the `Unlock` instruction. """ + from __future__ import annotations from minigrid.core.constants import COLOR_NAMES diff --git a/minigrid/envs/blockedunlockpickup.py b/minigrid/envs/blockedunlockpickup.py index eb401ac16..b4edd95df 100644 --- a/minigrid/envs/blockedunlockpickup.py +++ b/minigrid/envs/blockedunlockpickup.py @@ -7,7 +7,6 @@ class BlockedUnlockPickupEnv(RoomGrid): - """ ## Description diff --git a/minigrid/envs/crossing.py b/minigrid/envs/crossing.py index eeec21a1f..927a1955f 100644 --- a/minigrid/envs/crossing.py +++ b/minigrid/envs/crossing.py @@ -11,7 +11,6 @@ class CrossingEnv(MiniGridEnv): - """ ## Description diff --git a/minigrid/envs/distshift.py b/minigrid/envs/distshift.py index f4269b54e..1fd2568da 100644 --- a/minigrid/envs/distshift.py +++ b/minigrid/envs/distshift.py @@ -7,7 +7,6 @@ class DistShiftEnv(MiniGridEnv): - """ ## Description diff --git a/minigrid/envs/doorkey.py b/minigrid/envs/doorkey.py index 43c07f840..df5b29ef0 100644 --- a/minigrid/envs/doorkey.py +++ b/minigrid/envs/doorkey.py @@ -7,7 +7,6 @@ class DoorKeyEnv(MiniGridEnv): - """ ## Description diff --git a/minigrid/envs/fetch.py b/minigrid/envs/fetch.py index 6d2a3635e..485019941 100644 --- a/minigrid/envs/fetch.py +++ b/minigrid/envs/fetch.py @@ -8,7 +8,6 @@ class FetchEnv(MiniGridEnv): - """ ## Description diff --git a/minigrid/envs/fourrooms.py b/minigrid/envs/fourrooms.py index 71c25f641..d79f007e0 100644 --- a/minigrid/envs/fourrooms.py +++ b/minigrid/envs/fourrooms.py @@ -7,7 +7,6 @@ class FourRoomsEnv(MiniGridEnv): - """ ## Description diff --git a/minigrid/envs/keycorridor.py b/minigrid/envs/keycorridor.py index fdb84367d..3a5dbaef5 100644 --- a/minigrid/envs/keycorridor.py +++ b/minigrid/envs/keycorridor.py @@ -6,7 +6,6 @@ class KeyCorridorEnv(RoomGrid): - """ ## Description diff --git a/minigrid/envs/lavagap.py b/minigrid/envs/lavagap.py index dd6cc72f7..8ca33ca86 100644 --- a/minigrid/envs/lavagap.py +++ b/minigrid/envs/lavagap.py @@ -9,7 +9,6 @@ class LavaGapEnv(MiniGridEnv): - """ ## Description diff --git a/minigrid/envs/lockedroom.py b/minigrid/envs/lockedroom.py index a4c670f0d..9baf3dca2 100644 --- a/minigrid/envs/lockedroom.py +++ b/minigrid/envs/lockedroom.py @@ -22,7 +22,6 @@ def rand_pos(self, env): class LockedRoomEnv(MiniGridEnv): - """ ## Description diff --git a/minigrid/envs/memory.py b/minigrid/envs/memory.py index 8fd24b3c1..660b0a1b7 100644 --- a/minigrid/envs/memory.py +++ b/minigrid/envs/memory.py @@ -10,7 +10,6 @@ class MemoryEnv(MiniGridEnv): - """ ## Description diff --git a/minigrid/envs/multiroom.py b/minigrid/envs/multiroom.py index ff4f26a3d..b998a492e 100644 --- a/minigrid/envs/multiroom.py +++ b/minigrid/envs/multiroom.py @@ -16,7 +16,6 @@ def __init__(self, top, size, entryDoorPos, exitDoorPos): class MultiRoomEnv(MiniGridEnv): - """ ## Description diff --git a/minigrid/envs/obstructedmaze.py b/minigrid/envs/obstructedmaze.py index b8f7b7cc3..8280d5505 100644 --- a/minigrid/envs/obstructedmaze.py +++ b/minigrid/envs/obstructedmaze.py @@ -7,7 +7,6 @@ class ObstructedMazeEnv(RoomGrid): - """ ## Description diff --git a/minigrid/envs/putnear.py b/minigrid/envs/putnear.py index 49ca92596..667ac49aa 100644 --- a/minigrid/envs/putnear.py +++ b/minigrid/envs/putnear.py @@ -8,7 +8,6 @@ class PutNearEnv(MiniGridEnv): - """ ## Description diff --git a/minigrid/envs/redbluedoors.py b/minigrid/envs/redbluedoors.py index 26433792e..8a846cef3 100644 --- a/minigrid/envs/redbluedoors.py +++ b/minigrid/envs/redbluedoors.py @@ -7,7 +7,6 @@ class RedBlueDoorEnv(MiniGridEnv): - """ ## Description diff --git a/minigrid/envs/unlock.py b/minigrid/envs/unlock.py index 5dd6a5fd5..974acd6f5 100644 --- a/minigrid/envs/unlock.py +++ b/minigrid/envs/unlock.py @@ -5,7 +5,6 @@ class UnlockEnv(RoomGrid): - """ ## Description diff --git a/minigrid/envs/unlockpickup.py b/minigrid/envs/unlockpickup.py index 45a653f41..82e75ec53 100644 --- a/minigrid/envs/unlockpickup.py +++ b/minigrid/envs/unlockpickup.py @@ -6,7 +6,6 @@ class UnlockPickupEnv(RoomGrid): - """ ## Description diff --git a/minigrid/envs/wfc/wfclogic/adjacency.py b/minigrid/envs/wfc/wfclogic/adjacency.py index 0923a79bd..aa7b4a05f 100644 --- a/minigrid/envs/wfc/wfclogic/adjacency.py +++ b/minigrid/envs/wfc/wfclogic/adjacency.py @@ -1,4 +1,5 @@ """Convert input data to adjacency information. Implementation based on https://github.com/ikarth/wfc_2019f""" + from __future__ import annotations import numpy as np diff --git a/minigrid/envs/wfc/wfclogic/control.py b/minigrid/envs/wfc/wfclogic/control.py index 0d1969506..fbb2c6a5b 100644 --- a/minigrid/envs/wfc/wfclogic/control.py +++ b/minigrid/envs/wfc/wfclogic/control.py @@ -1,4 +1,5 @@ """Main WFC execution function. Implementation based on https://github.com/ikarth/wfc_2019f""" + from __future__ import annotations import logging diff --git a/minigrid/envs/wfc/wfclogic/solver.py b/minigrid/envs/wfc/wfclogic/solver.py index a4cadad9f..701503e49 100644 --- a/minigrid/envs/wfc/wfclogic/solver.py +++ b/minigrid/envs/wfc/wfclogic/solver.py @@ -1,4 +1,5 @@ """Wave Function Collapse solver. Implementation based on https://github.com/ikarth/wfc_2019f""" + from __future__ import annotations import itertools diff --git a/minigrid/envs/wfc/wfclogic/tiles.py b/minigrid/envs/wfc/wfclogic/tiles.py index a4ffcdf2e..87a7e0a0b 100644 --- a/minigrid/envs/wfc/wfclogic/tiles.py +++ b/minigrid/envs/wfc/wfclogic/tiles.py @@ -1,4 +1,5 @@ """Breaks an image into consituant tiles. Implementation based on https://github.com/ikarth/wfc_2019f""" + from __future__ import annotations import numpy as np diff --git a/minigrid/envs/wfc/wfclogic/utilities.py b/minigrid/envs/wfc/wfclogic/utilities.py index 8c9e6e997..c90fd4de1 100644 --- a/minigrid/envs/wfc/wfclogic/utilities.py +++ b/minigrid/envs/wfc/wfclogic/utilities.py @@ -1,4 +1,5 @@ """Utility data and functions for WFC. Implementation based on https://github.com/ikarth/wfc_2019f""" + from __future__ import annotations import collections diff --git a/minigrid/wrappers.py b/minigrid/wrappers.py index 814c6e5f5..43aa70feb 100644 --- a/minigrid/wrappers.py +++ b/minigrid/wrappers.py @@ -1,8 +1,6 @@ from __future__ import annotations import math -import operator -from functools import reduce from typing import Any import gymnasium as gym @@ -596,7 +594,9 @@ def observation(self, obs): ), f"mission string too long ({len(mission)} chars)" mission = mission.lower() - str_array = np.zeros(shape=(self.maxStrLen, self.numCharCodes), dtype="uint8") + str_array = np.zeros( + shape=(self.maxStrLen, self.numCharCodes), dtype="uint8" + ) # as `numCharCodes` < 255 then we can use `uint8` for idx, ch in enumerate(mission): diff --git a/tests/test_wfc/test_wfc_adjacency.py b/tests/test_wfc/test_wfc_adjacency.py index be9cf22e2..f0cb113b0 100644 --- a/tests/test_wfc/test_wfc_adjacency.py +++ b/tests/test_wfc/test_wfc_adjacency.py @@ -1,4 +1,5 @@ """Convert input data to adjacency information""" + from __future__ import annotations import numpy as np diff --git a/tests/test_wfc/test_wfc_tiles.py b/tests/test_wfc/test_wfc_tiles.py index 4a114b4f7..d5563c964 100644 --- a/tests/test_wfc/test_wfc_tiles.py +++ b/tests/test_wfc/test_wfc_tiles.py @@ -1,4 +1,5 @@ """Breaks an image into consituant tiles.""" + from __future__ import annotations from minigrid.envs.wfc.wfclogic import tiles as wfc_tiles diff --git a/tests/utils.py b/tests/utils.py index f1a3ae5a3..586ddb010 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -1,4 +1,5 @@ """Finds all the specs that we can test with""" + from __future__ import annotations from importlib.util import find_spec From b6530e9ee4fdd3338c3152b010ddceecc2ae3a42 Mon Sep 17 00:00:00 2001 From: Bolun <36321182+BolunDai0216@users.noreply.github.com> Date: Sun, 6 Oct 2024 13:56:08 -0400 Subject: [PATCH 04/11] reformatted code --- minigrid/__init__.py | 24 +++++++++++++----------- pyproject.toml | 37 +++++++++++-------------------------- 2 files changed, 24 insertions(+), 37 deletions(-) diff --git a/minigrid/__init__.py b/minigrid/__init__.py index 154fb611d..9fd1f5a74 100644 --- a/minigrid/__init__.py +++ b/minigrid/__init__.py @@ -10,17 +10,6 @@ __version__ = "2.3.1" -try: - import sys - - from farama_notifications import notifications - - if "minigrid" in notifications and __version__ in notifications["minigrid"]: - print(notifications["minigrid"][__version__], file=sys.stderr) -except Exception: # nosec - pass - - def register_minigrid_envs(): # BlockedUnlockPickup # ---------------------------------------- @@ -1133,3 +1122,16 @@ def register_minigrid_envs(): id="BabyAI-BossLevelNoUnlock-v0", entry_point="minigrid.envs.babyai:BossLevelNoUnlock", ) + + +register_minigrid_envs() + +try: + import sys + + from farama_notifications import notifications + + if "minigrid" in notifications and __version__ in notifications["minigrid"]: + print(notifications["minigrid"][__version__], file=sys.stderr) +except Exception: # nosec + pass diff --git a/pyproject.toml b/pyproject.toml index 5d71ab691..d8f654713 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,7 +13,7 @@ authors = [{ name = "Farama Foundation", email = "contact@farama.org" }] license = { text = "MIT License" } keywords = ["Memory, Environment, Agent, RL, Gymnasium"] classifiers = [ - "Development Status :: 4 - Beta", # change to `5 - Production/Stable` when ready + "Development Status :: 4 - Beta", # change to `5 - Production/Stable` when ready "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.7", @@ -24,23 +24,12 @@ classifiers = [ 'Intended Audience :: Science/Research', 'Topic :: Scientific/Engineering :: Artificial Intelligence', ] -dependencies = [ - "numpy>=1.18.0", - "gymnasium>=0.28.1", - "pygame>=2.4.0", -] +dependencies = ["numpy>=1.18.0", "gymnasium>=0.28.1", "pygame>=2.4.0"] dynamic = ["version"] [project.optional-dependencies] -testing = [ - "pytest>=7.0.1", - "pytest-mock>=3.10.0", - "matplotlib>=3.0" -] -wfc = [ - "networkx", - "imageio>=2.31.1", -] +testing = ["pytest>=7.0.1", "pytest-mock>=3.10.0", "matplotlib>=3.0"] +wfc = ["networkx", "imageio>=2.31.1"] [project.urls] Homepage = "https://farama.org" @@ -60,24 +49,18 @@ include = ["minigrid*"] # Linters and Test tools ####################################################### [tool.black] -safe = true [tool.isort] atomic = true profile = "black" append_only = true src_paths = ["minigrid", "tests"] -add_imports = [ "from __future__ import annotations" ] +add_imports = ["from __future__ import annotations"] [tool.pyright] -include = [ - "minigrid/**", -] +include = ["minigrid/**"] -exclude = [ - "**/node_modules", - "**/__pycache__", -] +exclude = ["**/node_modules", "**/__pycache__"] strict = [] @@ -98,8 +81,10 @@ reportPrivateUsage = "warning" reportUntypedFunctionDecorator = "none" reportMissingTypeStubs = false reportUnboundVariable = "warning" -reportGeneralTypeIssues ="none" +reportGeneralTypeIssues = "none" reportPrivateImportUsage = "none" [tool.pytest.ini_options] -filterwarnings = ['ignore:.*step API.*:DeprecationWarning'] # TODO: to be removed when old step API is removed +filterwarnings = [ + 'ignore:.*step API.*:DeprecationWarning', +] # TODO: to be removed when old step API is removed From b085105262363fba876147f8ddf017ca4b05668a Mon Sep 17 00:00:00 2001 From: Bolun <36321182+BolunDai0216@users.noreply.github.com> Date: Sun, 6 Oct 2024 15:07:32 -0400 Subject: [PATCH 05/11] added a bunch of unwrapped --- minigrid/envs/babyai/core/verifier.py | 1 + minigrid/envs/crossing.py | 2 ++ minigrid/manual_control.py | 2 +- minigrid/wrappers.py | 37 ++++++++++++++++++--------- tests/test_envs.py | 8 +++--- tests/test_obstructed_maze.py | 6 ++--- tests/test_wrappers.py | 23 ++++++++--------- 7 files changed, 47 insertions(+), 32 deletions(-) diff --git a/minigrid/envs/babyai/core/verifier.py b/minigrid/envs/babyai/core/verifier.py index fac7c7e8f..dc0a3c3af 100644 --- a/minigrid/envs/babyai/core/verifier.py +++ b/minigrid/envs/babyai/core/verifier.py @@ -109,6 +109,7 @@ def find_matching_objs(self, env, use_location=True): the location of the object. e.g. A ball that was on "your right" initially will still be tracked as being "on your right" when you move. """ + env = env.unwrapped if use_location: self.obj_set = [] diff --git a/minigrid/envs/crossing.py b/minigrid/envs/crossing.py index 927a1955f..dab56e2ee 100644 --- a/minigrid/envs/crossing.py +++ b/minigrid/envs/crossing.py @@ -93,6 +93,7 @@ def __init__( ): self.num_crossings = num_crossings self.obstacle_type = obstacle_type + self.goal_position = None if obstacle_type == Lava: mission_space = MissionSpace(mission_func=self._gen_mission_lava) @@ -133,6 +134,7 @@ def _gen_grid(self, width, height): # Place a goal square in the bottom-right corner self.put_obj(Goal(), width - 2, height - 2) + self.goal_position = (width - 2, height - 2) # Place obstacles (lava or walls) v, h = object(), object() # singleton `vertical` and `horizontal` objects diff --git a/minigrid/manual_control.py b/minigrid/manual_control.py index 07be2e043..bbf6aa23a 100755 --- a/minigrid/manual_control.py +++ b/minigrid/manual_control.py @@ -36,7 +36,7 @@ def start(self): def step(self, action: Actions): _, reward, terminated, truncated, _ = self.env.step(action) - print(f"step={self.env.step_count}, reward={reward:.2f}") + print(f"step={self.env.unwrapped.step_count}, reward={reward:.2f}") if terminated: print("terminated!") diff --git a/minigrid/wrappers.py b/minigrid/wrappers.py index c87879b65..6cac0c57f 100644 --- a/minigrid/wrappers.py +++ b/minigrid/wrappers.py @@ -325,7 +325,7 @@ def __init__(self, env, tile_size=8): ) def observation(self, obs): - rgb_img = self.get_frame( + rgb_img = self.unwrapped.get_frame( highlight=self.unwrapped.highlight, tile_size=self.tile_size ) @@ -374,7 +374,9 @@ def __init__(self, env, tile_size=8): ) def observation(self, obs): - rgb_img_partial = self.get_frame(tile_size=self.tile_size, agent_pov=True) + rgb_img_partial = self.unwrapped.get_frame( + tile_size=self.tile_size, agent_pov=True + ) return {**obs, "image": rgb_img_partial} @@ -403,7 +405,11 @@ def __init__(self, env): new_image_space = spaces.Box( low=0, high=255, - shape=(self.env.width, self.env.height, 3), # number of cells + shape=( + self.env.unwrapped.width, + self.env.unwrapped.height, + 3, + ), # number of cells dtype="uint8", ) @@ -696,21 +702,21 @@ def reset( if not self.goal_position: self.goal_position = [ - x for x, y in enumerate(self.grid.grid) if isinstance(y, Goal) + x for x, y in enumerate(self.unwrapped.grid.grid) if isinstance(y, Goal) ] # in case there are multiple goals , needs to be handled for other env types if len(self.goal_position) >= 1: self.goal_position = ( - int(self.goal_position[0] / self.height), - self.goal_position[0] % self.width, + int(self.goal_position[0] / self.unwrapped.height), + self.goal_position[0] % self.unwrapped.width, ) return self.observation(obs), info def observation(self, obs): slope = np.divide( - self.goal_position[1] - self.agent_pos[1], - self.goal_position[0] - self.agent_pos[0], + self.goal_position[1] - self.unwrapped.agent_pos[1], + self.goal_position[0] - self.unwrapped.agent_pos[0], ) if self.type == "angle": @@ -746,7 +752,11 @@ def __init__(self, env): new_image_space = spaces.Box( low=0, high=max(OBJECT_TO_IDX.values()), - shape=(self.env.width, self.env.height, 3), # number of cells + shape=( + self.env.unwrapped.width, + self.env.unwrapped.height, + 3, + ), # number of cells dtype="uint8", ) self.observation_space = spaces.Dict( @@ -755,10 +765,13 @@ def __init__(self, env): def observation(self, obs): objects = np.array( - [OBJECT_TO_IDX[o.type] if o is not None else -1 for o in self.grid.grid] + [ + OBJECT_TO_IDX[o.type] if o is not None else -1 + for o in self.unwrapped.grid.grid + ] ) - agent_pos = self.env.agent_pos - ncol, nrow = self.width, self.height + agent_pos = self.env.unwrapped.agent_pos + ncol, nrow = self.unwrapped.width, self.unwrapped.height grid = np.mgrid[:ncol, :nrow] _objects = np.transpose(objects.reshape(1, nrow, ncol), (0, 2, 1)) diff --git a/tests/test_envs.py b/tests/test_envs.py index 7b62ec128..64fef5bc0 100644 --- a/tests/test_envs.py +++ b/tests/test_envs.py @@ -121,13 +121,13 @@ def test_render_modes(spec): @pytest.mark.parametrize("env_id", ["MiniGrid-DoorKey-6x6-v0"]) def test_agent_sees_method(env_id): env = gym.make(env_id) - goal_pos = (env.grid.width - 2, env.grid.height - 2) + goal_pos = (env.unwrapped.grid.width - 2, env.unwrapped.grid.height - 2) # Test the env.agent_sees() function env.reset() # Test the "in" operator on grid objects - assert ("green", "goal") in env.grid - assert ("blue", "key") not in env.grid + assert ("green", "goal") in env.unwrapped.grid + assert ("blue", "key") not in env.unwrapped.grid for i in range(0, 500): action = env.action_space.sample() obs, reward, terminated, truncated, info = env.step(action) @@ -135,7 +135,7 @@ def test_agent_sees_method(env_id): grid, _ = Grid.decode(obs["image"]) goal_visible = ("green", "goal") in grid - agent_sees_goal = env.agent_sees(*goal_pos) + agent_sees_goal = env.unwrapped.agent_sees(*goal_pos) assert agent_sees_goal == goal_visible if terminated or truncated: env.reset() diff --git a/tests/test_obstructed_maze.py b/tests/test_obstructed_maze.py index c6f035c33..45cd67c13 100644 --- a/tests/test_obstructed_maze.py +++ b/tests/test_obstructed_maze.py @@ -15,13 +15,13 @@ def find_ball_room(env): - for obj in env.grid.grid: + for obj in env.unwrapped.grid.grid: if isinstance(obj, Ball) and obj.color == COLOR_NAMES[0]: - return env.room_from_pos(*obj.cur_pos) + return env.unwrapped.room_from_pos(*obj.cur_pos) def find_target_key(env, color): - for obj in env.grid.grid: + for obj in env.unwrapped.grid.grid: if isinstance(obj, Box) and obj.contains.color == color: return True return False diff --git a/tests/test_wrappers.py b/tests/test_wrappers.py index 9afd544f1..362d17566 100644 --- a/tests/test_wrappers.py +++ b/tests/test_wrappers.py @@ -141,7 +141,7 @@ def test_dict_observation_space_wrapper(env_spec): env = env_spec.make() env = DictObservationSpaceWrapper(env) env.reset() - mission = env.mission + mission = env.unwrapped.mission obs, _, _, _, _ = env.step(0) assert env.string_to_indices(mission) == [ value for value in obs["mission"] if value != 0 @@ -273,10 +273,9 @@ def test_direction_obs_wrapper(env_id, type): env = gym.make(env_id) env = DirectionObsWrapper(env, type=type) obs, _ = env.reset() - slope = np.divide( - env.goal_position[1] - env.agent_pos[1], - env.goal_position[0] - env.agent_pos[0], + env.unwrapped.goal_position[1] - env.unwrapped.agent_pos[1], + env.unwrapped.goal_position[0] - env.unwrapped.agent_pos[0], ) if type == "slope": assert obs["goal_direction"] == slope @@ -285,8 +284,8 @@ def test_direction_obs_wrapper(env_id, type): obs, _, _, _, _ = env.step(0) slope = np.divide( - env.goal_position[1] - env.agent_pos[1], - env.goal_position[0] - env.agent_pos[0], + env.unwrapped.goal_position[1] - env.unwrapped.agent_pos[1], + env.unwrapped.goal_position[0] - env.unwrapped.agent_pos[0], ) if type == "slope": assert obs["goal_direction"] == slope @@ -302,10 +301,10 @@ def test_symbolic_obs_wrapper(env_id): env = SymbolicObsWrapper(env) obs, _ = env.reset(seed=123) - agent_pos = env.agent_pos - goal_pos = env.goal_pos + agent_pos = env.unwrapped.agent_pos + goal_pos = env.unwrapped.goal_pos - assert obs["image"].shape == (env.width, env.height, 3) + assert obs["image"].shape == (env.unwrapped.width, env.unwrapped.height, 3) assert np.alltrue( obs["image"][agent_pos[0], agent_pos[1], :] == np.array([agent_pos[0], agent_pos[1], OBJECT_TO_IDX["agent"]]) @@ -316,10 +315,10 @@ def test_symbolic_obs_wrapper(env_id): ) obs, _, _, _, _ = env.step(2) - agent_pos = env.agent_pos - goal_pos = env.goal_pos + agent_pos = env.unwrapped.agent_pos + goal_pos = env.unwrapped.goal_pos - assert obs["image"].shape == (env.width, env.height, 3) + assert obs["image"].shape == (env.unwrapped.width, env.unwrapped.height, 3) assert np.alltrue( obs["image"][agent_pos[0], agent_pos[1], :] == np.array([agent_pos[0], agent_pos[1], OBJECT_TO_IDX["agent"]]) From e59c2735fd5d4b18ff7ce2b8f8a83883e60e7dc3 Mon Sep 17 00:00:00 2001 From: Bolun <36321182+BolunDai0216@users.noreply.github.com> Date: Sun, 6 Oct 2024 15:11:51 -0400 Subject: [PATCH 06/11] updated nodeath --- minigrid/wrappers.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/minigrid/wrappers.py b/minigrid/wrappers.py index 6cac0c57f..3c40f0764 100644 --- a/minigrid/wrappers.py +++ b/minigrid/wrappers.py @@ -862,9 +862,9 @@ def __init__(self, env, no_death_types: tuple[str, ...], death_cost: float = -1. def step(self, action): # In Dynamic-Obstacles, obstacles move after the agent moves, # so we need to check for collision before self.env.step() - front_cell = self.grid.get(*self.front_pos) + front_cell = self.unwrapped.grid.get(*self.unwrapped.front_pos) going_to_death = ( - action == self.actions.forward + action == self.unwrapped.actions.forward and front_cell is not None and front_cell.type in self.no_death_types ) @@ -873,7 +873,7 @@ def step(self, action): # We also check if the agent stays in death cells (e.g., lava) # without moving - current_cell = self.grid.get(*self.agent_pos) + current_cell = self.unwrapped.grid.get(*self.unwrapped.agent_pos) in_death = current_cell is not None and current_cell.type in self.no_death_types if terminated and (going_to_death or in_death): From 1309a10789915617594a6f6f38444dc8a7a87781 Mon Sep 17 00:00:00 2001 From: Bolun <36321182+BolunDai0216@users.noreply.github.com> Date: Tue, 22 Oct 2024 03:56:57 -1000 Subject: [PATCH 07/11] updated numpy to 2.0.0+ --- requirements.txt | 4 ++-- tests/test_wfc/test_wfc_solver.py | 2 +- tests/test_wrappers.py | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/requirements.txt b/requirements.txt index 794fa473f..b928113c2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ -numpy>=1.18.0 -gymnasium>=0.26 +numpy>=2.0.0 +gymnasium>=1.0.0 pygame>=2.2.0 diff --git a/tests/test_wfc/test_wfc_solver.py b/tests/test_wfc/test_wfc_solver.py index 831238b82..1602cf705 100644 --- a/tests/test_wfc/test_wfc_solver.py +++ b/tests/test_wfc/test_wfc_solver.py @@ -18,7 +18,7 @@ def test_entropyLocationHeuristic() -> None: wave = np.ones((5, 3, 4), dtype=bool) # everything is possible wave[1:, 0, 0] = False # first cell is fully observed wave[4, :, 2] = False - preferences: NDArray[np.float_] = np.ones((3, 4), dtype=np.float_) * 0.5 + preferences: NDArray[np.float64] = np.ones((3, 4), dtype=np.float64) * 0.5 preferences[1, 2] = 0.3 preferences[1, 1] = 0.1 heu = wfc_solver.makeEntropyLocationHeuristic(preferences) diff --git a/tests/test_wrappers.py b/tests/test_wrappers.py index 362d17566..8930285d5 100644 --- a/tests/test_wrappers.py +++ b/tests/test_wrappers.py @@ -305,11 +305,11 @@ def test_symbolic_obs_wrapper(env_id): goal_pos = env.unwrapped.goal_pos assert obs["image"].shape == (env.unwrapped.width, env.unwrapped.height, 3) - assert np.alltrue( + assert np.all( obs["image"][agent_pos[0], agent_pos[1], :] == np.array([agent_pos[0], agent_pos[1], OBJECT_TO_IDX["agent"]]) ) - assert np.alltrue( + assert np.all( obs["image"][goal_pos[0], goal_pos[1], :] == np.array([goal_pos[0], goal_pos[1], OBJECT_TO_IDX["goal"]]) ) @@ -319,11 +319,11 @@ def test_symbolic_obs_wrapper(env_id): goal_pos = env.unwrapped.goal_pos assert obs["image"].shape == (env.unwrapped.width, env.unwrapped.height, 3) - assert np.alltrue( + assert np.all( obs["image"][agent_pos[0], agent_pos[1], :] == np.array([agent_pos[0], agent_pos[1], OBJECT_TO_IDX["agent"]]) ) - assert np.alltrue( + assert np.all( obs["image"][goal_pos[0], goal_pos[1], :] == np.array([goal_pos[0], goal_pos[1], OBJECT_TO_IDX["goal"]]) ) From 05b9900e19193039f92e73134b96f8a2dcf4b715 Mon Sep 17 00:00:00 2001 From: Bolun <36321182+BolunDai0216@users.noreply.github.com> Date: Tue, 22 Oct 2024 13:31:26 -1000 Subject: [PATCH 08/11] updated pyproject.toml and build.yml --- .github/workflows/build.yml | 2 +- pyproject.toml | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1483d4c18..359512921 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -17,6 +17,6 @@ jobs: --build-arg PYTHON_VERSION=${{ matrix.python-version }} \ --tag minigrid-docker . - name: Run tests - run: docker run minigrid-docker pytest + run: docker run minigrid-docker pytest --ignore tests/test_wfc - name: Run doctest run: docker run minigrid-docker pytest --doctest-modules minigrid/ diff --git a/pyproject.toml b/pyproject.toml index d8f654713..7e41b2e5c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -37,9 +37,6 @@ Repository = "https://minigrid.farama.org/" Documentation = "https://minigrid.farama.org/" "Bug Report" = "https://github.com/Farama-Foundation/Minigrid/issues" -[project.entry-points."gymnasium.envs"] -__root__ = "minigrid.__init__:register_minigrid_envs" - [tool.setuptools] include-package-data = true From 958b4cd290fa1f49c19c9d04afdd424c5645b8ba Mon Sep 17 00:00:00 2001 From: Bolun <36321182+BolunDai0216@users.noreply.github.com> Date: Sun, 3 Nov 2024 10:13:20 -0500 Subject: [PATCH 09/11] updated doctests --- minigrid/__init__.py | 2 +- minigrid/wrappers.py | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/minigrid/__init__.py b/minigrid/__init__.py index 9fd1f5a74..43703d978 100644 --- a/minigrid/__init__.py +++ b/minigrid/__init__.py @@ -7,7 +7,7 @@ from minigrid.core.world_object import Wall from minigrid.envs.wfc.config import WFC_PRESETS, register_wfc_presets -__version__ = "2.3.1" +__version__ = "3.0.0" def register_minigrid_envs(): diff --git a/minigrid/wrappers.py b/minigrid/wrappers.py index 3c40f0764..3e553564a 100644 --- a/minigrid/wrappers.py +++ b/minigrid/wrappers.py @@ -24,20 +24,20 @@ class ReseedWrapper(Wrapper): >>> from minigrid.wrappers import ReseedWrapper >>> env = gym.make("MiniGrid-Empty-5x5-v0") >>> _ = env.reset(seed=123) - >>> [env.np_random.integers(10) for i in range(10)] + >>> [env.np_random.integers(10).item() for i in range(10)] [0, 6, 5, 0, 9, 2, 2, 1, 3, 1] >>> env = ReseedWrapper(env, seeds=[0, 1], seed_idx=0) >>> _, _ = env.reset() - >>> [env.np_random.integers(10) for i in range(10)] + >>> [env.np_random.integers(10).item() for i in range(10)] [8, 6, 5, 2, 3, 0, 0, 0, 1, 8] >>> _, _ = env.reset() - >>> [env.np_random.integers(10) for i in range(10)] + >>> [env.np_random.integers(10).item() for i in range(10)] [4, 5, 7, 9, 0, 1, 8, 9, 2, 3] >>> _, _ = env.reset() - >>> [env.np_random.integers(10) for i in range(10)] + >>> [env.np_random.integers(10).item() for i in range(10)] [8, 6, 5, 2, 3, 0, 0, 0, 1, 8] >>> _, _ = env.reset() - >>> [env.np_random.integers(10) for i in range(10)] + >>> [env.np_random.integers(10).item() for i in range(10)] [4, 5, 7, 9, 0, 1, 8, 9, 2, 3] """ @@ -686,7 +686,7 @@ class DirectionObsWrapper(ObservationWrapper): >>> env = gym.make("MiniGrid-LavaCrossingS11N5-v0") >>> env_obs = DirectionObsWrapper(env, type="slope") >>> obs, _ = env_obs.reset() - >>> obs['goal_direction'] + >>> obs['goal_direction'].item() 1.0 """ From e55450289551c46c7ef635b7c0926ab4b98c9344 Mon Sep 17 00:00:00 2001 From: Bolun <36321182+BolunDai0216@users.noreply.github.com> Date: Sun, 3 Nov 2024 15:00:18 -0500 Subject: [PATCH 10/11] updated pre-commit workflow --- .github/workflows/pre-commit.yml | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 5886f5a2e..3e87ddfe4 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -1,18 +1,20 @@ # https://pre-commit.com # This GitHub Action assumes that the repo contains a valid .pre-commit-config.yaml file. -name: pre-commit -on: [pull_request, push] +name: Run pre-commit +on: + pull_request: + push: + branches: [main] permissions: - contents: read + contents: read # to fetch code (actions/checkout) jobs: pre-commit: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions/setup-python@v2 - - run: pip install pre-commit + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + - run: pipx install pre-commit - run: pre-commit --version - - run: pre-commit install - run: pre-commit run --all-files \ No newline at end of file From abed4300d92d138ad894c644d538929726c3b5dc Mon Sep 17 00:00:00 2001 From: Bolun <36321182+BolunDai0216@users.noreply.github.com> Date: Mon, 4 Nov 2024 07:29:07 -0500 Subject: [PATCH 11/11] updated pyright version --- .github/workflows/pre-commit.yml | 4 ++-- .pre-commit-config.yaml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 3e87ddfe4..a5f32d32b 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -4,7 +4,7 @@ name: Run pre-commit on: pull_request: push: - branches: [main] + branches: [master] permissions: contents: read # to fetch code (actions/checkout) @@ -15,6 +15,6 @@ jobs: steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 - - run: pipx install pre-commit + - run: pip install pre-commit - run: pre-commit --version - run: pre-commit run --all-files \ No newline at end of file diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0cea21b90..4aa0eefff 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -48,6 +48,6 @@ repos: language: node pass_filenames: false types: [python] - additional_dependencies: ["pyright"] + additional_dependencies: ["pyright@1.1.383"] args: - --project=pyproject.toml