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 Padded Room

From Leeroopedia
Knowledge Sources
Domains Reinforcement_Learning, Locomotion
Last Updated 2026-02-15 04:00 GMT

Overview

A LabMaze-compatible square room where the outermost cells are padded with empty space, providing a simple bounded open area for locomotion tasks with randomized agent spawn and object positions.

Description

The PaddedRoom class extends labmaze.BaseMaze and generates a simple square room with a 2-cell padding border on each side (total padding of 4 cells added to room_size). The border cells can optionally be filled with wall characters ('*') to create a bounded enclosure. The interior of the room is open space, unlike more complex random maze generators.

On each call to regenerate(), the room clears its interior and randomly places agent spawn positions (marked with SPAWN_TOKEN) and target objects (marked with OBJECT_TOKEN) at positions sampled uniformly without replacement from the interior grid cells. The number of spawn positions and target objects are configured at construction time.

The room provides two layers: entity_layer (containing wall, spawn, and object tokens) and variations_layer (containing variation tokens for texture assignment). Both are labmaze.TextGrid instances that can be consumed by maze arena builders such as MazeWithTargets to construct 3D MuJoCo environments.

Usage

Use PaddedRoom when you need a simple, open room environment for locomotion tasks such as target reaching, object collection, or basic navigation. It provides a bounded space without the complexity of corridors and passages found in random maze generators. Pass the resulting room to a maze arena builder to create the corresponding 3D MuJoCo model.

Code Reference

Source Location

Signature

class PaddedRoom(labmaze.BaseMaze):
    def __init__(self, room_size, num_objects=0, random_state=None,
                 pad_with_walls=True, num_agent_spawn_positions=1):
        ...
    def regenerate(self):
        ...
    @property
    def entity_layer(self):
        ...
    @property
    def variations_layer(self):
        ...
    @property
    def width(self):
        ...
    @property
    def height(self):
        ...

Import

from dm_control.locomotion.arenas.padded_room import PaddedRoom

I/O Contract

Inputs (__init__)

Name Type Required Description
room_size int Yes The size of the interior room (excluding 4-cell padding)
num_objects int No Number of target objects to place in the room (default 0)
random_state np.random.RandomState or None No Random state for position sampling; defaults to np.random
pad_with_walls bool No If True, fill border cells with wall characters (default True)
num_agent_spawn_positions int No Number of agent spawn positions to place (default 1)

Outputs

Name Type Description
entity_layer labmaze.TextGrid Grid containing wall ('*'), spawn (SPAWN_TOKEN), object (OBJECT_TOKEN), and empty (' ') tokens
variations_layer labmaze.TextGrid Grid of variation tokens for texture assignment (all '.')
width int Total grid width: room_size + 4
height int Total grid height: room_size + 4

Grid Layout

For a room_size=3 with pad_with_walls=True, the entity layer after regenerate() might look like:

*******
*     *
*  P  *
*     *
*  O  *
*     *
*******

Where '*' = wall, 'P' = spawn position, 'O' = object, and ' ' = empty space. The total grid size is 7x7 (3 + 4 padding).

Usage Examples

from dm_control.locomotion.arenas.padded_room import PaddedRoom
import numpy as np

rng = np.random.RandomState(42)

# Create a simple room with 2 target objects
room = PaddedRoom(
    room_size=5,
    num_objects=2,
    random_state=rng,
    pad_with_walls=True,
    num_agent_spawn_positions=1
)

# Generate the room layout (place spawn and objects)
room.regenerate()

# Access the grid layers
print(room.entity_layer)  # TextGrid with walls, spawn, objects
print(room.width)   # 9 (5 + 4)
print(room.height)  # 9 (5 + 4)

# Regenerate for a new episode (new random positions)
room.regenerate()

# Create a room without walls (no boundary)
open_room = PaddedRoom(
    room_size=5,
    num_objects=3,
    random_state=rng,
    pad_with_walls=False
)

Related Pages

Page Connections

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