Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for gymnasium v1.0 #475

Merged
merged 8 commits into from
Nov 5, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add support for gymnasium v1.0
araffin committed Nov 2, 2024
commit 3e6f40edff0bb68cd5bff9343a81a97afec9c433
21 changes: 13 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -20,7 +20,12 @@ jobs:
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]

include:
# Default version
- gymnasium-version: "1.0.0"
# Add a new config to test gym<1.0
- python-version: "3.10"
gymnasium-version: "0.29.1"
steps:
- uses: actions/checkout@v3
with:
@@ -32,22 +37,22 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip

# Use uv for faster downloads
pip install uv
# Install Atari Roms
uv pip install --system autorom
wget https://gist.githubusercontent.com/jjshoots/61b22aefce4456920ba99f2c36906eda/raw/00046ac3403768bfe45857610a3d333b8e35e026/Roms.tar.gz.b64
base64 Roms.tar.gz.b64 --decode &> Roms.tar.gz
AutoROM --accept-license --source-file Roms.tar.gz

# cpu version of pytorch
# See https://github.com/astral-sh/uv/issues/1497
uv pip install --system torch==2.4.1+cpu --index https://download.pytorch.org/whl/cpu
# Install full requirements (for additional envs and test tools)
uv pip install --system -r requirements.txt
# Use headless version
uv pip install --system opencv-python-headless
uv pip install --system -e .[plots,tests]

- name: Install specific version of gym
run: |
uv pip install --system gymnasium==${{ matrix.gymnasium-version }}
# Only run for python 3.10, downgrade gym to 0.29.1

- name: Lint with ruff
run: |
make lint
21 changes: 14 additions & 7 deletions .github/workflows/trained_agents.yml
Original file line number Diff line number Diff line change
@@ -21,7 +21,12 @@ jobs:
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]

include:
# Default version
- gymnasium-version: "1.0.0"
# Add a new config to test gym<1.0
- python-version: "3.10"
gymnasium-version: "0.29.1"
steps:
- uses: actions/checkout@v3
with:
@@ -36,19 +41,21 @@ jobs:

# Use uv for faster downloads
pip install uv
# Install Atari Roms
uv pip install --system autorom
wget https://gist.githubusercontent.com/jjshoots/61b22aefce4456920ba99f2c36906eda/raw/00046ac3403768bfe45857610a3d333b8e35e026/Roms.tar.gz.b64
base64 Roms.tar.gz.b64 --decode &> Roms.tar.gz
AutoROM --accept-license --source-file Roms.tar.gz

# cpu version of pytorch
# See https://github.com/astral-sh/uv/issues/1497
uv pip install --system torch==2.4.1+cpu --index https://download.pytorch.org/whl/cpu
# Install full requirements (for additional envs and test tools)
# Install full requirements (for additional envs and test tools)
uv pip install --system -r requirements.txt
# Use headless version
uv pip install --system opencv-python-headless
uv pip install --system -e .[plots,tests]

- name: Install specific version of gym
run: |
uv pip install --system gymnasium==${{ matrix.gymnasium-version }}
# Only run for python 3.10, downgrade gym to 0.29.1

- name: Check trained agents
run: |
make check-trained-agents
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
gym==0.26.2
stable-baselines3[extra_no_roms,tests,docs]>=2.4.0a10,<3.0
stable-baselines3[extra,tests,docs]>=2.4.0a10,<3.0
box2d-py==2.3.8
pybullet_envs_gymnasium>=0.4.0
# minigrid
@@ -9,4 +9,4 @@ plotly
# need to upgrade to gymnasium:
# panda-gym~=3.0.1
wandb
moviepy
moviepy>=1.0.0
5 changes: 4 additions & 1 deletion rl_zoo3/gym_patches.py
Original file line number Diff line number Diff line change
@@ -39,5 +39,8 @@ def step(self, action):

# Patch Gymnasium TimeLimit
gymnasium.wrappers.TimeLimit = PatchedTimeLimit # type: ignore[misc]
gymnasium.wrappers.time_limit.TimeLimit = PatchedTimeLimit # type: ignore[misc]
try:
gymnasium.wrappers.time_limit.TimeLimit = PatchedTimeLimit # type: ignore[misc]
except AttributeError:
gymnasium.wrappers.common.TimeLimit = PatchedTimeLimit # type: ignore[misc]
gymnasium.envs.registration.TimeLimit = PatchedTimeLimit # type: ignore[misc,attr-defined]
9 changes: 8 additions & 1 deletion rl_zoo3/import_envs.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Callable, Optional

import gymnasium as gym
from gymnasium.envs.registration import register
from gymnasium.envs.registration import register, register_envs

from rl_zoo3.wrappers import MaskVelocityWrapper

@@ -10,6 +10,13 @@
except ImportError:
pass

try:
import ale_py
# no-op
gym.register_envs(ale_py)
except ImportError:
pass

try:
import highway_env
except ImportError: