Implementation:Facebookresearch Habitat lab Gym Definitions
| Knowledge Sources | |
|---|---|
| Domains | Embodied_AI, Reinforcement_Learning |
| Last Updated | 2026-02-15 00:00 GMT |
Overview
This module registers Habitat environments with OpenAI Gym, providing factory functions to create gym-compatible Habitat environments from configuration files and pre-registering standard benchmark tasks.
Description
The module handles the integration between Habitat-Lab and OpenAI Gym's environment registration system. It operates at two levels:
Factory Functions:
- make_gym_from_config(config, dataset) -- Creates a gym environment from a Habitat config by looking up the environment class from
config.env_taskin the Habitat registry. - _make_habitat_gym_env(cfg_file_path, override_options, use_render_mode) -- Internal factory that loads a config from a YAML file, optionally adds a third-person RGB sensor for rendering, and creates the gym environment.
- _get_env_name(cfg) -- Extracts the environment task name from config, handling both nested and flat config formats.
- _add_sim_sensor_to_config(config, sensor) -- Adds a simulator sensor (e.g., ThirdRGBSensorConfig) to the default agent in the config using the
read_writecontext manager. - _try_register(id_name, entry_point, kwargs) -- Safely registers a gym environment, skipping if already registered.
Pre-registered Tasks:
The module pre-registers the following gym environments at import time via the PRE_REGISTERED_GYM_TASKS dictionary:
- Rearrange skills: CloseFridge, Pick, NavToObj, ReachState, CloseCab, OpenCab, Place, OpenFridge
- Multi-task: SetTable, Rearrange, PrepareGroceries, RearrangeEasy, TidyHouse
Each task is registered twice: once as Habitat{Name}-v0 and once as HabitatRender{Name}-v0 (with a third-person RGB sensor added). Additionally, two generic environments are registered:
Habitat-v0-- Generic environment supporting arbitrary configsHabitatRender-v0-- Same with rendering support
Usage
Import this module to auto-register Habitat environments with Gym. Then use standard gym.make("HabitatPick-v0") calls or use make_gym_from_config for custom configurations.
Code Reference
Source Location
- Repository: Facebookresearch_Habitat_lab
- File: habitat-lab/habitat/gym/gym_definitions.py
- Lines: 1-138
Signature
def make_gym_from_config(config: "DictConfig", dataset=None) -> gym.Env:
def _make_habitat_gym_env(
cfg_file_path: str,
override_options: List[Any] = None,
use_render_mode: bool = False,
) -> gym.Env:
def _try_register(id_name, entry_point, kwargs):
Import
from habitat.gym.gym_definitions import make_gym_from_config
# Or simply import the module to trigger auto-registration:
import habitat.gym.gym_definitions
I/O Contract
Inputs (make_gym_from_config)
| Name | Type | Required | Description |
|---|---|---|---|
| config | DictConfig | Yes | Habitat-lab or habitat-baselines configuration (may contain "habitat" key) |
| dataset | object | No (default=None) | Optional dataset to pass to the environment |
Inputs (_make_habitat_gym_env)
| Name | Type | Required | Description |
|---|---|---|---|
| cfg_file_path | str | Yes | Path to the YAML configuration file |
| override_options | List[Any] | No (default=None) | List of config overrides |
| use_render_mode | bool | No (default=False) | Whether to add a third-person RGB sensor for rendering |
Outputs
| Name | Type | Description |
|---|---|---|
| make_gym_from_config() | gym.Env | A gym-compatible Habitat environment |
| _make_habitat_gym_env() | gym.Env | A gym-compatible Habitat environment from a config file |
Pre-Registered Gym Environments
| Gym ID | Config File |
|---|---|
| HabitatPick-v0 | benchmark/rearrange/skills/pick.yaml |
| HabitatPlace-v0 | benchmark/rearrange/skills/place.yaml |
| HabitatNavToObj-v0 | benchmark/rearrange/skills/nav_to_obj.yaml |
| HabitatReachState-v0 | benchmark/rearrange/skills/reach_state.yaml |
| HabitatOpenFridge-v0 | benchmark/rearrange/skills/open_fridge.yaml |
| HabitatCloseFridge-v0 | benchmark/rearrange/skills/close_fridge.yaml |
| HabitatOpenCab-v0 | benchmark/rearrange/skills/open_cab.yaml |
| HabitatCloseCab-v0 | benchmark/rearrange/skills/close_cab.yaml |
| HabitatRearrange-v0 | benchmark/rearrange/multi_task/rearrange.yaml |
| HabitatRearrangeEasy-v0 | benchmark/rearrange/multi_task/rearrange_easy.yaml |
| HabitatSetTable-v0 | benchmark/rearrange/multi_task/set_table.yaml |
| HabitatTidyHouse-v0 | benchmark/rearrange/multi_task/tidy_house.yaml |
| HabitatPrepareGroceries-v0 | benchmark/rearrange/multi_task/prepare_groceries.yaml |
Usage Examples
Basic Usage
import gym
import habitat.gym # Triggers auto-registration
# Create a pre-registered Habitat gym environment
env = gym.make("HabitatPick-v0")
obs = env.reset()
done = False
while not done:
action = env.action_space.sample()
obs, reward, done, info = env.step(action)
env.close()
# Create from a custom config
from habitat.gym.gym_definitions import make_gym_from_config
from habitat import get_config
config = get_config("benchmark/rearrange/skills/pick.yaml")
env = make_gym_from_config(config)