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 Randomizers

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

Overview

The randomizers module provides standard functions for randomizing MuJoCo joint positions across all joint types (hinge, slide, ball, free), used by nearly every domain in the dm_control suite for episode initialization.

Description

This utility module defines two functions that form the standard mechanism for randomizing initial joint configurations in dm_control environments. The random_limited_quaternion function generates a random quaternion constrained within a specified angular limit by sampling a random axis (from a normal distribution) and a uniform random angle, then converting to quaternion form via MuJoCo's mju_axisAngle2Quat.

The main function, randomize_limited_and_rotational_joints, iterates over all joints in a physics model and applies type-appropriate randomization. Bounded hinge and slide joints are sampled uniformly within their joint range. Unbounded hinge joints are sampled uniformly in [-pi, pi]. Unlimited ball joints receive random unit quaternions (normalized from standard normal samples). Limited ball joints receive quaternions from random_limited_quaternion. Free joints receive random orientation quaternions while preserving their linear position; notably, the quaternion sampling uses random.rand (uniform) rather than random.randn (normal) for historical reasons to avoid affecting benchmark results.

Usage

Use this module whenever you need to randomize joint configurations at episode start. It is called internally by most suite environments in their initialize_episode methods. It can also be used directly when building custom environments.

Code Reference

Source Location

Signature

def random_limited_quaternion(random, limit):
    """Generates a random quaternion limited to the specified rotations."""

def randomize_limited_and_rotational_joints(physics, random=None):
    """Randomizes the positions of joints defined in the physics body."""

Import

from dm_control.suite.utils import randomizers

I/O Contract

Inputs

Name Type Required Description
physics mujoco.Physics Yes Physics instance holding the loaded model whose joints will be randomized
random np.random.RandomState No Random state instance; defaults to the global NumPy random state
limit float Yes (for random_limited_quaternion) Maximum rotation angle in radians for the limited quaternion

Outputs

Name Type Description
(in-place) None Joint positions are modified in-place in physics.named.data.qpos
quaternion np.ndarray (from random_limited_quaternion) A length-4 quaternion array

Usage Examples

from dm_control.suite.utils import randomizers
from dm_control import mujoco
import numpy as np

# Load a physics model
physics = mujoco.Physics.from_xml_path('model.xml')

# Randomize all joints with a fixed seed
rng = np.random.RandomState(42)
randomizers.randomize_limited_and_rotational_joints(physics, rng)

# Generate a limited random quaternion
quat = randomizers.random_limited_quaternion(rng, limit=0.5)
print("Random quaternion:", quat)

Related Pages

Page Connections

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