Skip to content

Commit

Permalink
Update Minigrid with pre-commit, fix ci, and clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
pseudo-rnd-thoughts committed Jan 10, 2025
1 parent fb7ce2b commit 62b5c91
Show file tree
Hide file tree
Showing 104 changed files with 154 additions and 123 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ Add any other context about the problem here.

### Checklist

- [ ] I have checked that there is no similar [issue](https://github.com/Farama-Foundation/MiniGrid/issues) in the repo (**required**)
- [ ] I have checked that there is no similar [issue](https://github.com/Farama-Foundation/MiniGrid/issues) in the repo (**required**)
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/proposal.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ title: "[Proposal] Proposal title"



### Proposal
### Proposal

A clear and concise description of the proposal.

Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions py.Dockerfile → .github/docker/py.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# A Dockerfile that sets up a full Gym install with test dependencies
ARG PYTHON_VERSION
ARG GYMNASIUM_VERSION
ARG NUMPY_VERSION
FROM python:$PYTHON_VERSION

SHELL ["/bin/bash", "-o", "pipefail", "-c"]
Expand All @@ -8,12 +10,10 @@ RUN apt-get -y update \
&& apt-get install --no-install-recommends -y \
xvfb

COPY . /usr/local/minigrid/
COPY ../.. /usr/local/minigrid/
WORKDIR /usr/local/minigrid/

RUN pip install .[wfc,testing] --no-cache-dir

RUN ["chmod", "+x", "/usr/local/minigrid/docker_entrypoint"]
RUN pip install gymnasium$GYMNASIUM_VERSION numpy$NUMPY_VERSION

ENTRYPOINT ["/usr/local/minigrid/docker_entrypoint"]

2 changes: 1 addition & 1 deletion .github/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ only: issues

# issues:
# exemptLabels:
# - confirmed
# - confirmed
2 changes: 1 addition & 1 deletion .github/workflows/build-docs-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ jobs:
with:
folder: _build
target-folder: main
clean: false
clean: false
2 changes: 1 addition & 1 deletion .github/workflows/build-docs-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ jobs:
folder: _build
clean-exclude: |
*.*.*/
main
main
22 changes: 0 additions & 22 deletions .github/workflows/build.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/manual-build-docs-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,4 @@ jobs:
folder: _build
clean-exclude: |
*.*.*/
main
main
2 changes: 1 addition & 1 deletion .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ jobs:
- uses: actions/setup-python@v5
- run: pip install pre-commit
- run: pre-commit --version
- run: pre-commit run --all-files
- run: pre-commit run --all-files
File renamed without changes.
37 changes: 37 additions & 0 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: build
on: [pull_request, push]

permissions:
contents: read

jobs:
build-latest:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
steps:
- uses: actions/checkout@v4
- run: |
docker build -f .github/docker/py.Dockerfile \
--build-arg PYTHON_VERSION=${{ matrix.python-version }} \
--build-arg GYMNASIUM_VERSION=">=1.0" \
--build-arg NUMPY_VERSION=">=2.0" \
--tag minigrid-docker .
- name: Run tests
run: docker run minigrid-docker pytest
- name: Run doctest
run: docker run minigrid-docker pytest --doctest-modules minigrid/

build-old:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: |
docker build -f .github/docker/py.Dockerfile \
--build-arg PYTHON_VERSION="3.10" \
--build-arg GYMNASIUM_VERSION="<1.0" \
--build-arg NUMPY_VERSION="<2.0" \
--tag minigrid-docker .
- name: Run tests
run: docker run minigrid-docker pytest
46 changes: 31 additions & 15 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,33 @@
---
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: check-symlinks
- id: destroyed-symlinks
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-toml
- id: check-ast
- id: check-added-large-files
- id: check-merge-conflict
- id: check-executables-have-shebangs
- id: check-shebang-scripts-are-executable
- id: detect-private-key
- id: debug-statements
- repo: https://github.com/python/black
rev: 23.12.1
rev: 24.10.0
hooks:
- id: black
- repo: https://github.com/codespell-project/codespell
rev: v2.2.6
rev: v2.3.0
hooks:
- id: codespell
args:
- --ignore-words-list=linz
- repo: https://github.com/PyCQA/flake8
rev: 7.0.0
rev: 7.1.1
hooks:
- id: flake8
args:
Expand All @@ -36,18 +52,18 @@ repos:
# - --convention=google
# additional_dependencies: ["toml"]
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.0
rev: v3.19.1
hooks:
- id: pyupgrade
args: ["--py37-plus"]
- repo: local
hooks:
- id: pyright
name: pyright
entry: pyright
language: node
pass_filenames: false
types: [python]
additional_dependencies: ["[email protected]"]
args:
- --project=pyproject.toml
# - repo: local
# hooks:
# - id: pyright
# name: pyright
# entry: pyright
# language: node
# pass_filenames: false
# types: [python]
# additional_dependencies: ["[email protected]"]
# args:
# - --project=pyproject.toml
1 change: 0 additions & 1 deletion CNAME

This file was deleted.

1 change: 0 additions & 1 deletion CODE_OF_CONDUCT.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,3 @@ Attribution
-----------
This Code of Conduct is adapted from `Python's Code of Conduct <https://www.python.org/psf/conduct/>`_, which is under a `Creative Commons License
<https://creativecommons.org/licenses/by-sa/3.0/>`_.

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<img src="figures/door-key-curriculum.gif" width=200 alt="Figure Door Key Curriculum">
</p>

The Minigrid library contains a collection of discrete grid-world environments to conduct research on Reinforcement Learning. The environments follow the [Gymnasium](https://github.com/Farama-Foundation/Gymnasium) standard API and they are designed to be lightweight, fast, and easily customizable.
The Minigrid library contains a collection of discrete grid-world environments to conduct research on Reinforcement Learning. The environments follow the [Gymnasium](https://github.com/Farama-Foundation/Gymnasium) standard API and they are designed to be lightweight, fast, and easily customizable.

The documentation website is at [minigrid.farama.org](https://minigrid.farama.org/), and we have a public discord server (which we also use to coordinate development work) that you can join here: [https://discord.gg/bnJ6kubTg6](https://discord.gg/bnJ6kubTg6)

Expand All @@ -24,7 +24,7 @@ To install the Minigrid library use `pip install minigrid`.
We support Python 3.7, 3.8, 3.9, 3.10 and 3.11 on Linux and macOS. We will accept PRs related to Windows, but do not officially support it.

# Environments
The included environments can be divided in two groups. The original `Minigrid` environments and the `BabyAI` environments.
The included environments can be divided in two groups. The original `Minigrid` environments and the `BabyAI` environments.

## Minigrid
The list of the environments that were included in the original `Minigrid` library can be found in the [documentation](https://minigrid.farama.org/environments/minigrid/). These environments have in common a triangle-like agent with a discrete action space that has to navigate a 2D map with different obstacles (Walls, Lava, Dynamic obstacles) depending on the environment. The task to be accomplished is described by a `mission` string returned by the observation of the agent. These mission tasks include different goal-oriented and hierarchical missions such as picking up boxes, opening doors with keys or navigating a maze to reach a goal location. Each environment provides one or more configurations registered with Gymansium. Each environment is also programmatically tunable in terms of size/complexity, which is useful for curriculum learning or to fine-tune difficulty.
Expand All @@ -34,7 +34,7 @@ These environments have been imported from the [BabyAI](https://github.com/mila-
natural-looking instructions (e.g. “put the red ball next to the box on your left”) that command the the agent to navigate the world (including unlocking doors) and move objects to specified locations in order to accomplish the task.

# Training an Agent
The [rl-starter-files](https://github.com/lcswillems/torch-rl) is a repository with examples on how to train `Minigrid` environments with RL algorithms. This code has been tested and is known to work with this environment. The default hyper-parameters are also known to converge.
The [rl-starter-files](https://github.com/lcswillems/torch-rl) is a repository with examples on how to train `Minigrid` environments with RL algorithms. This code has been tested and is known to work with this environment. The default hyper-parameters are also known to converge.

# Citation

Expand Down
8 changes: 5 additions & 3 deletions docs/_scripts/gen_env_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@
import re
from itertools import chain

from gymnasium.envs.registration import registry
import gymnasium
from tqdm import tqdm

import minigrid
from utils import env_name_format, trim

gymnasium.register_envs(minigrid)

readme_path = os.path.join(
os.path.dirname(os.path.dirname(os.path.dirname(__file__))),
"README.md",
)

all_envs = list(registry.values())
all_envs = list(gymnasium.registry.values())

filtered_envs_by_type = {}
env_names = []
Expand Down Expand Up @@ -120,7 +123,6 @@
|---|---|
| Action Space | `{re.sub(' +', ' ', action_space_table)}` |
| Observation Space | `{re.sub(' +', ' ', observation_space_table)}` |
| Reward Range | `{env.reward_range}` |
| Creation | `gymnasium.make("{env_spec.id}")` |
"""

Expand Down
9 changes: 8 additions & 1 deletion docs/_scripts/gen_gifs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
from PIL import Image
from tqdm import tqdm

import minigrid

gymnasium.register_envs(minigrid)

# snake to camel case: https://stackoverflow.com/questions/1175208/elegant-python-function-to-convert-camelcase-to-snake-case # noqa: E501
pattern = re.compile(r"(?<!^)(?=[A-Z])")

Expand All @@ -22,7 +26,7 @@
envs_completed = []

# iterate through all envspecs
for env_spec in tqdm(gymnasium.envs.registry.values()):
for env_spec in tqdm(gymnasium.registry.values()):
# minigrid.envs:Env or minigrid.envs.babyai:Env
if not isinstance(env_spec.entry_point, str):
continue
Expand All @@ -44,6 +48,9 @@
# try catch in case missing some installs
try:
env = gymnasium.make(env_spec.id, render_mode="rgb_array")
env.reset(seed=123)
env.action_space.seed(123)

# the gymnasium needs to be rgb renderable
if not ("rgb_array" in env.metadata["render_modes"]):
continue
Expand Down
24 changes: 12 additions & 12 deletions docs/_static/img/minigrid-white.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 12 additions & 12 deletions docs/_static/img/minigrid.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/_static/videos/babyai/ActionObjDoor.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/_static/videos/babyai/BlockedUnlockPickup.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/_static/videos/babyai/BossLevel.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/_static/videos/babyai/BossLevelNoUnlock.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/_static/videos/babyai/FindObjS5.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/_static/videos/babyai/GoTo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/_static/videos/babyai/GoToDoor.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/_static/videos/babyai/GoToImpUnlock.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/_static/videos/babyai/GoToLocal.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/_static/videos/babyai/GoToObj.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/_static/videos/babyai/GoToObjDoor.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/_static/videos/babyai/GoToRedBall.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/_static/videos/babyai/GoToRedBallGrey.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/_static/videos/babyai/GoToRedBallNoDists.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/_static/videos/babyai/GoToRedBlueBall.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/_static/videos/babyai/GoToSeq.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/_static/videos/babyai/KeyCorridor.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/_static/videos/babyai/KeyInBox.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/_static/videos/babyai/MiniBossLevel.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/_static/videos/babyai/MoveTwoAcross.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/_static/videos/babyai/OneRoomS8.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/_static/videos/babyai/Open.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/_static/videos/babyai/OpenDoor.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/_static/videos/babyai/OpenDoorsOrder.gif
Binary file modified docs/_static/videos/babyai/OpenRedDoor.gif
Binary file modified docs/_static/videos/babyai/OpenTwoDoors.gif
Binary file modified docs/_static/videos/babyai/Pickup.gif
Binary file modified docs/_static/videos/babyai/PickupAbove.gif
Binary file modified docs/_static/videos/babyai/PickupDist.gif
Binary file modified docs/_static/videos/babyai/PickupLoc.gif
Binary file modified docs/_static/videos/babyai/PutNext.gif
Binary file modified docs/_static/videos/babyai/PutNextLocal.gif
Binary file modified docs/_static/videos/babyai/Synth.gif
Binary file modified docs/_static/videos/babyai/SynthLoc.gif
Binary file modified docs/_static/videos/babyai/SynthSeq.gif
Binary file modified docs/_static/videos/babyai/UnblockPickup.gif
Binary file modified docs/_static/videos/babyai/Unlock.gif
Binary file modified docs/_static/videos/babyai/UnlockLocal.gif
Binary file modified docs/_static/videos/babyai/UnlockPickup.gif
Binary file modified docs/_static/videos/babyai/UnlockToUnlock.gif
Binary file modified docs/_static/videos/minigrid/BlockedUnlockPickupEnv.gif
Binary file modified docs/_static/videos/minigrid/CrossingEnv.gif
Binary file modified docs/_static/videos/minigrid/DistShiftEnv.gif
Binary file modified docs/_static/videos/minigrid/DoorKeyEnv.gif
Binary file modified docs/_static/videos/minigrid/DynamicObstaclesEnv.gif
Binary file modified docs/_static/videos/minigrid/EmptyEnv.gif
Binary file modified docs/_static/videos/minigrid/FetchEnv.gif
Binary file modified docs/_static/videos/minigrid/FourRoomsEnv.gif
Binary file modified docs/_static/videos/minigrid/GoToDoorEnv.gif
Binary file modified docs/_static/videos/minigrid/GoToObjectEnv.gif
Binary file modified docs/_static/videos/minigrid/KeyCorridorEnv.gif
Binary file modified docs/_static/videos/minigrid/LavaGapEnv.gif
Binary file modified docs/_static/videos/minigrid/LockedRoomEnv.gif
Binary file modified docs/_static/videos/minigrid/MemoryEnv.gif
Binary file modified docs/_static/videos/minigrid/MultiRoomEnv.gif
Binary file modified docs/_static/videos/minigrid/ObstructedMaze_1Dlhb.gif
Binary file modified docs/_static/videos/minigrid/ObstructedMaze_Full.gif
Binary file modified docs/_static/videos/minigrid/ObstructedMaze_Full_V1.gif
Binary file modified docs/_static/videos/minigrid/PlaygroundEnv.gif
Binary file modified docs/_static/videos/minigrid/PutNearEnv.gif
Binary file modified docs/_static/videos/minigrid/RedBlueDoorEnv.gif
Binary file modified docs/_static/videos/minigrid/UnlockEnv.gif
Binary file modified docs/_static/videos/minigrid/UnlockPickupEnv.gif
Binary file modified docs/_static/videos/wfc/DungeonMazeScaled.gif
Binary file modified docs/_static/videos/wfc/MazeSimple.gif
Binary file modified docs/_static/videos/wfc/ObstaclesAngular.gif
Binary file modified docs/_static/videos/wfc/ObstaclesBlackdots.gif
Binary file modified docs/_static/videos/wfc/ObstaclesHogs3.gif
Binary file modified docs/_static/videos/wfc/RoomsFabric.gif
6 changes: 3 additions & 3 deletions docs/api/wrapper.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ field which can be used as an optional compass. Using dictionaries makes it
easy for you to add additional information to observations
if you need to, without having to encode everything into a single tensor.

There are a variety of wrappers to change the observation format available in [minigrid/wrappers.py](/minigrid/wrappers.py).
If your RL code expects one single tensor for observations, take a look at `FlatObsWrapper`.
There are a variety of wrappers to change the observation format available in [minigrid/wrappers.py](/minigrid/wrappers.py).
If your RL code expects one single tensor for observations, take a look at `FlatObsWrapper`.
There is also an `ImgObsWrapper` that gets rid of the 'mission' field in observations, leaving only the image field tensor.

Please note that the default observation format is a partially observable view of the environment using a
Expand All @@ -36,4 +36,4 @@ obs, _ = env.reset() # This now produces an RGB tensor only
```{toctree}
:hidden:
wrappers
```
```
Loading

0 comments on commit 62b5c91

Please sign in to comment.