Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions docs/environments.md
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,25 @@ The OpenEnv community has built a catalog of ready-to-run environments that cove
</div>
</div>

<div class="environment-card">
<div class="environment-card__body">
<span class="environment-card__tag">dm_control</span>
<p class="environment-card__description">
MuJoCo-based continuous control tasks from DeepMind's dm_control suite — cartpole, hopper, quadruped, walker, and more.
</p>
</div>
<div class="environment-card__links">
<a class="environment-card__icon" href="/OpenEnv/environments/dm-control/" aria-label="dm_control docs">
<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false">
<path d="M6 3c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V9l-6-6H6zm8 1.5L18.5 9H14V4.5z" fill="currentColor"/>
</svg>
</a>
<a class="environment-card__icon environment-card__icon--hf" href="https://huggingface.co/spaces/mreso/dm_control_env" target="_blank" rel="noreferrer noopener" aria-label="dm_control on Hugging Face">
<img src="https://huggingface.co/front/assets/huggingface_logo-noborder.svg" alt="" aria-hidden="true" />
</a>
</div>
</div>



</div>
Expand Down
1 change: 1 addition & 0 deletions docs/environments/dm-control.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--8<-- "../../envs/dm_control_env/README.md"
167 changes: 167 additions & 0 deletions envs/dm_control_env/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
---
title: dm_control Environment Server
emoji: 🤖
colorFrom: green
colorTo: blue
sdk: docker
pinned: false
app_port: 8000
base_path: /web
tags:
- openenv
---

# dm_control OpenEnv Environment

A generic OpenEnv environment for [dm_control.suite](https://github.com/google-deepmind/dm_control), providing access to all MuJoCo-based continuous control tasks.

<p align="center">
<img src="assets/cartpole.png" width="45%" alt="Cartpole Balance"/>
<img src="assets/quadruped.png" width="45%" alt="Quadruped Walk"/>
</p>

## Supported Environments

| Domain | Tasks |
|--------|-------|
| cartpole | balance, swingup, swingup_sparse |
| walker | stand, walk, run |
| humanoid | stand, walk, run |
| cheetah | run |
| hopper | stand, hop |
| reacher | easy, hard |
| pendulum | swingup |
| finger | spin, turn_easy, turn_hard |
| fish | upright, swim |
| ball_in_cup | catch |
| And more... | See `dm_control.suite.BENCHMARKING` |

## Quick Start

### Using the Client

```python
from envs.dm_control_env import DMControlEnv, DMControlAction

# Connect to a running server
with DMControlEnv(base_url="http://localhost:8000") as env:
# Reset with default (cartpole/balance)
result = env.reset()
print(f"Observations: {result.observation.observations.keys()}")

# Take actions
for _ in range(100):
action = DMControlAction(values=[0.5]) # Push cart right
result = env.step(action)
print(f"Reward: {result.reward}, Done: {result.done}")

if result.done:
result = env.reset()
```

### Switching Environments

```python
# Start with cartpole
result = env.reset(domain_name="cartpole", task_name="balance")

# Switch to walker (on next reset)
result = env.reset(domain_name="walker", task_name="walk")
# Note: walker has 6 action dimensions
action = DMControlAction(values=[0.0] * 6)
result = env.step(action)
```

### Running the Server

```bash
# From OpenEnv root
cd envs/dm_control_env
uvicorn server.app:app --host 0.0.0.0 --port 8000

# Or using uv
uv run --project . server
```

### Using Docker

```bash
# Build
docker build -t dm_control:latest -f server/Dockerfile .

# Run
docker run -p 8000:8000 dm_control:latest
```

## API

### Action

```python
class DMControlAction(Action):
values: List[float] # Continuous action values
```

Action dimensions vary by environment:
- cartpole: 1 (force on cart)
- walker: 6 (joint torques)
- humanoid: 21 (joint torques)

### Observation

```python
class DMControlObservation(Observation):
observations: Dict[str, List[float]] # Named observation arrays
pixels: Optional[str] # Base64 PNG (if render=True)
reward: float
done: bool
```

### State

```python
class DMControlState(State):
domain_name: str
task_name: str
action_spec: Dict[str, Any]
observation_spec: Dict[str, Any]
physics_timestep: float
control_timestep: float
episode_id: str
step_count: int
```

## Examples

See the `examples/` directory:
- `cartpole_control.py` - Interactive cartpole control with arrow keys
- `hopper_control.py` - Interactive hopper control with spacebar for random forces
- `quadruped_control.py` - Interactive quadruped control with spacebar for random forces
- `list_environments.py` - Print all available environments

All examples support consistent CLI arguments:

```bash
# Default: interactive mode with minimal pygame window
python examples/cartpole_control.py

# Visual mode with rendered MuJoCo frames
python examples/cartpole_control.py --visual

# Headless mode (no pygame, automated control)
python examples/cartpole_control.py --headless --max-steps 500

# Select a different task
python examples/cartpole_control.py --task swingup
python examples/hopper_control.py --task stand
python examples/quadruped_control.py --task run
```

## Environment Variables

| Variable | Default | Description |
|----------|---------|-------------|
| `DMCONTROL_DOMAIN` | cartpole | Default domain |
| `DMCONTROL_TASK` | balance | Default task |
| `DMCONTROL_RENDER_HEIGHT` | 480 | Render height |
| `DMCONTROL_RENDER_WIDTH` | 640 | Render width |
14 changes: 14 additions & 0 deletions envs/dm_control_env/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""dm_control OpenEnv Environment.

A generic OpenEnv environment for dm_control.suite supporting all domains/tasks.
"""

from .models import DMControlAction, DMControlObservation, DMControlState
from .client import DMControlEnv

__all__ = [
"DMControlAction",
"DMControlObservation",
"DMControlState",
"DMControlEnv",
]
Binary file added envs/dm_control_env/assets/cartpole.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added envs/dm_control_env/assets/quadruped.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading