Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Google deepmind Dm control Suite Swimmer

From Leeroopedia
Knowledge Sources
Domains Reinforcement Learning, Locomotion, Physics Simulation
Last Updated 2026-02-15 04:00 GMT

Overview

The Swimmer domain implements a procedurally generated multi-link planar swimmer that must navigate to a target, with two benchmarking tasks at 6-link and 15-link complexity levels.

Description

The Swimmer module defines a planar aquatic locomotion environment where a chain of body segments must coordinate to reach a target position. The model is procedurally generated from a base swimmer.xml template by the _make_model function, which creates a chain of n_bodies segments, each with joints (range limited to 360/n_bodies degrees), motors, velocimeters, and gyro sensors. Tracking cameras are scaled proportionally to the swimmer's length.

The Physics class extends mujoco.Physics with methods for computing the nose-to-target vector in the head's local frame, the nose-to-target distance, local body velocities (x, y linear and z rotational extracted from sensor data), and internal joint angles (excluding root joints). The Swimmer task randomizes joint angles and places a target randomly, with a 20% probability of a close target (within 0.3 units) and 80% probability of a far target (within 2.0 units).

The reward function uses rewards.tolerance() with a long_tail sigmoid on the nose-to-target distance, where the margin is 5 times the target size. Two benchmarking tasks are registered: swimmer6 (6 links) and swimmer15 (15 links), and a general swimmer(n_links) function allows arbitrary chain lengths (minimum 3).

Usage

Use this module for benchmarking locomotion algorithms at different complexity levels. The scalable chain length makes it ideal for studying how algorithms handle increasing dimensionality of action and observation spaces.

Code Reference

Source Location

Signature

def get_model_and_assets(n_joints):
    """Returns a tuple containing the model XML string and a dict of assets."""

def swimmer6(time_limit=_DEFAULT_TIME_LIMIT, random=None, environment_kwargs=None):
    """Returns a 6-link swimmer."""

def swimmer15(time_limit=_DEFAULT_TIME_LIMIT, random=None, environment_kwargs=None):
    """Returns a 15-link swimmer."""

def swimmer(n_links=3, time_limit=_DEFAULT_TIME_LIMIT, random=None,
            environment_kwargs=None):
    """Returns a swimmer with n links."""

class Physics(mujoco.Physics):
    def nose_to_target(self): ...
    def nose_to_target_dist(self): ...
    def body_velocities(self): ...
    def joints(self): ...

class Swimmer(base.Task):
    def __init__(self, random=None): ...
    def initialize_episode(self, physics): ...
    def get_observation(self, physics): ...
    def get_reward(self, physics): ...

Import

from dm_control.suite import swimmer

I/O Contract

Inputs

Name Type Required Description
n_joints int Yes Number of joints/links in the swimmer (minimum 3)
time_limit float No Episode time limit in seconds (default 30)
random int/np.random.RandomState/None No Random seed or state for reproducibility
environment_kwargs dict No Additional keyword arguments passed to the Environment constructor

Outputs

Name Type Description
environment control.Environment A dm_control Environment instance with the swimmer task
observation OrderedDict Contains joints (internal joint angles), to_target (nose-to-target vector), body_velocities (local velocities)
reward float Tolerance on nose-to-target distance with long_tail sigmoid, range [0, 1]

Usage Examples

from dm_control import suite

# Load the 6-link swimmer benchmark
env = suite.load('swimmer', 'swimmer6')

# Load the 15-link swimmer benchmark
env = suite.load('swimmer', 'swimmer15')

# Create a custom swimmer with arbitrary link count
from dm_control.suite import swimmer
env = swimmer.swimmer(n_links=10, time_limit=30)

# Step through the environment
time_step = env.reset()
observation = time_step.observation
print("Joint angles:", observation['joints'])
print("Target direction:", observation['to_target'])

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment