Skip to content

Comments

Delegates close stage logic in SimulationContext to Stage utility#4688

Open
ooctipus wants to merge 1 commit intoisaac-sim:developfrom
ooctipus:feature/develop/remove_remaining_omniusd
Open

Delegates close stage logic in SimulationContext to Stage utility#4688
ooctipus wants to merge 1 commit intoisaac-sim:developfrom
ooctipus:feature/develop/remove_remaining_omniusd

Conversation

@ooctipus
Copy link
Collaborator

Description

This PR refactors the code further

Removes remaining refactorable omni.usd usage

Refactores SimulationContext.clear_instance to delegate stage teardown to
isaaclab.sim.utils.close_stage instead of manually clearing the stage cache,
thread-local context, and Kit USD context inline.

Updates isaaclab.sim.utils.close_stage to also close the Kit USD context stage
(omni.usd.get_context().close_stage()) when Kit is running, making it a complete
stage teardown function.

Fixes # (issue)

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Screenshots

Please attach before and after screenshots of the change if applicable.

Checklist

  • I have read and understood the contribution guidelines
  • I have run the pre-commit checks with ./isaaclab.sh --format
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the changelog and the corresponding version in the extension's config/extension.toml file
  • I have added my name to the CONTRIBUTORS.md or my name already exists there

@github-actions github-actions bot added enhancement New feature or request isaac-mimic Related to Isaac Mimic team labels Feb 23, 2026
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 23, 2026

Greptile Summary

This PR successfully refactors stage teardown logic by consolidating stage cleanup into the close_stage() utility function. The main changes delegate SimulationContext.clear_instance() stage teardown to stage_utils.close_stage(), which now handles stage cache clearing, thread-local context cleanup, and Kit USD context stage closure in one place. Additionally, the PR removes remaining direct dependencies on omni.usd across scripts by replacing calls with IsaacLab's unified sim_utils API (get_current_stage() and close_stage()).

Key changes:

  • Enhanced close_stage() to close Kit USD context stage when Kit is running, making it symmetric with stage initialization
  • Removed manual stage cache and context management from SimulationContext.clear_instance() in favor of centralized close_stage() call
  • Replaced 5 script files' direct omni.usd usage with sim_utils wrappers for better abstraction
  • Cleaned up unused omni.usd import from prims.py

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk - it's a clean refactoring that consolidates existing logic
  • The refactoring consolidates duplicate stage teardown code into a single utility function without changing behavior. All replacements are semantically equivalent (e.g., omni.usd.get_context().get_stage()sim_utils.get_current_stage()), and the enhanced close_stage() now properly handles all cleanup that was previously done inline. The changes improve maintainability by reducing code duplication and removing direct omni.usd dependencies.
  • No files require special attention

Important Files Changed

Filename Overview
source/isaaclab/isaaclab/sim/utils/stage.py Enhanced close_stage() to also close Kit USD context stage when Kit is running, making it a complete stage teardown utility
source/isaaclab/isaaclab/sim/simulation_context.py Refactored clear_instance() to delegate stage teardown to stage_utils.close_stage() instead of manually managing stage cache and contexts
scripts/environments/teleoperation/teleop_se3_agent.py Replaced omni.usd.get_context().close_stage() with sim_utils.close_stage() to use centralized stage closing utility
scripts/tools/record_demos.py Replaced omni.usd.get_context().close_stage() with sim_utils.close_stage() to use centralized stage closing utility

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[SimulationContext.clear_instance] --> B{Stage Teardown}
    B --> C[stage_utils.close_stage]
    C --> D[Clear UsdUtils.StageCache]
    C --> E[Set _context.stage = None]
    C --> F{Kit Running?}
    F -->|Yes| G[omni.usd.get_context.close_stage]
    F -->|No| H[Skip Kit Context Cleanup]
    
    I[Script Files] --> J{Stage Access}
    J -->|Get Stage| K[sim_utils.get_current_stage]
    J -->|Close Stage| L[sim_utils.close_stage]
    
    K -.->|abstracts| M[omni.usd.get_context.get_stage]
    L -.->|abstracts| G
    
    style C fill:#90EE90
    style A fill:#87CEEB
    style I fill:#FFD700
Loading

Last reviewed commit: d873772

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

10 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request isaac-mimic Related to Isaac Mimic team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant