From 04925035f95412176a6c08e29fb4a46c5861c0e8 Mon Sep 17 00:00:00 2001 From: Dominik Roth Date: Wed, 13 Dec 2023 17:02:52 +0100 Subject: [PATCH 1/2] Metaworld did not allow rendering since render_mode was not passed through comparability adapter. --- fancy_gym/meta/metaworld_adapter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fancy_gym/meta/metaworld_adapter.py b/fancy_gym/meta/metaworld_adapter.py index 7853378..20519d5 100644 --- a/fancy_gym/meta/metaworld_adapter.py +++ b/fancy_gym/meta/metaworld_adapter.py @@ -61,7 +61,7 @@ def make_metaworld(underlying_id: str, seed: int = 1, render_mode: Optional[str] if underlying_id not in metaworld.ML1.ENV_NAMES: raise ValueError(f'Specified environment "{underlying_id}" not present in metaworld ML1.') - env = metaworld.envs.ALL_V2_ENVIRONMENTS_GOAL_OBSERVABLE[underlying_id + "-goal-observable"](seed=seed, **kwargs) + env = metaworld.envs.ALL_V2_ENVIRONMENTS_GOAL_OBSERVABLE[underlying_id + "-goal-observable"](seed=seed, render_mode=render_mode, **kwargs) # setting this avoids generating the same initialization after each reset env._freeze_rand_vec = False From 8672856e00ec8073d1d420d6f62eff285b3066ba Mon Sep 17 00:00:00 2001 From: Dominik Roth Date: Sat, 10 Feb 2024 09:22:06 +0100 Subject: [PATCH 2/2] Fix: Ensure automatic rendering on .step if render was called initially (new gym spec) --- fancy_gym/meta/metaworld_adapter.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/fancy_gym/meta/metaworld_adapter.py b/fancy_gym/meta/metaworld_adapter.py index 20519d5..8685cad 100644 --- a/fancy_gym/meta/metaworld_adapter.py +++ b/fancy_gym/meta/metaworld_adapter.py @@ -51,12 +51,29 @@ class FixMetaworldIgnoresSeedOnResetWrapper(gym.Wrapper, gym.utils.RecordConstru gym.Wrapper.__init__(self, env) def reset(self, **kwargs): - print('[!] You just called .reset on a Metaworld env and supplied a seed. Metaworld curretly does not correctly implement seeding. Do not rely on deterministic behavior.') if 'seed' in kwargs: + print('[!] You just called .reset on a Metaworld env and supplied a seed. Metaworld curretly does not correctly implement seeding. Do not rely on deterministic behavior.') self.env.seed(kwargs['seed']) return self.env.reset(**kwargs) +class FixMetaworldRenderOnStep(gym.Wrapper, gym.utils.RecordConstructorArgs): + def __init__(self, env: gym.Env): + gym.utils.RecordConstructorArgs.__init__(self) + gym.Wrapper.__init__(self, env) + self.render_active = False + + def render(self, *args, **kwargs): + self.render_active = True + return self.env.render(*args, **kwargs) + + def step(self, *args, **kwargs): + ret = self.env.step(*args, **kwargs) + if self.render_active: + self.env.render() + return ret + + def make_metaworld(underlying_id: str, seed: int = 1, render_mode: Optional[str] = None, **kwargs): if underlying_id not in metaworld.ML1.ENV_NAMES: raise ValueError(f'Specified environment "{underlying_id}" not present in metaworld ML1.') @@ -68,11 +85,9 @@ def make_metaworld(underlying_id: str, seed: int = 1, render_mode: Optional[str] # New argument to use global seeding env.seeded_rand_vec = True - # TODO remove, when this has been fixed upstream env = FixMetaworldHasIncorrectObsSpaceWrapper(env) - # TODO remove, when this has been fixed upstream # env = FixMetaworldIncorrectResetPathLengthWrapper(env) - # TODO remove, when this has been fixed upstream + env = FixMetaworldRenderOnStep(env) env = FixMetaworldIgnoresSeedOnResetWrapper(env) return env