From fb22b257b6f0e4e40aedb8de3c1f9e81e6008ab9 Mon Sep 17 00:00:00 2001 From: Theresa Eimer Date: Mon, 11 Dec 2023 13:42:04 +0100 Subject: [PATCH] fully move dmc to gymnasium --- carl/__init__.py | 9 ++++++++- carl/envs/dmc/wrappers.py | 4 ++-- test/test_gymnasium_envs.py | 4 ++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/carl/__init__.py b/carl/__init__.py index b2d3d700..fa63768c 100644 --- a/carl/__init__.py +++ b/carl/__init__.py @@ -58,7 +58,6 @@ def check_spec(spec_name: str) -> bool: ) return found - # Environment loading found = check_spec("Box2D") if found: for e in envs.gymnasium.box2d.__all__: @@ -67,6 +66,14 @@ def check_spec(spec_name: str) -> bool: entry_point=f"carl.envs.gymnasium.box2d:{e}", ) + found = check_spec("dm_control") + if found: + for e in envs.dmc.__all__: + register( + id=f"carl/{e}-v0", + entry_point=f"carl.envs.dmc:{e}", + ) + found = check_spec("py4j") if found: register( diff --git a/carl/envs/dmc/wrappers.py b/carl/envs/dmc/wrappers.py index 7ac9a059..665e5c26 100644 --- a/carl/envs/dmc/wrappers.py +++ b/carl/envs/dmc/wrappers.py @@ -1,10 +1,10 @@ from typing import Any, Optional, Tuple, TypeVar, Union import dm_env # type: ignore -import gym +import gymnasium as gym import numpy as np from dm_env import StepType -from gym import spaces +from gymnasium import spaces ObsType = TypeVar("ObsType") ActType = TypeVar("ActType") diff --git a/test/test_gymnasium_envs.py b/test/test_gymnasium_envs.py index e2c6ddd0..246f002e 100644 --- a/test/test_gymnasium_envs.py +++ b/test/test_gymnasium_envs.py @@ -27,13 +27,13 @@ class TestGymnasiumRegistration(unittest.TestCase): def test_registration(self): registered_envs = gym.envs.registration.registry.keys() for e in carl.envs.__all__: - if "RNA" not in e and "Brax" not in e and "Dmc" not in e: + if "RNA" not in e and "Brax" not in e: env_name = f"carl/{e}-v0" self.assertTrue(env_name in registered_envs) def test_make(self): for e in carl.envs.__all__: - if "RNA" not in e and "Brax" not in e and "Dmc" not in e: + if "RNA" not in e and "Brax" not in e: env_name = f"carl/{e}-v0" env = gym.make(env_name) self.assertTrue(isinstance(env, gym.Env))