Skip to content

[Fix] Make generated template projects import without Kit (no eager omni.ext) - #5941

Merged
kellyguo11 merged 9 commits into
isaac-sim:developfrom
hujc7:jichuanh/fix-template-generator
Jun 5, 2026
Merged

kellyguo11 merged 9 commits into
isaac-sim:developfrom
hujc7:jichuanh/fix-template-generator

Conversation

@hujc7

@hujc7 hujc7 commented Jun 3, 2026 •

Copy link
Copy Markdown
Collaborator

1. Summary

  • Generated template projects could not be imported headless (e.g. Gym registration before SimulationApp): import <project> failed with ModuleNotFoundError: No module named 'omni.ext'. The package root no longer imports the example UI extension, so it stays omni-free. (NVBug 6251247)
  • Hardened the generator to fail loudly when a requested agent-config template is missing, instead of silently emitting a project whose Gym registration points at a non-existent config.
  • Self-contained on develop. Includes the template-generator test scaffolding (also proposed in Adds CI tests for template generator #5885, commit preserved) plus new regression coverage — 15 tests.

2. Changes

2.1 Generator (tools/template)

  • templates/extension/__init__ext: drop the eager from .ui_extension_example import * from the package root.
  • templates/extension/config/extension.toml: register <name>.ui_extension_example as its own [[python.module]] so Kit still loads the UI extension (Kit imports each python.module by name and scans it for omni.ext.IExt).
  • templates/extension/ui_extension_example.py: add the missing import omni.ui.
  • generator.py: raise (instead of silently continue-ing) when an agents/<rl_library>_<algorithm>_cfg template is missing.

2.2 Tests

  • Existing scaffolding: algorithm discovery, single/multi-agent registry entry points, launch configs.
  • New regressions: omni/pxr import-safety of the generated package, extension.toml UI-module registration, generated-.py ast/compile validity, no top-level backend imports in generated env modules, per-library agent-config completeness.

3. Design note: why not lazy-import omni.ext

  • omni.ext / ExampleExtension are consumed only by Kit's extension manager (via [[python.module]]), never on the headless path. The correct fix is to not import it at the package root, not to defer it.

4. Out of scope / known limitations

  • AMP on the generated single-agent template (NVBug 6257353) is intentionally left as a known limitation (tracked on the ticket), not changed here: AMP requires task-specific reference motion data (a MotionLoader + collect_reference_motions + AMP observations) that a generic generated env cannot provide — see contrib/humanoid_amp. PPO trains as-generated.
  • The free() / omni.UsdMdl TfNotice startup crashes (NVBug 6257159, 6251258) are a separate core issue already fixed by deferring pxr ([Fix] Defer pxr loading in isaaclab.sim, .assets, .scene, and .sim/utils #5826) and cherry-picked to release/3.0.0-beta2.

5. Test plan

  • ./isaaclab.sh -p -m pytest source/isaaclab_rl/test/test_template_generator.py → 15 passed
  • Import-safety + UI-module tests fail without the __init__ext/extension.toml fix (verified by reverting)
  • Generator raises on a missing agent template (verified)
  • ./isaaclab.sh -f (pre-commit) clean

@github-actions github-actions Bot added bug Something isn't working isaac-lab Related to Isaac Lab team infrastructure labels Jun 3, 2026

@isaaclab-review-bot isaaclab-review-bot Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review Summary

Well-structured fix PR that addresses two distinct but related template-generator issues. The approach is sound and the test coverage is excellent.

Overall assessment: ✅ Approve-worthy — clean, minimal, well-tested fixes with thorough regression coverage.


Architecture & Design

Import Safety Fix (NVBug 6251247)

The fix correctly separates the UI extension loading path from the package import path:

  1. __init__ext — Removes the eager from .ui_extension_example import *, replacing it with a clear comment explaining why.
  2. extension.toml — Adds [[python.module]] name = "{{ name }}.ui_extension_example" so Kit's extension manager still discovers and loads the IExt subclass at runtime.
  3. ui_extension_example.py — Adds the previously-missing import omni.ui.

This is the correct architectural choice over lazy-importing: the UI extension is only consumed by Kit's module scanner, so it should be declared in extension.toml rather than imported at package level.

Error Handling Fix

The generator.py change to raise FileNotFoundError instead of silently continuing when a template is missing is the right call — projects now fail at generation time rather than at train time with a cryptic missing-config error.


Test Coverage Analysis

The test suite is comprehensive with excellent regression guards:

Test What it validates
test_generated_env_modules_have_no_forbidden_top_level_imports AST-based check for pxr/omni/carb/isaacsim/usdrt at module scope
test_each_requested_agent_cfg_file_is_generated No silently-skipped agent configs
test_generated_python_is_syntactically_valid AST + compile check on all generated .py
test_extension_toml_registers_ui_extension_as_separate_module Both halves of the import-safety fix
test_generated_package_import_is_omni_and_pxr_free Subprocess import with omni/pxr blocker

The subprocess-based import-safety test (test_generated_package_import_is_omni_and_pxr_free) is particularly well-designed — it uses a custom sys.meta_path finder to block omni/pxr imports and verifies the package still loads cleanly.


🔄 Follow-up Review — 374d842 (2026-06-04)

✅ Previous Concern Resolved

The stray debug comment in __init__ext (#rj: what's the consequence of this change?...) has been removed. This was the only blocking issue from my previous review.

No New Issues Introduced

The new commit cleanly addresses the feedback with no regressions:

  • All existing tests should continue to pass
  • New test coverage is thorough and well-designed
  • Changelog fragment is properly formatted

LGTM. Ready for merge.


🔄 Follow-up Review — 911435d6 (2026-06-04)

New Changes (NVBug 6251258/6257159 — Manager-Based pxr Fix)

The new commits add a second fix addressing eager pxr imports in manager-based template projects:

  1. mdp/__init__.py — Replaced wildcard re-exports with lazy_export() from isaaclab.utils.module, deferring heavy imports until actually accessed.
  2. mdp/__init__.pyi — Added type stub for IDE support without runtime cost.
  3. mdp/rewards.py — Moved from isaaclab.assets import Articulation into TYPE_CHECKING guard to break the pxr import chain.
  4. New test — test_generated_manager_based_env_cfg_resolution_is_omni_and_pxr_free validates env config instantiation in a subprocess with omni/pxr blocked.
  5. Changelog — Updated with the additional fix description.

Assessment

✅ No issues found. The lazy_export() + TYPE_CHECKING pattern is the correct approach for keeping template projects importable before Kit launches. Test coverage mirrors the existing import-safety test with the same subprocess-blocker strategy.

LGTM. Still approve-worthy.


🔄 Follow-up Review — e03366b5 (2026-06-04)

Trivial Cleanup

Single commit removes redundant source/isaaclab_rl/changelog.d/template-generator-tests.skip — an empty changelog fragment from the chained test branch that's no longer needed since the single jichuanh-fix-template-generator.rst fragment already covers the isaaclab_rl change.

✅ No issues. No code changes. LGTM.


🔄 Follow-up Review — b5795e73 (2026-06-04)

New Fix: Internal Task Registration

Addresses a subtle issue where generated internal tasks failed to register because after the core/contrib split (#5891), isaaclab_tasks/{direct,manager_based}/ became namespace directories without __init__.py. Since import_packages uses pkgutil.iter_modules, which skips namespace packages, internal tasks were never discovered.

Changes:

  1. generator.py — Moved workflow __init__.py creation into _generate_tasks() (from the external-only code path), now shared by both internal and external generation. Creates the init file only when missing to avoid clobbering existing packages.
  2. New test — test_generated_internal_task_workflow_dirs_are_importable_packages verifies pkgutil.iter_modules lists the generated workflow dirs as packages.
  3. Changelog — Added entry for the internal task registration fix.

Assessment

✅ No issues found. The fix is minimal and correct:

  • os.path.exists() check prevents clobbering existing packages
  • Moving the logic into _generate_tasks() eliminates duplicate code in the external path
  • Test directly validates the pkgutil.iter_modules behavior that import_packages depends on

LGTM. Continues to be approve-worthy.


Update (5c7cfb1): Reviewed incremental changes (e03366b → 5c7cfb1):

  • generator.py: Moved per-workflow __init__.py creation from _external() into _generate_tasks() — now both internal and external tasks get the package init. Added os.path.exists guard to avoid clobbering existing files. Clean refactor, no issues.
  • test_template_generator.py: Added two solid regression tests — test_generated_internal_task_workflow_dirs_are_importable_packages (verifies pkgutil.iter_modules discovers the workflow dirs) and test_generated_external_project_registers_tasks_on_import (end-to-end import registration check). Good coverage.
  • changelog.d: Added entry for the new fix.

No new issues. Changes look good. ✅


Update (d95991f): Reviewed incremental changes (5c7cfb1 → d95991f):

  • changelog.d/jichuanh-fix-template-generator.rst → Removed (replaced with .skip sentinel)
  • changelog.d/jichuanh-fix-template-generator.skip → Added (empty file)

This swaps the detailed changelog fragment for a .skip sentinel, meaning the isaaclab_rl package changelog will not emit an entry for this branch. Likely done because the relevant changelog entries are being consolidated elsewhere (e.g., in the parent isaaclab package changelog) or the template-generator changes are considered internal tooling not warranting a user-facing release note.

✅ No issues. Housekeeping-only change. LGTM.


Update (aea97ea): Large release-prep commit landed. Key changes:

  • Version bumps: isaaclab 6.3.0, isaaclab_newton 0.15.0, isaaclab_rl 0.6.0, isaaclab_tasks 2.0.2, isaaclab_contrib 0.4.2, isaaclab_experimental 0.1.1, isaaclab_ovphysx pin ovphysx==0.4.13
  • Changelog consolidation: Moved all pending changelog.d/ fragments into their respective CHANGELOG.rst files and removed the fragments
  • ls_parallel deprecation (isaaclab_newton): MJWarpSolverCfg.ls_parallel now emits DeprecationWarning and is forced to False via __post_init__. All test/task configs had ls_parallel references removed. Manager filters the field out before forwarding to solver constructor.
  • Removed scripts/tools/wrap_warp_to_torch.py: Obsolete migration helper deleted; test exclusion for it also removed
  • CI: Pinned ovphysx==0.4.13 in workflow extra-pip-packages; license-check workflow migrated from pip to uv
  • Docs: Updated MJWarp solver docs removing ls_parallel references; improved ls_iterations description; docs extension now respects smv_current_version
  • Tasks: Newton Spot preset expanded with collision pipeline config and use_mujoco_contacts=False; benchmark script wrapped step in torch.inference_mode(); camera demo subtitle fix
  • Tests: Updated test assertion message in test_template_generator.py for clarity

No new issues introduced. This is a well-organized release commit consolidating prior work. ✅

if self._newton_model.shape_count > 0 and self._newton_model.bvh_shapes is None:
newton.geometry.build_bvh_shape(self._newton_model, self._newton_model.state())

if self.cfg.create_default_light:
self.newton_sensor.utils.create_default_light(enable_shadows=self.cfg.enable_shadows)
=======
if newton_model.shape_count > 0 and newton_model.bvh_shapes is None:
newton.geometry.build_bvh_shape(newton_model, newton_model.state())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🚨 Unresolved merge conflict markers — this file has <<<<<<< Updated upstream / ======= / >>>>>>> Stashed changes blocks that will cause a SyntaxError at import time. Looks like a git stash pop or merge left conflicts that were accidentally committed.

@@ -41,6 +44,7 @@

from .preset_target import PresetTarget

<<<<<<< Updated upstream

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🚨 Unresolved merge conflict markers throughout this file — there are ~8 conflict blocks (<<<<<<< Updated upstream / >>>>>>> Stashed changes). This will not parse as valid Python. The refactoring here (removing deprecation helpers, renaming newton_mjwarp → newton) also seems like a significant scope expansion beyond the PR title — consider splitting into a separate PR once conflicts are resolved.

@hujc7
hujc7 force-pushed the jichuanh/fix-template-generator branch from d19e140 to 7f56599 Compare June 3, 2026 22:36
@hujc7
hujc7 force-pushed the jichuanh/fix-template-generator branch 2 times, most recently from 3a7aab3 to a1477e0 Compare June 4, 2026 00:50
@hujc7 hujc7 changed the title [Fix] Make template-generator output import-safe and drop unsupported AMP [Fix] Make generated template projects import without Kit (no eager omni.ext) Jun 4, 2026
The generated project package imported the example UI extension
(ui_extension_example.py -> import omni.ext) from its __init__, so
importing the project headless (e.g. Gym registration before
SimulationApp) failed with "ModuleNotFoundError: No module named
'omni.ext'". Load the UI extension via its own config/extension.toml
[[python.module]] entry instead, keeping the package root omni-free,
and add the missing omni.ui import the example relies on.

Also make the generator fail loudly when a requested agent config
template is missing: it previously skipped silently, emitting a project
whose Gym registration referenced a non-existent config file.

Extend the template-generator tests with regression coverage: omni/pxr
import-safety of the generated package, extension.toml UI-module
registration, generated-code syntax validity, no top-level backend
imports in generated env modules, and per-library agent-config
completeness.

NVBug 6251247
@hujc7
hujc7 force-pushed the jichuanh/fix-template-generator branch from a1477e0 to 374d842 Compare June 4, 2026 00:55
@@ -10,5 +10,8 @@ Python module serving as a project/extension template.
# Register Gym environments.
from .tasks import *

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Stray review comment — This line (#rj: what's the consequence of this change? does it require all other scripts to import?) looks like an inline reviewer note that was accidentally committed. Should be removed before merge.

hujc7 added 5 commits June 4, 2026 07:41
The skrl training scripts resolve the env config (resolve_task_config) before launch_simulation boots Kit, so the env config and the MDP terms it references must import without pxr. Generated manager-based projects loaded pxr eagerly two ways: the task mdp package re-exported isaaclab.envs.mdp with a star import, which force-resolves the whole lazy namespace, and mdp/rewards.py imported Articulation at module scope for a type-only annotation. Both pulled pxr before Kit, aborting startup with "TfNotice ... has not been created yet".

Switch the generated mdp package to lazy_export() with a .pyi stub and guard the Articulation import under TYPE_CHECKING, matching the patterns used across isaaclab and PR isaac-sim#5916. Add a regression test that resolves the generated env config with omni and pxr import-blocked.
The template-generator CI tests land together with the import-safety fixes in this PR, so the single Fixed fragment (jichuanh-fix-template-generator.rst) already represents the isaaclab_rl change. Remove the empty template-generator-tests.skip carried from the chained test branch so one fragment per package remains.
After the core/contrib split (isaac-sim#5891), isaaclab_tasks/direct and isaaclab_tasks/manager_based became namespace dirs with no __init__.py. import_packages walks via pkgutil.iter_modules, which skips namespace packages, so a generated internal task placed under them was never discovered or registered. The generator now creates the per-workflow __init__.py (only when missing, so an existing package is never clobbered) in _generate_tasks, covering both internal and external paths; the duplicate loop in the external path is removed.

Adds a regression test asserting pkgutil.iter_modules lists the generated workflow dirs as packages.
End-to-end guard for the generate-then-it-just-works promise: generate an external project and assert every workflow's task id lands in the Gym registry on a plain import, with no manual step.
isaaclab_rl is touched only by the generator tests; the actual fix lives in tools/template (not a versioned package). So isaaclab_rl warrants no changelog entry or version bump — use a .skip fragment instead of a Fixed entry.
@hujc7
hujc7 marked this pull request as ready for review June 4, 2026 20:43
@hujc7
hujc7 requested a review from hhansen-bdai as a code owner June 4, 2026 20:43
@greptile-apps

greptile-apps Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes two independent bugs in the template-project generator: generated packages could not be imported headlessly because the package __init__ eagerly pulled in omni.ext, and a missing agent-config template was silently skipped, producing a broken project at train time instead of failing at generation time. It also adds 15 regression tests that lock both fixes in place.

  • Headless-import fix: __init__ext drops from .ui_extension_example import *; extension.toml gains a dedicated [[python.module]] entry for <name>.ui_extension_example so Kit's extension manager still discovers it; rewards.py moves Articulation behind TYPE_CHECKING; mdp/__init__.py switches to lazy_export() with a companion .pyi stub.
  • Generator hardening: _generate_task_per_workflow now raises FileNotFoundError on a missing agent-config template instead of silently continue-ing; workflow-directory __init__.py creation is moved from _external() into _generate_tasks() so internal tasks also get importable workflow packages.
  • Test scaffolding: new test_template_generator.py covers algorithm discovery, Gym registry entry points, VS Code launch configs, omni/pxr import safety, TOML UI-module registration, Python syntax validity, and per-library agent-config completeness.

Confidence Score: 4/5

The changes are safe to merge; the core template and generator fixes are well-targeted and the 15 new tests verify both halves of the headless-import fix and the generator's new fail-loud behavior.

All changed code paths are covered by the new regression tests, and the fixes are narrow and self-contained. The only issue found is a stale docstring in one test that describes the old silent-skip behavior this PR removes, which could mislead a developer investigating a future failure.

source/isaaclab_rl/test/test_template_generator.py — the docstring on test_each_requested_agent_cfg_file_is_generated describes the removed continue behavior and should be updated.

Important Files Changed

Filename Overview
source/isaaclab_rl/test/test_template_generator.py New 590-line test file with 15 tests covering algorithm discovery, registry entry points, import safety, TOML registration, syntax validity, and agent-config completeness. One test docstring (test_each_requested_agent_cfg_file_is_generated) describes the old silent-skip behaviour that this PR removes.
tools/template/generator.py Two orthogonal improvements: (1) missing agent-config template now raises FileNotFoundError instead of silently continuing; (2) workflow-directory init.py creation moved from _external() into _generate_tasks() so it covers internal tasks too.
tools/template/templates/extension/__init__ext Removes the eager from .ui_extension_example import * that pulled in omni.ext at package import time, replacing it with a comment explaining the Kit-only load path.
tools/template/templates/extension/config/extension.toml Adds a second [[python.module]] entry for {{ name }}.ui_extension_example so Kit's extension manager still discovers and loads the UI extension now that the package root no longer imports it.
tools/template/templates/tasks/manager-based_single-agent/mdp/init.py Replaces eager star imports with lazy_export(), deferring resolution of isaaclab.envs.mdp names until first access so the module is safe to import before SimulationApp.
tools/template/templates/tasks/manager-based_single-agent/mdp/init.pyi New stub that drives lazy_export(): declares joint_pos_target_l2 as an explicit export, sets isaaclab.envs.mdp as a lazy fallback wildcard, and guides type checkers.
tools/template/templates/tasks/manager-based_single-agent/mdp/rewards.py Moves from isaaclab.assets import Articulation behind a TYPE_CHECKING guard so the rewards module no longer triggers eager pxr loading at import time.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["import project\n(headless / before SimulationApp)"] --> B["__init__.py\n(tasks registration only)"]
    B --> C["Gym registry populated"]
    B -.->|"NOT imported"| D["ui_extension_example.py\nomni.ext / omni.ui"]

    E["Kit extension manager"] -->|"[[python.module]] name"| B
    E -->|"[[python.module]] name.ui_extension_example"| D

    F["generate()"] --> G{"agent template\nexists?"}
    G -->|"Yes"| H["Write agent config file"]
    G -->|"No"| I["raise FileNotFoundError\n(was: silent continue)"]

    F --> J["_generate_tasks()"]
    J --> K["Create workflow/__init__.py\nif missing\n(was: only in _external)"]
    K --> L["Task importable by\npkgutil.iter_modules"]
Loading

Reviews (1): Last reviewed commit: "chore: make template-generator changelog..." | Re-trigger Greptile

Comment on lines +331 to +332
{"name": "direct", "type": "multi-agent"},
]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Stale docstring describes the removed behaviour

The docstring says "A missing agent template is silently skipped (``generator.py`` ``continue``)", but this PR explicitly removes that continue path and replaces it with a loud FileNotFoundError. A future reader debugging a generator error will be confused, because the docstring points them at code that no longer exists. The test body itself (checking that every requested config file is present) accurately reflects the new contract — the docstring should too.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@hujc7
hujc7 requested a review from StafaH June 4, 2026 20:47
hujc7 added 2 commits June 4, 2026 20:55
The generator now raises on a missing agent template instead of silently skipping; update the test docstring to match (greptile P2).
@hujc7
hujc7 requested review from AntoineRichard and ooctipus June 5, 2026 01:23
@hujc7 hujc7 added this to Isaac Lab Jun 5, 2026
@hujc7 hujc7 moved this to In review in Isaac Lab Jun 5, 2026
@kellyguo11

Copy link
Copy Markdown
Contributor

pls also cherry pick to the release branch

@kellyguo11
kellyguo11 merged commit 6f8eba9 into isaac-sim:develop Jun 5, 2026
37 checks passed
@github-project-automation github-project-automation Bot moved this from In review to Done in Isaac Lab Jun 5, 2026
kellyguo11 added a commit that referenced this pull request Jun 7, 2026
…mni.ext) (#5941) (#5993)

Cherry-picks #5941 from develop to release/3.0.0-beta2.

The generated template project pulled Kit/pxr eagerly, so importing it
headless (Gym registration before SimulationApp) failed with
`ModuleNotFoundError: No module named 'omni.ext'` and `TfNotice ... has
not been created yet`. The fix loads the UI extension via its own
`config/extension.toml` entry, switches the generated `mdp` package to
`lazy_export()` with a `.pyi` stub, guards type-only imports under
`TYPE_CHECKING`, creates the per-workflow `__init__.py` so internal
tasks register after the core/contrib split, and makes the generator
fail loudly on a missing agent template. Adds template-generator CI
regression coverage.

Validation:

- ./isaaclab.sh -f

Co-authored-by: Kelly Guo <kellyg@nvidia.com>
@kellyguo11 kellyguo11 mentioned this pull request Jun 26, 2026
5 of 7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working infrastructure isaac-lab Related to Isaac Lab team

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants