Implementation:Facebookresearch Habitat lab RLTaskEnv
| 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 (ifend_on_successis 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.Wrapperregistered as"GymRegistryEnv"that wraps any gym environment specified byenv_task_gym_idin the config, with support for importing additional dependency modules.
- GymHabitatEnv -- A
gym.Wrapperregistered 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
- Repository: Facebookresearch_Habitat_lab
- File: habitat-lab/habitat/core/environments.py
- Lines: 1-128
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()