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 Config Read Write

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

Overview

The read_write context manager temporarily unlocks an OmegaConf configuration object for modification, restoring its original readonly and struct flags upon exit.

Description

Habitat-Lab uses OmegaConf configurations that are typically frozen (readonly and struct-flagged) after initialization to prevent accidental modification. The read_write context manager provides a safe mechanism to temporarily disable both the readonly and struct flags on a configuration, allowing modifications within a with block. When the block exits (whether normally or via exception), the original flag states are restored.

The function:

  1. Asserts the input is an OmegaConf Container instance
  2. Captures the current readonly and struct flag states
  3. Disables both struct mode (which prevents adding new keys) and readonly mode
  4. Yields the config for modification
  5. Restores both flags to their original values in the finally block

This pattern is essential throughout Habitat-Lab wherever configuration modifications are needed after initial setup, such as adding sensors, changing task parameters, or adjusting simulator settings.

Usage

Use read_write whenever you need to modify an OmegaConf-based Habitat configuration that has already been frozen. This is particularly common when programmatically adjusting configs before creating environments or when overriding defaults in custom training scripts.

Code Reference

Source Location

Signature

@contextmanager
def read_write(config: Any) -> Generator[Node, None, None]:

Import

from habitat.config.read_write import read_write
# Or via the top-level habitat module:
from habitat import read_write

I/O Contract

Inputs

Name Type Required Description
config Any (must be OmegaConf Container) Yes The OmegaConf configuration object to temporarily unlock for writing

Outputs

Name Type Description
(yielded) Node The same configuration object, now writable within the context block

Usage Examples

Basic Usage

from habitat import get_config, read_write

# Load a frozen configuration
config = get_config("benchmark/nav/pointnav/pointnav_habitat_test.yaml")

# Modify the config within a read_write context
with read_write(config):
    config.habitat.simulator.habitat_sim_v0.gpu_device_id = 0
    config.habitat.environment.max_episode_steps = 500
    config.habitat.task.reward_measure = "distance_to_goal"

# Outside the context, config is frozen again
# config.habitat.task.slack_reward = -0.01  # This would raise an error

Related Pages

Page Connections

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