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:Facebookresearch Habitat lab ActionSpace

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

Overview

This module defines custom gym Space classes for Habitat's action and observation representations, including EmptySpace, ActionSpace, and ListSpace.

Description

The module provides three custom gym Space implementations used throughout Habitat:

  • EmptySpace -- A gym.Space subclass for actions that take no arguments. It always samples None and only contains None values. This ensures consistency in the action space interface where every action has an associated argument space.
  • ActionSpace -- Extends gym.spaces.Dict to represent a dictionary of EmbodiedTask actions and their argument spaces. Key features:
    • Accepts either a dict or list of (action_name, space) pairs, storing them in sorted order (for dicts) or preserved order (for lists)
    • The n property returns the number of available actions
    • sample() returns a dict with an "action" key (randomly selected action name) and "action_args" key (sampled from that action's space)
    • contains(x) validates that x is a dict with a valid action name and matching action arguments
  • ListSpace -- A gym.Space for variable-length sequences of another Space type. Useful for representing lists of token IDs, vectors, etc. Supports configurable minimum and maximum sequence lengths, with sampling producing lists of random length within those bounds.

Usage

ActionSpace is used internally by Habitat's EmbodiedTask system to define available actions. EmptySpace is used for actions without parameters (e.g., move_forward). ListSpace is used for observation spaces that contain variable-length sequences such as tokenized questions in EQA tasks.

Code Reference

Source Location

Signature

class EmptySpace(Space):
    def sample(self):
    def contains(self, x):

class ActionSpace(gym.spaces.Dict):
    def __init__(self, spaces: Union[List, Dict]):

class ListSpace(Space):
    def __init__(
        self,
        space: Space,
        min_seq_length: int = 0,
        max_seq_length: int = 1 << 15,
    ):

Import

from habitat.core.spaces import ActionSpace, EmptySpace, ListSpace

I/O Contract

Inputs (ActionSpace)

Name Type Required Description
spaces Union[List, Dict] Yes Dict or list of (action_name, argument_space) pairs defining available actions

Inputs (ListSpace)

Name Type Required Description
space Space Yes The gym.Space that each element in the list is drawn from
min_seq_length int No (default=0) Minimum length of sampled sequences
max_seq_length int No (default=32768) Maximum length of sampled sequences

Outputs

Name Type Description
ActionSpace.sample() dict Dict with "action" (str) and "action_args" (sampled from the action's space)
ActionSpace.n int Number of available actions
ListSpace.sample() List List of sampled elements with random length in [min_seq_length, max_seq_length]
EmptySpace.sample() None Always returns None

Usage Examples

Basic Usage

import gym
from habitat.core.spaces import ActionSpace, EmptySpace, ListSpace

# Define an action space with two actions
action_space = ActionSpace({
    "move": gym.spaces.Dict({
        "position": gym.spaces.Discrete(2),
        "velocity": gym.spaces.Discrete(3),
    }),
    "move_forward": EmptySpace(),
})

# Sample a random action
action = action_space.sample()
# e.g., {"action": "move_forward", "action_args": None}

# Check number of actions
num_actions = action_space.n  # 2

# Validate an action
is_valid = action_space.contains({
    "action": "move",
    "action_args": {"position": 1, "velocity": 2},
})  # True

# Create a list space for tokenized sequences
token_space = ListSpace(
    gym.spaces.Discrete(1000),
    min_seq_length=1,
    max_seq_length=50,
)
tokens = token_space.sample()  # List of random token IDs

Related Pages

Page Connections

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