Implementation:Facebookresearch Habitat lab Env integration testing
| Knowledge Sources | |
|---|---|
| Domains | Testing, Embodied_AI |
| Last Updated | 2026-02-15 02:00 GMT |
Overview
Concrete pattern for testing custom Habitat components using habitat.Env and HabGymWrapper in live simulation environments.
Description
Integration testing uses habitat.Env (for native API testing) and HabGymWrapper / habitat.gym.make_gym_from_config (for Gym API testing) to validate that custom components produce expected outputs. The Env.reset() and Env.step() methods exercise the full component lifecycle.
Usage
Write test scripts that create environments with custom components and verify outputs. Use habitat_test_scenes dataset for lightweight testing.
Code Reference
Source Location
- Repository: habitat-lab
- File: habitat-lab/habitat/core/env.py (Env: L70-137, reset: L236-270, step: L283-315), habitat-lab/habitat/gym/gym_wrapper.py (HabGymWrapper: L190-251)
Signature
class Env:
def __init__(
self,
config: DictConfig,
dataset: Optional[Dataset] = None,
):
"""Create Habitat environment."""
def reset(self) -> Observations:
"""Reset environment to new episode."""
def step(
self, action: Union[int, str, Dict[str, Any]]
) -> Observations:
"""Take action, return new observations."""
# Gym wrapper
class HabGymWrapper(gym.Env):
def __init__(self, env: RLEnv, save_orig_obs: bool = False): ...
def reset(self): ...
def step(self, action): ...
Import
import habitat
from habitat.gym.gym_wrapper import HabGymWrapper
# Or: env = habitat.gym.make_gym_from_config(config)
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| config | DictConfig | Yes | Config with custom components wired in |
| action | Union[int, str, Dict] | Yes | Action to execute in env.step |
Outputs
| Name | Type | Description |
|---|---|---|
| observations | Dict | Sensor outputs including custom sensor values |
| info | Dict | Contains metrics dict with custom measure values |
Usage Examples
Test Custom Components
import habitat
# Create env with custom components
env = habitat.Env(config=config)
obs = env.reset()
# Verify custom sensor output
assert "my_proximity" in obs
assert obs["my_proximity"].shape == (1,)
# Run a step and check metrics
obs = env.step("move_forward")
metrics = env.get_metrics()
assert "my_success" in metrics
env.close()
Test via Gym Wrapper
import habitat.gym
env = habitat.gym.make_gym_from_config(config)
obs, info = env.reset()
obs, reward, terminated, truncated, info = env.step(env.action_space.sample())
env.close()