Starts the viewer with the specified policy and environment. Args: environment_loader: Either a callable that takes no arguments and returns an instance of dm_control.rl.control.Environment, or an instance of dm_control.rl.control.Environment. policy: An optional cal
(self, environment_loader, policy=None)
| 302 | self._runtime.single_step() |
| 303 | |
| 304 | def launch(self, environment_loader, policy=None): |
| 305 | """Starts the viewer with the specified policy and environment. |
| 306 | |
| 307 | Args: |
| 308 | environment_loader: Either a callable that takes no arguments and returns |
| 309 | an instance of dm_control.rl.control.Environment, or an instance of |
| 310 | dm_control.rl.control.Environment. |
| 311 | policy: An optional callable corresponding to a policy to execute |
| 312 | within the environment. It should accept a `TimeStep` and return |
| 313 | a numpy array of actions conforming to the output of |
| 314 | `environment.action_spec()`. If the callable implements a method `reset` |
| 315 | then this method is called when the viewer is reset. |
| 316 | |
| 317 | Raises: |
| 318 | ValueError: If `environment_loader` is None. |
| 319 | """ |
| 320 | if environment_loader is None: |
| 321 | raise ValueError('"environment_loader" argument is required.') |
| 322 | if callable(environment_loader): |
| 323 | self._environment_loader = environment_loader |
| 324 | else: |
| 325 | self._environment_loader = lambda: environment_loader |
| 326 | self._policy = policy |
| 327 | self._load_environment(zoom_to_scene=True) |
| 328 | def tick(): |
| 329 | self._viewport.set_size(*self._window.shape) |
| 330 | self._tick() |
| 331 | return self._renderer.pixels |
| 332 | self._window.event_loop(tick_func=tick) |
| 333 | self._window.close() |