Pre and post physics renderer initialization#5573
Conversation
There was a problem hiding this comment.
Code Review: Pre-Initialize Renderers
Thank you for this PR! The approach of front-loading renderer initialization to ensure deterministic ordering is a solid architectural improvement. Here are my observations:
✅ Strengths
-
Deterministic Initialization Order: Moving renderer backend creation before
SimulationContext.reset()ensures consistent initialization sequence across runs, which is important for debugging and reproducibility. -
Idempotent Design: The use of
RenderContext.get_renderer()with config equality and theseenset tracking ensures the method can be safely called multiple times. -
Consistent Integration: The method is properly called from all relevant environment classes (
DirectRLEnv,DirectMARLEnv,ManagerBasedEnv,LeappDeploymentEnv, and the experimental Warp variants).
🔍 Suggestions
-
Consider Debug Logging (
interactive_scene.py):
The method silently iterates sensors withoutrenderer_cfg. Consider adding debug-level logging to aid troubleshooting:import logging logger = logging.getLogger(__name__) # ... in initialize_renderers(): logger.debug("Initialized %d unique renderer backends for %d sensors", len(backends), sensor_count)
-
Assertion Message (
ovrtx_renderer.py, line 171):
The assertion could be more descriptive for debugging:assert self._renderer is not None, "OVRTX Renderer creation failed - check log_file_path and log_level config"
-
CI Status: The
pre-commitand changelog fragment checks are currently failing. Please verify these pass before merge.
📝 Notes
- The decision to defer
prepare_stage()to camera initialization (documented in the docstring) is appropriate since it needs the finalnum_envsvalue. - The OVRTX renderer change from lazy initialization in
initialize()to eager initialization in__init__aligns well with the pre-initialization pattern.
Overall, this is a well-structured change that improves initialization predictability. 👍
Greptile SummaryThis PR front-loads renderer backend creation by introducing
Confidence Score: 4/5Safe to merge. The init-time renderer construction and the new The core logic is sound:
Important Files Changed
Sequence DiagramsequenceDiagram
participant Env as Env.__init__
participant IS as InteractiveScene
participant RC as RenderContext
participant OR as OVRTXRenderer
Env->>IS: InteractiveScene(cfg.scene)
IS-->>Env: scene (sensors populated)
Env->>IS: _setup_scene() [Direct envs only]
Env->>IS: initialize_renderers()
IS->>RC: get_renderer(rcfg) per sensor
RC->>OR: OVRTXRenderer.__init__(cfg)
OR->>OR: Renderer(OVRTX_CONFIG) [was in prepare_stage]
OR-->>RC: backend
RC-->>IS: backend (deduplicated)
IS-->>Env: [backends list, unused]
Note over Env,OR: Later — first Camera._initialize_impl
Env->>OR: prepare_stage(stage, num_envs)
OR->>OR: export_stage_for_ovrtx(...)
Env->>OR: initialize(spec)
OR->>OR: open_usd / add_usd, bind cameras
Reviews (1): Last reviewed commit: "Pre-Initialize renderers" | Re-trigger Greptile |
| keep_system_alive=True, | ||
| ) | ||
| self._renderer = Renderer(OVRTX_CONFIG) | ||
| assert self._renderer, "Renderer should be valid after creation" |
There was a problem hiding this comment.
assert can be silently stripped in optimized builds
assert self._renderer is disabled when Python is run with -O or -OO, so a None or falsy renderer would go undetected until a subsequent attribute access raises an AttributeError. This line was pre-existing in prepare_stage() but is now in __init__(), making it the only guard between a failed construction and all later renderer calls. A direct if not self._renderer: raise RuntimeError(...) would be more robust.
| class BaseRenderer(ABC): | ||
| """Abstract base class for renderer implementations.""" | ||
|
|
||
| def initialize(self) -> None: |
There was a problem hiding this comment.
question: is there a reason not to implement this for all backends?
| self._camera_rel_path: str | None = None | ||
| self._output_semantic_color_buffer: wp.array | None = None | ||
|
|
||
| logger.info("Creating OVRTX renderer...") |
There was a problem hiding this comment.
question: should this live inside the new initialize() method form BaseRenderer?
Description
Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context.
List any dependencies that are required for this change.
Fixes # (issue)
Type of change
Screenshots
Please attach before and after screenshots of the change if applicable.
Checklist
pre-commitchecks with./isaaclab.sh --formatconfig/extension.tomlfileCONTRIBUTORS.mdor my name already exists there