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

Migrate to gymnasium maintaining python 3.8 compatibility #73

Merged
merged 61 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from 55 commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
440d5a7
Initial commit
Rocamonde Jul 1, 2023
3ed6d2b
py38 compatible type hints
EdoardoPona Jul 27, 2023
35feb65
gymnasium compatible reset
EdoardoPona Jul 27, 2023
4696597
gymnasium compatibility changes
EdoardoPona Jul 28, 2023
bb20d54
gymnasium compatible reset and random
EdoardoPona Jul 28, 2023
b2f8421
Make type annotations python 3.8 compatible.
ernestum Aug 2, 2023
030ae67
Fix some grammar issues.
ernestum Aug 2, 2023
2f4af9d
Raise RuntimeErrors and ValueErrors in the proper places.
ernestum Aug 2, 2023
93292c5
Undoing unrelated formatting fixes in the readme.
ernestum Aug 3, 2023
a3520a6
Remove unused ruff configuration.
ernestum Aug 3, 2023
364d0e8
Add Adams wording suggestions.
ernestum Aug 3, 2023
baacaca
switch to alpha-version of the circle-ci image (reverst this before m…
ernestum Aug 8, 2023
c5cbe30
Update Xdummy-entrypoint.py to python3
ernestum Aug 11, 2023
b684e88
Update Dockerfile to Ubuntu 20.04 and add ssh.
ernestum Aug 11, 2023
a1ab629
Dont mention gym in inline comment but gymnasium.
ernestum Aug 11, 2023
0e56b49
Absorb terminated AND truncated steps.
ernestum Aug 11, 2023
034307f
Treat done == (terminated or truncated) and stop mentioning done in t…
ernestum Aug 11, 2023
57c6301
Remove outdated make_env_no_wrappers
ernestum Aug 11, 2023
83fc29e
Use registry keys instead of extracting env_id from the spec.
ernestum Aug 11, 2023
5eba4c2
Ensure to seed environments upon the first reset.
ernestum Aug 13, 2023
599031a
Add missing shimmy dependency for atari.
ernestum Aug 13, 2023
15f7494
Detect atari envs by looking for shimmy entrypoint instead of gym ent…
ernestum Aug 13, 2023
2342e72
Add missing observation space to TabularModelMDP
ernestum Aug 13, 2023
dada630
Look for render modes in new location of the environment metadata.
ernestum Aug 13, 2023
807d79b
When testing the rollout schema, check for both termination and trunc…
ernestum Aug 13, 2023
6bb994e
Remove outdated asserts on the result of env.reset().
ernestum Aug 13, 2023
05dcf67
Adapt reset() of MaskScroeWrapper to new gymnasium API
ernestum Aug 13, 2023
c7d8c1a
Switch to v4 versions of the MuJoCo environments.
ernestum Aug 14, 2023
e73e209
Simplify tests for render modes.
ernestum Aug 14, 2023
1650590
Forward args and kwargs when constructing environments, so we can pas…
ernestum Aug 14, 2023
602f0a9
Add `Casino-Unmasked-v5` to the list of slow envs with randomness.
ernestum Aug 14, 2023
b739176
Add some missing commas.
ernestum Aug 14, 2023
2dce7ae
Add pygame to setup.py
ernestum Aug 14, 2023
72da2f1
Update ale-py version.
ernestum Aug 14, 2023
062e31d
Make test_sample_distribution deterministic by introducing a seed.
ernestum Aug 14, 2023
4ccc884
Fixing isort issues.
ernestum Aug 14, 2023
4c2379c
Add missing trailing commas.
ernestum Aug 14, 2023
96b27e3
Minor formatting fixes.
ernestum Aug 14, 2023
85bbce2
Fix trailing whitespace.
ernestum Aug 14, 2023
ab4f182
Black fixes.
ernestum Aug 14, 2023
73666a1
Explicitly seed dummy environment.
ernestum Aug 14, 2023
04e4442
Remove unnecessary cast to int.
ernestum Aug 14, 2023
fd278ca
Fix some typing issues.
ernestum Aug 14, 2023
2702330
Fix more typing issues.
ernestum Aug 15, 2023
a8310d8
Simplify ObsCastWrapper by inheriting from gym.ObservationWrapper ins…
ernestum Aug 15, 2023
e0d954f
Small typos in docstrings.
ernestum Aug 15, 2023
d1e4f1a
Add reset info when generating rollouts.
ernestum Aug 15, 2023
36041d7
Remove unneeded default params to rand_gen.normal()
ernestum Aug 15, 2023
52bffb6
Remove unneeded setter for the observation space property in a Resett…
ernestum Aug 15, 2023
9ea13ba
Ignore coverage for edge cases of where the observation space has no …
ernestum Aug 15, 2023
d7cbaa3
Add a test case that ensures that options in the reset to a Resettabl…
ernestum Aug 15, 2023
c990834
Remove rand_state property of ResettablePOMDP and use the canonical n…
ernestum Aug 15, 2023
63009af
Remove newline in base_envs.py
ernestum Aug 15, 2023
6ee0aa9
Fix type annotations of FixedHorizonCartPole.reset()
ernestum Aug 15, 2023
63a7638
Remove leftover usages of rand_state.
ernestum Aug 15, 2023
9d73770
Fix quicks in dependencies that are no longer needed.
ernestum Aug 28, 2023
e137c24
Store unused info in _
ernestum Aug 28, 2023
b730bf3
Make test_sample_distribution by seeding the used rng instead of sett…
ernestum Aug 28, 2023
21f33dd
Add missing test dependency.
ernestum Aug 28, 2023
7353fcb
Ensure we have the newest pip version to make the dependency resoluti…
ernestum Aug 29, 2023
1cd4530
Make the dependencies cache also dependent on ci/build_venv.sh
ernestum Aug 29, 2023
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
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ orbs:

defaults: &defaults
docker:
- image: humancompatibleai/seals:base
- image: humancompatibleai/seals:base-alpha
auth:
username: $DOCKERHUB_USERNAME
password: $DOCKERHUB_PASSWORD
Expand Down
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# base stage contains just binary dependencies.
# This is used in the CI build.
FROM nvidia/cuda:10.0-runtime-ubuntu18.04 AS base
FROM nvidia/cuda:11.8.0-cudnn8-runtime-ubuntu20.04 AS base
ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get update -q \
Expand All @@ -9,6 +9,7 @@ RUN apt-get update -q \
curl \
ffmpeg \
git \
ssh \
libgl1-mesa-dev \
libgl1-mesa-glx \
libglew-dev \
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ All *seals* environments are available in the Gym registry. Simply import it and
would with your usual RL or specification learning algroithm:

```python
import gym
import gymnasium as gym
import seals

env = gym.make('seals/CartPole-v0')
Expand Down
2 changes: 1 addition & 1 deletion ci/Xdummy-entrypoint.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/python3

# Adapted from https://github.com/openai/mujoco-py/blob/master/vendor/Xdummy-entrypoint
# Copyright OpenAI; MIT License
Expand Down
5 changes: 1 addition & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,5 @@ build-backend = "setuptools.build_meta"
target-version = ["py38"]

[[tool.mypy.overrides]]
module = [
"gym.*",
"setuptools_scm.*",
]
module = ["gym.*", "setuptools_scm.*"]
ignore_missing_imports = true
19 changes: 10 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,10 @@ def get_readme() -> str:

ATARI_REQUIRE = [
"opencv-python",
"ale-py==0.7.4",
"ale-py~=0.8.1",
"pillow",
"autorom[accept-rom-license]~=0.4.2",
"shimmy[atari] >=0.1.0,<1.0",
]
TESTS_REQUIRE = [
# remove pin once https://github.com/nedbat/coveragepy/issues/881 fixed
Expand All @@ -115,11 +116,11 @@ def get_readme() -> str:
"pytest-xdist",
"pytype",
"stable-baselines3>=0.9.0",
# TODO(adam): remove pyglet pin once Gym upgraded to >0.21
# Workaround for https://github.com/openai/gym/issues/2986
# Discussed in https://github.com/HumanCompatibleAI/imitation/pull/603
"pyglet==1.5.27",
"setuptools_scm~=7.0.5",
# We'd like to specify `gymnasium[classic-control]`, but this is a no-op when
# gymnasium is already installed. See https://github.com/pypa/pip/issues/4957 for
ernestum marked this conversation as resolved.
Show resolved Hide resolved
# issue.
"pygame>=2.1.3",
*ATARI_REQUIRE,
]
DOCS_REQUIRE = [
Expand All @@ -140,16 +141,16 @@ def get_readme() -> str:
packages=find_packages("src"),
package_dir={"": "src"},
package_data={"seals": ["py.typed"]},
install_requires=["gym", "numpy"],
install_requires=["gymnasium", "numpy"],
tests_require=TESTS_REQUIRE,
extras_require={
# recommended packages for development
"dev": ["ipdb", "jupyter", *TESTS_REQUIRE, *DOCS_REQUIRE],
"docs": DOCS_REQUIRE,
"test": TESTS_REQUIRE,
# We'd like to specify `gym[mujoco]`, but this is a no-op when Gym is already
# installed. See https://github.com/pypa/pip/issues/4957 for issue.
"mujoco": ["mujoco_py>=1.50, <2.0", "imageio"],
# We'd like to specify `gymnasium[mujoco]`, but this is a no-op when gymnasium
# is already installed. See https://github.com/pypa/pip/issues/4957 for issue.
"mujoco": ["mujoco", "imageio"],
ernestum marked this conversation as resolved.
Show resolved Hide resolved
"atari": ATARI_REQUIRE,
},
url="https://github.com/HumanCompatibleAI/benchmark-environments",
Expand Down
8 changes: 4 additions & 4 deletions src/seals/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from importlib import metadata

import gym
import gymnasium as gym

from seals import atari, util
import seals.diagnostics # noqa: F401
Expand Down Expand Up @@ -31,12 +31,12 @@

for env_base in ["Ant", "HalfCheetah", "Hopper", "Humanoid", "Swimmer", "Walker2d"]:
gym.register(
id=f"seals/{env_base}-v0",
id=f"seals/{env_base}-v1",
entry_point=f"seals.mujoco:{env_base}Env",
max_episode_steps=util.get_gym_max_episode_steps(f"{env_base}-v3"),
max_episode_steps=util.get_gym_max_episode_steps(f"{env_base}-v4"),
)

# Atari

GYM_ATARI_ENV_SPECS = list(filter(atari._supported_atari_env, gym.envs.registry.all()))
GYM_ATARI_ENV_SPECS = list(filter(atari._supported_atari_env, gym.registry.values()))
atari.register_atari_envs(GYM_ATARI_ENV_SPECS)
21 changes: 11 additions & 10 deletions src/seals/atari.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

from typing import Dict, Iterable, Optional

import gym
import gymnasium as gym
from gymnasium.envs.registration import EnvSpec

from seals.util import (
AutoResetWrapper,
Expand Down Expand Up @@ -35,9 +36,9 @@ def _get_score_region(atari_env_id: str) -> Optional[MaskedRegionSpecifier]:
return SCORE_REGIONS.get(basename)


def make_atari_env(atari_env_id: str, masked: bool) -> gym.Env:
def make_atari_env(atari_env_id: str, masked: bool, *args, **kwargs) -> gym.Env:
"""Fixed-length, optionally masked-score variant of a given Atari environment."""
env = AutoResetWrapper(gym.make(atari_env_id))
env: gym.Env = AutoResetWrapper(gym.make(atari_env_id, *args, **kwargs))

if masked:
score_region = _get_score_region(atari_env_id)
Expand All @@ -59,15 +60,15 @@ def _not_ram_or_det(env_id: str) -> bool:
after_slash = slash_separated[-1]
hyphen_separated = after_slash.split("-")
assert len(hyphen_separated) > 1
not_ram = not ("ram" in hyphen_separated[1])
not_deterministic = not ("Deterministic" in env_id)
not_ram = "ram" not in hyphen_separated[1]
not_deterministic = "Deterministic" not in env_id
return not_ram and not_deterministic


def _supported_atari_env(gym_spec: gym.envs.registration.EnvSpec) -> bool:
def _supported_atari_env(gym_spec: EnvSpec) -> bool:
"""Checks if a gym Atari environment is one of the ones we will support."""
is_atari = gym_spec.entry_point == "gym.envs.atari:AtariEnv"
v5_and_plain = gym_spec.id.endswith("-v5") and not ("NoFrameskip" in gym_spec.id)
is_atari = gym_spec.entry_point == "shimmy.atari_env:AtariEnv"
v5_and_plain = gym_spec.id.endswith("-v5") and "NoFrameskip" not in gym_spec.id
v4_and_no_frameskip = gym_spec.id.endswith("-v4") and "NoFrameskip" in gym_spec.id
return (
is_atari
Expand All @@ -76,7 +77,7 @@ def _supported_atari_env(gym_spec: gym.envs.registration.EnvSpec) -> bool:
)


def _seals_name(gym_spec: gym.envs.registration.EnvSpec, masked: bool) -> str:
def _seals_name(gym_spec: EnvSpec, masked: bool) -> str:
"""Makes a Gym ID for an Atari environment in the seals namespace."""
slash_separated = gym_spec.id.split("/")
name = "seals/" + slash_separated[-1]
Expand All @@ -88,7 +89,7 @@ def _seals_name(gym_spec: gym.envs.registration.EnvSpec, masked: bool) -> str:


def register_atari_envs(
gym_atari_env_specs: Iterable[gym.envs.registration.EnvSpec],
gym_atari_env_specs: Iterable[EnvSpec],
) -> None:
"""Register masked and unmasked wrapped gym Atari environments."""

Expand Down
Loading