From 92f1f409f3ac917fc4b902864a10f66be53b66ec Mon Sep 17 00:00:00 2001 From: ottofabian Date: Fri, 2 Jul 2021 18:18:11 +0200 Subject: [PATCH] fixed minor back with __getattr__ --- alr_envs/examples/examples_general.py | 8 ++++---- alr_envs/utils/dmc2gym_wrapper.py | 10 +++++++--- setup.py | 2 +- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/alr_envs/examples/examples_general.py b/alr_envs/examples/examples_general.py index 99ca8f6..2e5fda7 100644 --- a/alr_envs/examples/examples_general.py +++ b/alr_envs/examples/examples_general.py @@ -87,16 +87,16 @@ def example_async(env_id="alr_envs:HoleReacher-v0", n_cpu=4, seed=int('533D', 16 if __name__ == '__main__': # Basic gym task - # example_general("Pendulum-v0", seed=10, iterations=200, render=True) + example_general("Pendulum-v0", seed=10, iterations=200, render=True) # # # Basis task from framework - # example_general("alr_envs:HoleReacher-v0", seed=10, iterations=200, render=True) + example_general("alr_envs:HoleReacher-v0", seed=10, iterations=200, render=True) # # # OpenAI Mujoco task - # example_general("HalfCheetah-v2", seed=10, render=True) + example_general("HalfCheetah-v2", seed=10, render=True) # # # Mujoco task from framework - # example_general("alr_envs:ALRReacher-v0", seed=10, iterations=200, render=True) + example_general("alr_envs:ALRReacher-v0", seed=10, iterations=200, render=True) # Vectorized multiprocessing environments example_async(env_id="alr_envs:HoleReacher-v0", n_cpu=2, seed=int('533D', 16), n_samples=2 * 200) diff --git a/alr_envs/utils/dmc2gym_wrapper.py b/alr_envs/utils/dmc2gym_wrapper.py index d1226e4..cb3658d 100644 --- a/alr_envs/utils/dmc2gym_wrapper.py +++ b/alr_envs/utils/dmc2gym_wrapper.py @@ -91,9 +91,13 @@ class DMCWrapper(core.Env): # set seed self.seed(seed=task_kwargs.get('random', 1)) - def __getattr__(self, name): - """Delegate attribute access to underlying environment.""" - return getattr(self._env, name) + 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) def _get_obs(self, time_step): if self._from_pixels: diff --git a/setup.py b/setup.py index 7170fa6..b30ce41 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ setup( 'gym', 'PyQt5', 'matplotlib', - 'mp_env_api @ git+ssh://git@github.com/ALRhub/motion_primitive_env_api.git', + # 'mp_env_api @ git+ssh://git@github.com/ALRhub/motion_primitive_env_api.git', 'mujoco_py' ],