Implementation:Google deepmind Dm control Viewer Launch
| Metadata | Value |
|---|---|
| Implementation | Viewer Launch |
| Domain | Reinforcement_Learning, Physics_Simulation, Computer_Graphics |
| Source | dm_control |
| Workflow | Control_Suite_RL_Training |
| Last Updated | 2026-02-15 00:00 GMT |
Overview
Concrete tool for launching an interactive GUI window that renders a dm_control environment in real time and optionally executes a policy for visual evaluation.
Description
The viewer.launch function is the top-level entry point for the dm_control interactive viewer. It:
- Creates an
application.Applicationinstance with the specified window title, width, and height. - Calls
app.launch(environment_loader, policy)to open a GLFW window, create the OpenGL rendering context, and enter the main event loop.
The environment_loader parameter can be either:
- A callable (zero-argument function) that returns a
dm_control.rl.control.Environment. The viewer will call this to create or recreate the environment. - An existing environment instance, which the viewer wraps in a loader internally.
The optional policy parameter is a callable that accepts a dm_env.TimeStep and returns a numpy action array. When provided, the viewer runs the policy in the loop and displays the resulting behaviour. When None, the simulation runs with zero actions (or the user can apply manual perturbations).
The viewer window supports interactive controls: camera rotation and zoom via mouse, simulation pause/resume, single-stepping, and episode reset via keyboard shortcuts.
Usage
Use this implementation when:
- You want to visually inspect a Control Suite environment or a custom dm_control environment.
- You want to evaluate a trained policy qualitatively before running full quantitative benchmarks.
- You are developing a new task and need to interactively verify physics behaviour.
Code Reference
| Attribute | Detail |
|---|---|
| Source Location | dm_control/viewer/__init__.py:L22-40
|
| Signature | viewer.launch(environment_loader, policy=None, title='Explorer', width=1024, height=768)
|
| Import | from dm_control import viewer
|
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
environment_loader |
callable or Environment | Yes | A callable returning a dm_control.rl.control.Environment, or an environment instance directly. Must not be None.
|
policy |
callable or None | No | A function policy(time_step) -> np.ndarray that selects actions. Default None (zero actions).
|
title |
str | No | Window title. Default "Explorer".
|
width |
int | No | Window width in pixels. Default 1024.
|
height |
int | No | Window height in pixels. Default 768.
|
Outputs
| Name | Type | Description |
|---|---|---|
| return | None |
The function blocks until the user closes the viewer window. It does not return a value. |
Exceptions
| Exception | Condition |
|---|---|
ValueError |
environment_loader is None.
|
Usage Examples
Launch viewer for a single environment:
from dm_control import suite
from dm_control import viewer
env = suite.load('cartpole', 'swingup')
viewer.launch(env)
Launch with an environment loader (recommended for reset support):
from dm_control import suite
from dm_control import viewer
def make_env():
return suite.load('humanoid', 'walk')
viewer.launch(make_env)
Launch with a trained policy:
from dm_control import suite
from dm_control import viewer
import numpy as np
def make_env():
return suite.load('cheetah', 'run')
def random_policy(time_step):
del time_step # unused
return np.random.uniform(-1, 1, size=(6,))
viewer.launch(make_env, policy=random_policy, title='Cheetah Runner')
Launch with a custom window size:
from dm_control import suite
from dm_control import viewer
viewer.launch(
environment_loader=lambda: suite.load('walker', 'walk'),
title='Walker Viewer',
width=1920,
height=1080,
)
Launch with a neural network policy (pseudocode):
from dm_control import suite
from dm_control import viewer
import numpy as np
# Assume `trained_model` is a loaded neural network with a predict method
# trained_model = load_model('path/to/checkpoint')
def make_env():
return suite.load('finger', 'spin')
def nn_policy(time_step):
obs = np.concatenate([v.ravel() for v in time_step.observation.values()])
return trained_model.predict(obs)
viewer.launch(make_env, policy=nn_policy, title='Finger Spin - Trained Agent')