From 15e1bdc218cae39fe6272a421ce207c70cd4e2ed Mon Sep 17 00:00:00 2001 From: Dominik Roth Date: Mon, 28 Aug 2023 16:18:18 +0200 Subject: [PATCH] Mitigation: Allow seeding Metaworld on reset --- fancy_gym/meta/metaworld_adapter.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/fancy_gym/meta/metaworld_adapter.py b/fancy_gym/meta/metaworld_adapter.py index a898a93..f7f3251 100644 --- a/fancy_gym/meta/metaworld_adapter.py +++ b/fancy_gym/meta/metaworld_adapter.py @@ -50,6 +50,18 @@ class MitigateMetaworldBug(gym.Wrapper, gym.utils.RecordConstructorArgs): return ret +class MetaworldResetFix(gym.Wrapper, gym.utils.RecordConstructorArgs): + def __init__(self, env: gym.Env): + gym.utils.RecordConstructorArgs.__init__(self) + gym.Wrapper.__init__(self, env) + + def reset(self, **kwargs): + ret = self.env.reset(**kwargs) + if 'seed' in kwargs: + self.env.seed(kwargs['seed']) + 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.') @@ -79,6 +91,7 @@ def make_metaworld(underlying_id: str, seed: int = 1, render_mode: Optional[str] env = MujocoMapSpacesWrapper(env) # TODO remove, when this has been fixed upstream env = MitigateMetaworldBug(env) + env = MetaworldResetFix(env) return env