DM-Control

1.0.39 · active · verified Thu Apr 16

DM-Control is a Python library from Google DeepMind that provides continuous control environments and Python bindings for the MuJoCo physics engine. It's widely used in reinforcement learning research for creating and interacting with physically realistic simulated agents. The library is actively maintained with frequent releases, often tied to updates in the underlying MuJoCo engine.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart loads the 'cartpole/balance' environment and attempts to launch the interactive viewer. The viewer requires the `dm-control[viewer]` extra and a system-wide GLFW installation (e.g., `libglfw3` on Linux). If GLFW is not set up, the viewer might fail, but the environment can still be interacted with programmatically.

import os
from dm_control import suite
from dm_control import viewer

# Load a standard control environment
env = suite.load(domain_name="cartpole", task_name="balance")

# Create a viewer application
# Note: Requires system-level GLFW installation for the viewer to work
# e.g., `sudo apt-get install libglfw3` on Linux or `brew install glfw` on macOS
if os.environ.get('DM_CONTROL_NO_VIEWER') != 'true':
    try:
        viewer.launch(env)
    except Exception as e:
        print(f"Could not launch viewer: {e}")
        print("Try running without viewer by setting environment variable DM_CONTROL_NO_VIEWER=true")
        print("Or ensure GLFW is installed: `pip install dm-control[viewer]` and system-level `libglfw3`.")
else:
    print("Viewer explicitly disabled via DM_CONTROL_NO_VIEWER environment variable.")
    # Or, manually step through the environment:
    # action_spec = env.action_spec()
    # time_step = env.reset()
    # while not time_step.last():
    #     action = 0.0 # Example: apply zero action
    #     time_step = env.step(action)

view raw JSON →