From e321fb348a3f3816830d313fb9e1430d31830e6f Mon Sep 17 00:00:00 2001 From: Nicole Ng Date: Tue, 29 Sep 2020 01:41:08 -0700 Subject: [PATCH 1/4] Replace DMControlViewer with built-in DM viewer --- src/garage/envs/dm_control/dm_control_env.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/garage/envs/dm_control/dm_control_env.py b/src/garage/envs/dm_control/dm_control_env.py index 5c47b4634f..70963850b5 100644 --- a/src/garage/envs/dm_control/dm_control_env.py +++ b/src/garage/envs/dm_control/dm_control_env.py @@ -1,12 +1,13 @@ """DM control environment.""" import akro from dm_control import suite +from dm_control import viewer from dm_control.rl.control import flatten_observation from dm_env import StepType as dm_StepType import numpy as np from garage import Environment, EnvSpec, EnvStep, StepType -from garage.envs.dm_control.dm_control_viewer import DmControlViewer +# from garage.envs.dm_control.dm_control_viewer import DmControlViewer def _flat_shape(observation): @@ -180,14 +181,11 @@ def render(self, mode): def visualize(self): """Creates a visualization of the environment.""" if not self._viewer: - title = 'dm_control {}'.format(self._name) - self._viewer = DmControlViewer(title=title) + self._viewer = viewer self._viewer.launch(self._env) def close(self): """Close the environment.""" - if self._viewer: - self._viewer.close() self._env.close() self._viewer = None self._env = None From 6ebfe527e2cca047f40b2551510d86375545c98f Mon Sep 17 00:00:00 2001 From: Nicole Ng Date: Tue, 29 Sep 2020 01:41:08 -0700 Subject: [PATCH 2/4] Replace DMControlViewer with built-in DM viewer --- src/garage/envs/dm_control/dm_control_env.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/garage/envs/dm_control/dm_control_env.py b/src/garage/envs/dm_control/dm_control_env.py index 5c47b4634f..acee75406f 100644 --- a/src/garage/envs/dm_control/dm_control_env.py +++ b/src/garage/envs/dm_control/dm_control_env.py @@ -1,12 +1,12 @@ """DM control environment.""" import akro from dm_control import suite +from dm_control import viewer from dm_control.rl.control import flatten_observation from dm_env import StepType as dm_StepType import numpy as np from garage import Environment, EnvSpec, EnvStep, StepType -from garage.envs.dm_control.dm_control_viewer import DmControlViewer def _flat_shape(observation): @@ -180,14 +180,11 @@ def render(self, mode): def visualize(self): """Creates a visualization of the environment.""" if not self._viewer: - title = 'dm_control {}'.format(self._name) - self._viewer = DmControlViewer(title=title) + self._viewer = viewer self._viewer.launch(self._env) def close(self): """Close the environment.""" - if self._viewer: - self._viewer.close() self._env.close() self._viewer = None self._env = None From 8164d53c4f11316d072f6e89b3ed674ead69ebc3 Mon Sep 17 00:00:00 2001 From: Nicole Ng Date: Tue, 29 Sep 2020 20:03:17 -0700 Subject: [PATCH 3/4] Resolve merge conflict --- src/garage/envs/dm_control/dm_control_env.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/garage/envs/dm_control/dm_control_env.py b/src/garage/envs/dm_control/dm_control_env.py index cd7c5e89cf..acee75406f 100644 --- a/src/garage/envs/dm_control/dm_control_env.py +++ b/src/garage/envs/dm_control/dm_control_env.py @@ -7,10 +7,6 @@ import numpy as np from garage import Environment, EnvSpec, EnvStep, StepType -<<<<<<< HEAD -======= -# from garage.envs.dm_control.dm_control_viewer import DmControlViewer ->>>>>>> e321fb348a3f3816830d313fb9e1430d31830e6f def _flat_shape(observation): From 2e5ebc9a961ab7faef7dcc76e9cf4b0e13bcf7eb Mon Sep 17 00:00:00 2001 From: Nicole Ng Date: Thu, 29 Oct 2020 02:41:22 -0700 Subject: [PATCH 4/4] Delete DMControlViewer --- .../envs/dm_control/dm_control_viewer.py | 55 ------------------- 1 file changed, 55 deletions(-) delete mode 100644 src/garage/envs/dm_control/dm_control_viewer.py diff --git a/src/garage/envs/dm_control/dm_control_viewer.py b/src/garage/envs/dm_control/dm_control_viewer.py deleted file mode 100644 index dad5fef015..0000000000 --- a/src/garage/envs/dm_control/dm_control_viewer.py +++ /dev/null @@ -1,55 +0,0 @@ -""" Wrapper for the dm_control viewer which allows single-stepping """ -import dm_control.viewer.application as dm_viewer_app -import glfw - - -class DmControlViewer(dm_viewer_app.Application): - def render(self): - # Don't try to render into closed windows - if not self._window._context: - return - - self._render_once() - - # Just keep rendering if we're paused, but hold onto control flow - while self._pause_subject.value: - self._render_once() - - def _render_once(self): - # See https://github.com/deepmind/dm_control/blob/92f9913013face0468442cd0964d5973ea2089ea/dm_control/viewer/gui/glfw_gui.py#L280 # noqa: E501 - window = self._window - tick_func = self._tick_func - if (window._context - and not glfw.window_should_close(window._context.window)): - pixels = tick_func() - with window._context.make_current() as ctx: - ctx.call(window._update_gui_on_render_thread, - window._context.window, pixels) - window._mouse.process_events() - window._keyboard.process_events() - else: - window.close() - - def launch(self, environment_loader, policy=None): - # See https://github.com/deepmind/dm_control/blob/92f9913013face0468442cd0964d5973ea2089ea/dm_control/viewer/application.py#L304 # noqa: E501 - if environment_loader is None: - raise ValueError('"environment_loader" argument is required.') - if callable(environment_loader): - self._environment_loader = environment_loader - else: - self._environment_loader = lambda: environment_loader - self._policy = policy - self._load_environment(zoom_to_scene=True) - - def tick(): - self._viewport.set_size(*self._window.shape) - self._tick() - return self._renderer.pixels - - self._tick_func = tick - - # Start unpaused - self._pause_subject.value = False - - def close(self): - self._window.close()