Skip to content

Commit

Permalink
Add shimmy for atari and removes the gym compatibility for the shimmy…
Browse files Browse the repository at this point in the history
… versions (#125)
  • Loading branch information
pseudo-rnd-thoughts authored Dec 1, 2022
1 parent 203e4e7 commit 320b52c
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 249 deletions.
23 changes: 11 additions & 12 deletions gymnasium/envs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
from gymnasium.envs.registration import load_env_plugins as _load_env_plugins
from gymnasium.envs.registration import make, pprint_registry, register, registry, spec

# Hook to load plugins from entry points
_load_env_plugins()

"""Registers the internal gym envs then loads the env plugins for module using the entry point."""
from gymnasium.envs.registration import (
load_env_plugins,
make,
pprint_registry,
register,
registry,
spec,
)

# Classic
# ----------------------------------------
Expand Down Expand Up @@ -344,9 +347,5 @@
)


# Gym conversion
# ----------------------------------------
register(
id="GymV26Environment-v0",
entry_point="gymnasium.envs.external.gym_env:GymEnvironment",
)
# Hook to load plugins from entry points
load_env_plugins()
Empty file.
159 changes: 0 additions & 159 deletions gymnasium/envs/external/gym_env.py

This file was deleted.

5 changes: 5 additions & 0 deletions gymnasium/wrappers/compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import Any, Dict, Optional, Tuple

import gymnasium as gym
from gymnasium import logger
from gymnasium.core import ObsType
from gymnasium.utils.step_api_compatibility import (
convert_to_terminated_truncated_step_api,
Expand Down Expand Up @@ -62,6 +63,10 @@ def __init__(self, old_env: LegacyEnv, render_mode: Optional[str] = None):
old_env (LegacyEnv): the env to wrap, implemented with the old API
render_mode (str): the render mode to use when rendering the environment, passed automatically to env.render
"""
logger.warn(
"The `gymnasium.make(..., apply_api_compatibility=...)` parameter is deprecated and will be removed in v28. "
"Instead use `gym.make('GymV22Environment-v0', env_name=...)` or `from shimmy import GymV26CompatibilityV0`"
)
self.metadata = getattr(old_env, "metadata", {"render_modes": []})
self.render_mode = render_mode
self.reward_range = getattr(old_env, "reward_range", None)
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def get_version():

# Environment-specific dependencies.
extras = {
"atari": ["ale-py~=0.8.0"],
"atari": ["shimmy[atari]>=0.1.0,<1.0"],
"accept-rom-license": ["autorom[accept-rom-license]~=0.4.2"],
"box2d": ["box2d-py==2.3.5", "pygame==2.1.0", "swig==4.*"],
"classic_control": ["pygame==2.1.0"],
Expand All @@ -46,7 +46,6 @@ def get_version():

extras["testing"] = list(set(itertools.chain.from_iterable(extras.values()))) + [
"pytest==7.1.3",
"gym[classic_control, mujoco_py, mujoco, toy_text, other, atari, accept-rom-license]==0.26.2",
]

# All dependency groups - accept rom license as requires user to run
Expand Down Expand Up @@ -90,6 +89,7 @@ def get_version():
"cloudpickle >= 1.2.0",
"importlib_metadata >= 4.8.0; python_version < '3.10'",
"gymnasium_notices >= 0.0.1",
"shimmy>=0.1.0, <1.0",
],
classifiers=[
"Programming Language :: Python :: 3",
Expand Down
43 changes: 0 additions & 43 deletions tests/envs/test_gym_conversion.py

This file was deleted.

68 changes: 40 additions & 28 deletions tests/envs/test_make.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,33 +22,45 @@
from tests.testing_env import GenericTestEnv, old_step_fn
from tests.wrappers.utils import has_wrapper

gym.register(
"RegisterDuringMakeEnv-v0",
entry_point="tests.envs.utils_envs:RegisterDuringMakeEnv",
)

gym.register(
id="test.ArgumentEnv-v0",
entry_point="tests.envs.utils_envs:ArgumentEnv",
kwargs={
"arg1": "arg1",
"arg2": "arg2",
},
)
@pytest.fixture(scope="function")
def register_make_testing_envs():
"""Registers testing envs for `gym.make`"""
gym.register(
"RegisterDuringMakeEnv-v0",
entry_point="tests.envs.utils_envs:RegisterDuringMakeEnv",
)

gym.register(
id="test/NoHuman-v0",
entry_point="tests.envs.utils_envs:NoHuman",
)
gym.register(
id="test/NoHumanOldAPI-v0",
entry_point="tests.envs.utils_envs:NoHumanOldAPI",
)
gym.register(
id="test.ArgumentEnv-v0",
entry_point="tests.envs.utils_envs:ArgumentEnv",
kwargs={
"arg1": "arg1",
"arg2": "arg2",
},
)

gym.register(
id="test/NoHumanNoRGB-v0",
entry_point="tests.envs.utils_envs:NoHumanNoRGB",
)
gym.register(
id="test/NoHuman-v0",
entry_point="tests.envs.utils_envs:NoHuman",
)
gym.register(
id="test/NoHumanOldAPI-v0",
entry_point="tests.envs.utils_envs:NoHumanOldAPI",
)

gym.register(
id="test/NoHumanNoRGB-v0",
entry_point="tests.envs.utils_envs:NoHumanNoRGB",
)

yield

del gym.envs.registration.registry["RegisterDuringMakeEnv-v0"]
del gym.envs.registration.registry["test.ArgumentEnv-v0"]
del gym.envs.registration.registry["test/NoHuman-v0"]
del gym.envs.registration.registry["test/NoHumanOldAPI-v0"]
del gym.envs.registration.registry["test/NoHumanNoRGB-v0"]


def test_make():
Expand All @@ -70,7 +82,7 @@ def test_make_deprecated():
gym.make("Humanoid-v0", disable_env_checker=True)


def test_make_max_episode_steps():
def test_make_max_episode_steps(register_make_testing_envs):
# Default, uses the spec's
env = gym.make("CartPole-v1", disable_env_checker=True)
assert has_wrapper(env, TimeLimit)
Expand Down Expand Up @@ -208,7 +220,7 @@ def test_make_order_enforcing():
env.close()


def test_make_render_mode():
def test_make_render_mode(register_make_testing_envs):
env = gym.make("CartPole-v1", disable_env_checker=True)
assert env.render_mode is None
env.close()
Expand Down Expand Up @@ -293,7 +305,7 @@ def test_make_render_mode():
gym.make("CarRacing-v2", render="human")


def test_make_kwargs():
def test_make_kwargs(register_make_testing_envs):
env = gym.make(
"test.ArgumentEnv-v0",
arg2="override_arg2",
Expand All @@ -309,7 +321,7 @@ def test_make_kwargs():
env.close()


def test_import_module_during_make():
def test_import_module_during_make(register_make_testing_envs):
# Test custom environment which is registered at make
env = gym.make(
"tests.envs.utils:RegisterDuringMakeEnv-v0",
Expand Down
Loading

0 comments on commit 320b52c

Please sign in to comment.