Implementation:Facebookresearch Habitat lab HierarchicalPolicy init
| Knowledge Sources | |
|---|---|
| Domains | Hierarchical_RL, Software_Architecture |
| Last Updated | 2026-02-15 02:00 GMT |
Overview
Concrete constructor for the hierarchical policy that loads and orchestrates pre-trained skill sub-policies under a high-level controller, provided by habitat-baselines.
Description
The HierarchicalPolicy.__init__ method reads the defined_skills config mapping, instantiates each skill policy (loading checkpoints via NnSkillPolicy.from_config), creates the high-level policy (neural, fixed, or planner), and sets up the action/observation space routing. The act method implements the option-framework execution: the high-level policy selects a skill, the skill executes until termination, then control returns.
Usage
Instantiated by the registry during PPOTrainer._init_train() when the policy config specifies HierarchicalPolicy.
Code Reference
Source Location
- Repository: habitat-lab
- File: habitat-baselines/habitat_baselines/rl/hrl/hierarchical_policy.py
- Lines: L41-122 (__init__), L280-392 (act)
Signature
class HierarchicalPolicy(nn.Module, Policy):
def __init__(
self,
config,
full_config,
observation_space: spaces.Space,
action_space: ActionSpace,
orig_action_space: ActionSpace,
num_envs: int,
aux_loss_config,
agent_name: Optional[str] = None,
):
"""
Args:
config: Hierarchical policy config section
full_config: Complete experiment config
observation_space: Full environment observation space
action_space: Mapped action space for this policy
orig_action_space: Original environment action space
num_envs: Number of parallel environments
aux_loss_config: Auxiliary loss configuration
agent_name: Optional agent name (for multi-agent)
"""
Import
from habitat_baselines.rl.hrl.hierarchical_policy import HierarchicalPolicy
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| config | DictConfig | Yes | Hierarchical policy config with defined_skills and high_level_policy
|
| full_config | DictConfig | Yes | Complete experiment config |
| observation_space | spaces.Space | Yes | Environment observation space |
| action_space | ActionSpace | Yes | Mapped action space |
| num_envs | int | Yes | Number of parallel environments |
Outputs
| Name | Type | Description |
|---|---|---|
| policy | HierarchicalPolicy | Assembled hierarchical policy with loaded skills and HL policy |
Usage Examples
Construct Hierarchical Policy
from habitat_baselines.rl.hrl.hierarchical_policy import HierarchicalPolicy
# Typically constructed by registry during training init
policy = HierarchicalPolicy(
config=config.habitat_baselines.rl.policy.hierarchical_policy,
full_config=config,
observation_space=envs.observation_spaces[0],
action_space=envs.action_spaces[0],
orig_action_space=envs.orig_action_spaces[0],
num_envs=config.habitat_baselines.num_environments,
aux_loss_config=config.habitat_baselines.rl.auxiliary_losses,
)