Principle:Haosulab ManiSkill Lazy Controller Instantiation
| Knowledge Sources | |
|---|---|
| Domains | Robotics, Simulation, Software_Architecture |
| Last Updated | 2026-02-15 08:00 GMT |
Overview
Controllers are instantiated only when their control mode is first selected, deferring expensive operations like IK solver initialization and action space construction until actually needed.
Description
The Lazy Controller Instantiation principle addresses the cost of eagerly constructing all possible controllers for a robot agent. A single robot may support 10+ control modes (joint position, joint velocity, end-effector pose variants, base velocity, etc.), each requiring its own action space, drive property configuration, and potentially an IK solver. Instantiating all of these at environment creation time wastes memory and computation.
Instead, BaseAgent stores controller configurations as declarative specifications and only instantiates the controller hierarchy for the selected control mode. This is implemented through the _controller_configs property (which returns config objects, not live controllers) and a lazy initialization path in _load_controller() that builds controllers on first use.
Usage
This principle applies whenever:
- A robot declares many control modes but only one is used per environment instance.
- End-effector controllers require loading URDF files and building kinematic chains, which is expensive to do eagerly.
- GPU memory must be conserved by not allocating IK solver buffers for unused control modes.
Theoretical Basis
Deferred Construction: Controller configs are lightweight dataclasses specifying parameters. The actual controller objects (with allocated buffers, parsed URDF chains, action spaces) are created only when the environment selects a control mode.
Single Active Controller: At any time, only one controller (or combined controller) is active per agent. Switching control modes triggers a new instantiation, replacing the previous controller.
Memory Efficiency: For GPU-parallelized environments with hundreds of parallel instances, avoiding unnecessary IK solver allocations across all instances provides meaningful memory savings.
Related Pages
- Implementation:Haosulab_ManiSkill_BaseAgent -- BaseAgent implementing lazy controller loading.