Principle:Facebookresearch Habitat lab Registry Registration
| Knowledge Sources | |
|---|---|
| Domains | Software_Architecture, Design_Patterns |
| Last Updated | 2026-02-15 02:00 GMT |
Overview
A global registry pattern using Python decorators to register custom components (sensors, measures, actions) for string-based lookup from configuration.
Description
Registry Registration is the mechanism by which custom Habitat components become discoverable from YAML configuration. The @registry.register_* decorators add classes to a global mapping keyed by their registration name (defaulting to the class name). When Habitat initializes a task, it looks up component names from config in the registry and instantiates the corresponding classes.
This pattern enables extending Habitat without modifying framework code -- custom components are registered at import time and resolved at runtime through config.
Usage
Register custom sensors, measures, and actions after defining them. The registration name must match the type field in the corresponding structured config dataclass.
Theoretical Basis
The registry pattern implements a service locator:
- Registration: Decorator maps a name to a class in a global dict
- Resolution: Framework looks up name from config, gets class, and instantiates
- Extensibility: New components are added without modifying framework code
# Abstract registry pattern
registry = {}
def register(name):
def decorator(cls):
registry[name] = cls
return cls
return decorator
@register("my_sensor")
class MySensor: ...
# Later, resolved from config:
sensor_cls = registry[config.type]
sensor = sensor_cls(config=config, sim=sim)