updated to new API, so tests still failing

This commit is contained in:
Fabian
2023-01-17 08:27:29 +01:00
parent ec2063aa0b
commit c53924d9fc
9 changed files with 49 additions and 27 deletions
+11
View File
@@ -0,0 +1,11 @@
import gymnasium as gym
class EnvCompatibility(gym.wrappers.EnvCompatibility):
def __getattr__(self, item):
"""Propagate only non-existent properties to wrapped env."""
if item.startswith('_'):
raise AttributeError("attempted to get missing private attribute '{}'".format(item))
if item in self.__dict__:
return getattr(self, item)
return getattr(self.env, item)
+6 -4
View File
@@ -3,12 +3,14 @@ import uuid
from collections.abc import MutableMapping
from copy import deepcopy
from math import ceil
from typing import Iterable, Type, Union
from typing import Iterable, Type, Union, Optional
import gymnasium as gym
import numpy as np
from gymnasium.envs.registration import register, registry
from fancy_gym.utils.env_compatibility import EnvCompatibility
try:
from dm_control import suite, manipulation
from shimmy.dm_control_compatibility import EnvType
@@ -186,9 +188,9 @@ def make_bb(
def get_env_duration(env: gym.Env):
try:
# TODO Remove if this is in the compatibility class
duration = env.spec.max_episode_steps * env.dt
except (AttributeError, TypeError) as e:
# TODO Remove if this information is in the compatibility class
logging.error(f'Attributes env.spec.max_episode_steps and env.dt are not available. '
f'Assuming you are using dm_control. Please make sure you have ran '
f'"pip install shimmy[dm_control]" for that.')
@@ -300,7 +302,7 @@ def make_bb_env_helper(**kwargs):
# return env
def make_metaworld(env_id: str, seed: int, **kwargs):
def make_metaworld(env_id: str, seed: int, render_mode: Optional[str] = None, **kwargs):
if env_id not in metaworld.ML1.ENV_NAMES:
raise ValueError(f'Specified environment "{env_id}" not present in metaworld ML1.')
@@ -314,7 +316,7 @@ def make_metaworld(env_id: str, seed: int, **kwargs):
max_episode_steps = _env.max_path_length
# TODO remove this as soon as there is support for the new API
_env = gym.wrappers.EnvCompatibility(_env)
_env = EnvCompatibility(_env, render_mode)
gym_id = uuid.uuid4().hex + '-v1'