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 Habitat2 Quickstart Tutorial

From Leeroopedia
Revision as of 12:35, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Facebookresearch_Habitat_lab_Habitat2_Quickstart_Tutorial.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains Embodied_AI, Tutorials, Rearrangement_Tasks
Last Updated 2026-02-15 00:00 GMT

Overview

The Habitat2_Quickstart tutorial is a Jupyter notebook (in percent-format Python) that covers the basics of Habitat 2.0, including environment setup, Gym API usage, defining custom rearrangement tasks with sensors and measurements, and generating episode datasets.

Description

This tutorial walks through four key areas of Habitat 2.0:

1. Quickstart Environment Interaction: Demonstrates a minimal environment loop using the Habitat API. Sets up a pick task environment, takes random actions until the episode ends, and saves a video of the rendered observations.

2. Gym API: Shows how to use Habitat environments through the OpenAI Gym interface with gym.make("HabitatRenderPick-v0"), collecting observations and rendering to video.

3. Defining New Tasks: Provides a complete example of creating a custom navigation-and-pick task (NavPickTaskV1) registered as "RearrangeDemoNavPickTask-v0". Includes:

  • A RearrangeTask subclass with custom reset logic (random target object, random agent start position).
  • DistanceToTargetObject measure that computes Euclidean distance from end-effector to target.
  • NavPickReward reward function (based on RearrangeReward) that scales distance to target, with configurable penalty parameters for collisions and force.
  • NavPickSuccess success measure that checks if the agent has grasped the correct target object.
  • Hydra ConfigStore registration for all measurements.
  • A complete YAML task configuration defining the action space (arm + base velocity), measurements, sensors, simulator settings, and dataset.

4. Dataset Generation: Shows how to create a custom episode dataset configuration YAML specifying scene sets (ReplicaCAD), object sets (YCB kitchen objects), and receptacle sets (table), then references the run_episode_generator.py script to generate episodes.

Usage

This tutorial is intended as a learning resource for new Habitat 2.0 users. Run it as a Jupyter notebook or execute cell-by-cell in a Python environment with Habitat Lab and Habitat Sim installed. The ReplicaCAD dataset will auto-download on first run.

Code Reference

Source Location

Signature

# Key classes and functions defined in the tutorial:

def insert_render_options(config):
    ...

@registry.register_task(name="RearrangeDemoNavPickTask-v0")
class NavPickTaskV1(RearrangeTask):
    def reset(self, episode):
        ...

@registry.register_measure
class DistanceToTargetObject(Measure):
    cls_uuid: str = "distance_to_object"
    ...

@registry.register_measure
class NavPickReward(RearrangeReward):
    cls_uuid: str = "navpick_reward"
    ...

@registry.register_measure
class NavPickSuccess(Measure):
    cls_uuid: str = "navpick_success"
    ...

@dataclass
class NavPickRewardMeasurementConfig(MeasurementConfig):
    type: str = "NavPickReward"
    scaling_factor: float = 0.1
    ...

Import

# Tutorial imports
import habitat
import habitat.gym
from habitat.core.embodied_task import Measure
from habitat.core.registry import registry
from habitat.tasks.rearrange.rearrange_sensors import RearrangeReward
from habitat.tasks.rearrange.rearrange_task import RearrangeTask
from habitat.utils.visualizations.utils import observations_to_image, overlay_frame

I/O Contract

Inputs

Name Type Required Description
Habitat config YAML str Yes Path to a rearrangement task config (e.g., benchmark/rearrange/skills/pick.yaml)
ReplicaCAD dataset files Yes Scene assets and episode datasets (auto-downloaded on first run)

Outputs

Name Type Description
Video files MP4 Rendered episode videos saved to examples/tutorials/habitat_lab_visualization/
Custom task registered class NavPickTaskV1 registered as "RearrangeDemoNavPickTask-v0"
Dataset config YAML Custom episode dataset configuration for the nav-pick task

Usage Examples

Basic Usage

import habitat
from habitat.utils.visualizations.utils import observations_to_image, overlay_frame

# Quickstart: run a pick task with random actions
config = habitat.get_config(
    "habitat-lab/habitat/config/benchmark/rearrange/skills/pick.yaml"
)

with habitat.Env(config=config) as env:
    observations = env.reset()
    count_steps = 0

    while not env.episode_over:
        observations = env.step(env.action_space.sample())
        info = env.get_metrics()
        render_obs = observations_to_image(observations, info)
        count_steps += 1

    print(f"Episode finished after {count_steps} steps.")

# Using the Gym API
import gym
import habitat.gym

env = gym.make("HabitatRenderPick-v0")
done = False
env.reset()
while not done:
    obs, reward, done, info = env.step(env.action_space.sample())

Related Pages

Page Connections

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