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 RLTaskEnv

From Leeroopedia
Revision as of 10:39, 27 September 2026 by Agent (talk | contribs) (Sync from local file)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains Embodied_AI, Reinforcement_Learning
Last Updated 2026-02-15 00:00 GMT

Overview

This module provides task-specific and trainer-specific RL environment classes, including RLTaskEnv for reward-based training and wrapper classes for integrating Habitat environments with OpenAI Gym.

Description

The module defines several environment classes designed for reinforcement learning in Habitat:

  • get_env_class(env_name) -- A utility function that retrieves an environment class by name from the Habitat registry.
  • RLTaskEnv -- The primary RL environment class, extending habitat.RLEnv. It reads reward and success measures from the task config and implements the standard RL environment interface:
    • get_reward(observations) computes reward as slack_reward + current measure value + success_reward (if episode succeeded).
    • get_done(observations) returns True when the episode is over or when the task succeeds (if end_on_success is enabled).
    • get_reward_range() returns (-inf, inf) since the reward measure bounds are unknown.
    • get_info(observations) returns the full metrics dictionary from the environment.
  • GymRegistryEnv -- A gym.Wrapper registered as "GymRegistryEnv" that wraps any gym environment specified by env_task_gym_id in the config, with support for importing additional dependency modules.
  • GymHabitatEnv -- A gym.Wrapper registered as "GymHabitatEnv" that wraps an RLTaskEnv with HabGymWrapper to provide the standard gym API for Habitat tasks.

A type alias RLTaskEnvObsType is defined as Union[np.ndarray, Dict[str, np.ndarray]].

Usage

Use RLTaskEnv when training RL agents on Habitat tasks. It is the default environment class used by habitat-baselines trainers. Register custom environments using @habitat.registry.register_env(name="myEnv") for integration with the training pipeline.

Code Reference

Source Location

Signature

class RLTaskEnv(habitat.RLEnv):
    def __init__(
        self, config: "DictConfig", dataset: Optional[Dataset] = None
    ):

class GymRegistryEnv(gym.Wrapper):
    def __init__(
        self, config: "DictConfig", dataset: Optional[Dataset] = None
    ):

class GymHabitatEnv(gym.Wrapper):
    def __init__(
        self, config: "DictConfig", dataset: Optional[Dataset] = None
    ):

def get_env_class(env_name: str) -> Type[habitat.RLEnv]:

Import

from habitat.core.environments import RLTaskEnv, GymRegistryEnv, GymHabitatEnv, get_env_class

I/O Contract

Inputs (RLTaskEnv)

Name Type Required Description
config DictConfig Yes Habitat configuration with task.reward_measure, task.success_measure, task.slack_reward, task.success_reward, and task.end_on_success
dataset Dataset No (default=None) Optional dataset for episode management

Outputs

Name Type Description
reset() Union[np.ndarray, Dict[str, np.ndarray]] Observations from the environment after reset
step() Tuple[RLTaskEnvObsType, float, bool, dict] Standard (obs, reward, done, info) tuple
get_reward(observations) float Computed reward for the current step
get_done(observations) bool Whether the episode is complete
get_info(observations) dict Full metrics dictionary from the environment

Usage Examples

Basic Usage

from habitat.core.environments import RLTaskEnv, get_env_class
from habitat import get_config

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

# Create the RL environment
env = RLTaskEnv(config=config.habitat)

# Run a simple episode
observations = env.reset()
done = False
total_reward = 0.0
while not done:
    action = env.action_space.sample()
    observations, reward, done, info = env.step(action)
    total_reward += reward

env.close()

Related Pages

Page Connections

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