From a14d2ed4d008449e16f89429e8d58ba90093d206 Mon Sep 17 00:00:00 2001 From: Bolun <36321182+BolunDai0216@users.noreply.github.com> Date: Mon, 24 Jul 2023 11:22:06 -0400 Subject: [PATCH 1/8] updated docs --- docs/content/basic_usage.md | 10 +--------- docs/content/training.md | 2 +- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/docs/content/basic_usage.md b/docs/content/basic_usage.md index 6d93fb4b0..0c8cd5eef 100644 --- a/docs/content/basic_usage.md +++ b/docs/content/basic_usage.md @@ -21,13 +21,5 @@ The environment being run can be selected with the `--env` option, eg: ## Training an Agent -If you want to train an agent with reinforcement learning, I recommend using the code found in the [torch-rl](https://github.com/lcswillems/torch-rl) repository. -This code has been tested and is known to work with this environment. The default hyper-parameters are also known to converge. - -A sample training command is: - -``` -cd torch-rl -python3 -m scripts.train --env MiniGrid-Empty-8x8-v0 --algo ppo -``` +If you want to train an agent with reinforcement learning, please refer to the [training tutorial](training.md). diff --git a/docs/content/training.md b/docs/content/training.md index 5817b0849..1560de762 100644 --- a/docs/content/training.md +++ b/docs/content/training.md @@ -4,7 +4,7 @@ title: Training Minigrid Environments firstpage: --- -## Training Minigrid Environments +# Training Minigrid Environments The environments in the Minigrid library can be trained easily using [StableBaselines3](https://stable-baselines3.readthedocs.io/en/master/). In this tutorial we show how a PPO agent can be trained on the `MiniGrid-Empty-16x16-v0` environment. From 3dadbe8f587fd9a88d3181dfa4828556142fd29c Mon Sep 17 00:00:00 2001 From: Bolun <36321182+BolunDai0216@users.noreply.github.com> Date: Mon, 31 Jul 2023 10:00:21 -0400 Subject: [PATCH 2/8] added installation tutorial --- docs/content/basic_usage.md | 19 +++++++++++++++---- docs/content/training.md | 2 +- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/docs/content/basic_usage.md b/docs/content/basic_usage.md index 0c8cd5eef..24a1530d7 100644 --- a/docs/content/basic_usage.md +++ b/docs/content/basic_usage.md @@ -9,17 +9,28 @@ firstpage: There is a UI application which allows you to manually control the agent with the arrow keys: -``` +```bash ./minigrid/manual_control.py ``` The environment being run can be selected with the `--env` option, eg: -``` +```bash ./minigrid/manual_control.py --env MiniGrid-Empty-8x8-v0 ``` -## Training an Agent +## Installation + +Minigrid call be installed via `pip`: -If you want to train an agent with reinforcement learning, please refer to the [training tutorial](training.md). +```bash +python3 -m pip install minigrid +``` + +To modify the codebase or contribute to Minigrid, you would need to install Minigrid from source: +```bash +git clone https://github.com/Farama-Foundation/Minigrid.git +cd Minigrid +python3 -m pip install -e . +``` diff --git a/docs/content/training.md b/docs/content/training.md index 1560de762..f2d333d38 100644 --- a/docs/content/training.md +++ b/docs/content/training.md @@ -10,7 +10,7 @@ The environments in the Minigrid library can be trained easily using [StableBase ## Create Custom Feature Extractor -Although `StableBaselines3` is fully compatible with `Gymnasium`-based environments, including Minigrid, the default CNN architecture does not directly support the Minigrid observation space. Thus, to train an agent on Minigrid environments, we therefore need to create a custom feature extractor. This can be done by creating a feature extractor class that inherits from `stable_baselines3.common.torch_layers.BaseFeaturesExtractor` +Although `StableBaselines3` is fully compatible with `Gymnasium`-based environments (which includes Minigrid), the default CNN architecture does not directly support the Minigrid observation space. Thus, to train an agent on Minigrid environments, we need to create a custom feature extractor. This can be done by creating a feature extractor class that inherits from `stable_baselines3.common.torch_layers.BaseFeaturesExtractor` ```python class MinigridFeaturesExtractor(BaseFeaturesExtractor): From c7b2b876ba34e15842abad49be5edea0e242c2e2 Mon Sep 17 00:00:00 2001 From: Bolun <36321182+BolunDai0216@users.noreply.github.com> Date: Mon, 31 Jul 2023 10:46:14 -0400 Subject: [PATCH 3/8] added default value to agent_pos and agent_dir in __str__ --- minigrid/minigrid_env.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/minigrid/minigrid_env.py b/minigrid/minigrid_env.py index 910435fc1..9ac5bdff9 100755 --- a/minigrid/minigrid_env.py +++ b/minigrid/minigrid_env.py @@ -196,10 +196,19 @@ def __str__(self): output = "" + # check if self.agent_pos & self.agent_dir is None + # should not be after env is reset + if self.agent_pos is None: + _agent_pos = (1, 1) + _agent_dir = 0 + else: + _agent_pos = self.agent_pos + _agent_dir = self.agent_dir + for j in range(self.grid.height): for i in range(self.grid.width): - if i == self.agent_pos[0] and j == self.agent_pos[1]: - output += 2 * AGENT_DIR_TO_STR[self.agent_dir] + if i == _agent_pos[0] and j == _agent_pos[1]: + output += 2 * AGENT_DIR_TO_STR[_agent_dir] continue tile = self.grid.get(i, j) From 5d9ed8b381dd5e3c19739a599c9af008516e8e15 Mon Sep 17 00:00:00 2001 From: Bolun <36321182+BolunDai0216@users.noreply.github.com> Date: Mon, 31 Jul 2023 10:52:10 -0400 Subject: [PATCH 4/8] updated __str__ --- minigrid/minigrid_env.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/minigrid/minigrid_env.py b/minigrid/minigrid_env.py index 9ac5bdff9..c79927b17 100755 --- a/minigrid/minigrid_env.py +++ b/minigrid/minigrid_env.py @@ -199,16 +199,12 @@ def __str__(self): # check if self.agent_pos & self.agent_dir is None # should not be after env is reset if self.agent_pos is None: - _agent_pos = (1, 1) - _agent_dir = 0 - else: - _agent_pos = self.agent_pos - _agent_dir = self.agent_dir + return super().__str__() for j in range(self.grid.height): for i in range(self.grid.width): - if i == _agent_pos[0] and j == _agent_pos[1]: - output += 2 * AGENT_DIR_TO_STR[_agent_dir] + if i == self.agent_pos[0] and j == self.agent_pos[1]: + output += 2 * AGENT_DIR_TO_STR[self.agent_dir] continue tile = self.grid.get(i, j) From 92cb30610eadc7f81d8d00f890df0190fe89e147 Mon Sep 17 00:00:00 2001 From: Bolun Dai Date: Mon, 25 Sep 2023 09:30:16 -0400 Subject: [PATCH 5/8] updated documentation with installation guide --- docs/content/installation.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 docs/content/installation.md diff --git a/docs/content/installation.md b/docs/content/installation.md new file mode 100644 index 000000000..fb801afb5 --- /dev/null +++ b/docs/content/installation.md @@ -0,0 +1,28 @@ +# Installation + +To install `minigrid`, the easiest way is to use `pip`: + +```bash +pip install minigrid +``` + +However, if you would like to build on top of `minigrid`, you would need to install it from source. To do this, first clone the repository: + +```bash +git clone https://github.com/Farama-Foundation/Minigrid.git +``` + +Then, install the package: + +```bash +cd Minigrid +python3 -m pip install . +``` + +If you want to install the package in [development mode](https://setuptools.pypa.io/en/latest/userguide/development_mode.html), use the following command instead: + +```bash +python3 -m pip install -e . +``` + +An installation in development mode (i.e., an editable install) is useful if you want to modify the source code of `minigrid` and have your changes take effect immediately. \ No newline at end of file From d3232c43e268ead92edd58f80ee0b3ae867547e6 Mon Sep 17 00:00:00 2001 From: Bolun <36321182+BolunDai0216@users.noreply.github.com> Date: Sun, 14 Jan 2024 20:26:23 -0500 Subject: [PATCH 6/8] updated github workflow --- .github/workflows/build-docs-dev.yml | 2 +- .github/workflows/build-docs-version.yml | 2 +- .github/workflows/manual-build-docs-version.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-docs-dev.yml b/.github/workflows/build-docs-dev.yml index 84cb18270..194ce26e7 100644 --- a/.github/workflows/build-docs-dev.yml +++ b/.github/workflows/build-docs-dev.yml @@ -21,7 +21,7 @@ jobs: run: pip install -r docs/requirements.txt - name: Register Envs - run: pip install -e . + run: pip install -e .[wfc] - name: Build Envs Docs run: python docs/_scripts/gen_env_docs.py diff --git a/.github/workflows/build-docs-version.yml b/.github/workflows/build-docs-version.yml index 56112a823..631e87271 100644 --- a/.github/workflows/build-docs-version.yml +++ b/.github/workflows/build-docs-version.yml @@ -26,7 +26,7 @@ jobs: run: pip install -r docs/requirements.txt - name: Register Envs - run: pip install -e . + run: pip install -e .[wfc] - name: Build Envs Docs run: python docs/_scripts/gen_env_docs.py diff --git a/.github/workflows/manual-build-docs-version.yml b/.github/workflows/manual-build-docs-version.yml index 4cd95d081..a99cba639 100644 --- a/.github/workflows/manual-build-docs-version.yml +++ b/.github/workflows/manual-build-docs-version.yml @@ -37,7 +37,7 @@ jobs: run: pip install -r docs/requirements.txt - name: Register Envs - run: pip install -e . + run: pip install -e .[wfc] - name: Build Envs Docs run: python docs/_scripts/gen_env_docs.py From 78a9dbc1cc7ec087731ff63f15463abeb9ef50e9 Mon Sep 17 00:00:00 2001 From: Bolun <36321182+BolunDai0216@users.noreply.github.com> Date: Sun, 14 Jan 2024 20:55:16 -0500 Subject: [PATCH 7/8] updated github workflow --- docs/_scripts/gen_envs_display.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/docs/_scripts/gen_envs_display.py b/docs/_scripts/gen_envs_display.py index 3deacea06..ea323f526 100644 --- a/docs/_scripts/gen_envs_display.py +++ b/docs/_scripts/gen_envs_display.py @@ -77,9 +77,19 @@ def generate_page(env, limit=-1, base_path=""): env_type = key page = generate_page({"id": key, "list": value}) + # fp = open( + # os.path.join( + # os.path.dirname(__file__), "..", "environments", env_type, "list.html" + # ), + # "w", + # encoding="utf-8", + # ) fp = open( os.path.join( - os.path.dirname(__file__), "..", "environments", env_type, "list.html" + os.path.dirname(__file__), + "..", + "environments/minigrid", + f"{env_type}.md", ), "w", encoding="utf-8", From f69415506e120c96894db70b2631356b13154319 Mon Sep 17 00:00:00 2001 From: Bolun <36321182+BolunDai0216@users.noreply.github.com> Date: Mon, 15 Jan 2024 08:53:25 -0500 Subject: [PATCH 8/8] updated class name for obstructedmaze_v1 --- docs/_scripts/gen_envs_display.py | 12 +----------- minigrid/__init__.py | 8 ++++---- minigrid/envs/__init__.py | 1 + minigrid/envs/obstructedmaze_v1.py | 2 +- 4 files changed, 7 insertions(+), 16 deletions(-) diff --git a/docs/_scripts/gen_envs_display.py b/docs/_scripts/gen_envs_display.py index ea323f526..3deacea06 100644 --- a/docs/_scripts/gen_envs_display.py +++ b/docs/_scripts/gen_envs_display.py @@ -77,19 +77,9 @@ def generate_page(env, limit=-1, base_path=""): env_type = key page = generate_page({"id": key, "list": value}) - # fp = open( - # os.path.join( - # os.path.dirname(__file__), "..", "environments", env_type, "list.html" - # ), - # "w", - # encoding="utf-8", - # ) fp = open( os.path.join( - os.path.dirname(__file__), - "..", - "environments/minigrid", - f"{env_type}.md", + os.path.dirname(__file__), "..", "environments", env_type, "list.html" ), "w", encoding="utf-8", diff --git a/minigrid/__init__.py b/minigrid/__init__.py index be2f75264..d98e6ed0c 100644 --- a/minigrid/__init__.py +++ b/minigrid/__init__.py @@ -478,7 +478,7 @@ def register_minigrid_envs(): register( id="MiniGrid-ObstructedMaze-2Dlhb-v1", - entry_point="minigrid.envs.obstructedmaze_v1:ObstructedMaze_Full", + entry_point="minigrid.envs:ObstructedMaze_Full_V1", kwargs={ "agent_room": (2, 1), "key_in_box": True, @@ -490,7 +490,7 @@ def register_minigrid_envs(): register( id="MiniGrid-ObstructedMaze-1Q-v1", - entry_point="minigrid.envs.obstructedmaze_v1:ObstructedMaze_Full", + entry_point="minigrid.envs:ObstructedMaze_Full_V1", kwargs={ "agent_room": (1, 1), "key_in_box": True, @@ -502,7 +502,7 @@ def register_minigrid_envs(): register( id="MiniGrid-ObstructedMaze-2Q-v1", - entry_point="minigrid.envs.obstructedmaze_v1:ObstructedMaze_Full", + entry_point="minigrid.envs:ObstructedMaze_Full_V1", kwargs={ "agent_room": (2, 1), "key_in_box": True, @@ -514,7 +514,7 @@ def register_minigrid_envs(): register( id="MiniGrid-ObstructedMaze-Full-v1", - entry_point="minigrid.envs.obstructedmaze_v1:ObstructedMaze_Full", + entry_point="minigrid.envs:ObstructedMaze_Full_V1", ) # Playground diff --git a/minigrid/envs/__init__.py b/minigrid/envs/__init__.py index 5401e7157..7962f1e78 100644 --- a/minigrid/envs/__init__.py +++ b/minigrid/envs/__init__.py @@ -20,6 +20,7 @@ ObstructedMaze_Full, ObstructedMazeEnv, ) +from minigrid.envs.obstructedmaze_v1 import ObstructedMaze_Full_V1 from minigrid.envs.playground import PlaygroundEnv from minigrid.envs.putnear import PutNearEnv from minigrid.envs.redbluedoors import RedBlueDoorEnv diff --git a/minigrid/envs/obstructedmaze_v1.py b/minigrid/envs/obstructedmaze_v1.py index 08f6022b5..cae181e93 100644 --- a/minigrid/envs/obstructedmaze_v1.py +++ b/minigrid/envs/obstructedmaze_v1.py @@ -6,7 +6,7 @@ from minigrid.envs.obstructedmaze import ObstructedMazeEnv -class ObstructedMaze_Full(ObstructedMazeEnv): +class ObstructedMaze_Full_V1(ObstructedMazeEnv): """ A blue ball is hidden in one of the 4 corners of a 3x3 maze. Doors are locked, doors are obstructed by a ball and keys are hidden in