Skip to content

[Core] Refactor and cleanup core subpackage for 3.0 [1/N] - #7958

Merged
StafaH merged 6 commits into
isaac-sim:developfrom
StafaH:core-cleanup/01-imports
Sep 23, 2026
Merged

StafaH merged 6 commits into
isaac-sim:developfrom
StafaH:core-cleanup/01-imports

Conversation

@StafaH

@StafaH StafaH commented Sep 22, 2026 •

Copy link
Copy Markdown
Collaborator

Description

First PR in a series that splits the core cleanup in #7949 into small, reviewable pieces. This PR only changes how imports are written in source/isaaclab/isaaclab and adds the import rules to AGENTS.md; there is no logic change.

Import rules (new ## Code style section in AGENTS.md)

  • Imports are grouped in PEP 8 order: __future__, standard library, third-party, Omniverse runtime packages, Isaac Lab packages, then local relative imports. The existing ruff isort config already enforces this.
  • Imports from the same package are relative when the target is at most three leading dots away (e.g. from ...utils import math as math_utils), and absolute for deeper targets and other packages.
  • Modules with an if __name__ == "__main__": block keep absolute imports, because some are executed by file path (e.g. benchmark/entrypoints/multigpu.py launches itself as the worker script), where relative imports fail.

Changes in the core package

  • Applied the rule above across the package with an AST-based rewrite: 725 imports converted (686 from isaaclab.x import ..., 39 import isaaclab.x.y as z -> from ...x import y as z), then re-sorted with ruff. 103 imports that would need more than three dots stay absolute.
  • No imports are added, removed, or moved between scopes.
  • test/sensors/test_ray_caster_kernels.py loaded utils/warp/kernels.py by file path, which cannot resolve relative imports. It now imports the kernels as regular package modules; they import without Kit.

Verification:

  • Every file's AST is identical to develop once relative imports are resolved to absolute names (520 files).
  • Importing every module under isaaclab gives the same result as on develop, both in one process and with each of the 203 top-level modules in a fresh process (checks for import-order-dependent cycles).
  • isaaclab train --rl_library rsl_rl --task Isaac-Cartpole-Direct --num_envs 16 presets=newton_mjwarp --max_iterations 5 completes.
  • pytest source/isaaclab/test/benchmark source/isaaclab/test/cli source/isaaclab/test/app/test_app_launcher_argv.py: 661 passed.
  • ruff check (including isort) / ruff format are clean.

Type of change

  • Code cleanup (non-breaking, no functional change)

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 added a changelog fragment under source/<pkg>/changelog.d/ for every touched package (.skip)

  • I have added my name to the CONTRIBUTORS.md or my name already exists there

  • Backport this pull request to the active release branch after it merges into develop

@StafaH
StafaH requested a review from a team September 22, 2026 23:03
@github-actions github-actions Bot added isaac-mimic Related to Isaac Mimic team isaac-lab Related to Isaac Lab team labels Sep 22, 2026
@greptile-apps

greptile-apps Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

The PR is not safe to merge until the missing UsdGeom runtime import is restored, because ordinary spawner calls otherwise fail after creating their source prim.

Findings

  1. P1 UsdGeom Is No Longer Imported ▶
  2. P2 Import Timing Excludes Work ▶
  3. P2 Import Text Corrupts Documentation ▶

Summary

This PR broadly converts internal Isaac Lab imports to relative forms, removes unused imports, and hoists several standard-library imports. Most import-path changes preserve the lazy package-export behavior, but one removed runtime import breaks normal spawner execution; the benchmark import hoists also alter startup measurements, and one accidental line corrupts generated documentation.

Reviews (1) · Last reviewed commit: "Use relative imports and drop unused imp..."

@functools.wraps(func)
def wrapper(prim_path: str | Sdf.Path, cfg: SpawnerCfg, *args, **kwargs):
from pxr import Sdf, UsdGeom # noqa: PLC0415
from pxr import Sdf # noqa: PLC0415

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.

P1 UsdGeom Is No Longer Imported

The wrapper now imports only Sdf, but it still calls UsdGeom.Imageable(prim). Because every SpawnerCfg defines visible, normal decorated spawns reach this branch and raise NameError after creating the source prim, preventing the asset from spawning.

Suggested change
from pxr import Sdf # noqa: PLC0415
from pxr import Sdf, UsdGeom # noqa: PLC0415

Comment on lines +10 to +18
import argparse
import contextlib
import math
import os
import random
import sys
import time
from datetime import datetime
from typing import TYPE_CHECKING, Any

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 Import Timing Excludes Work

Hoisting these standard-library imports to module scope moves their cold-import work before run() records imports_t0. The dispatcher loads each backend module before invoking run(), and modules such as math, random, and importlib.metadata are not guaranteed to be preloaded. As a result, StartupTime.python_imports excludes work it previously measured and can vary with module-cache state. The same issue affects the changed RL-Games, RSL-RL, SB3, and SKRL benchmark entrypoints.

Knowledge Base Used: Learning workflows

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!


* :attr:`pose_range` - a dictionary of pose ranges for each axis. The keys of the dictionary are ``roll``,
``pitch``, and ``yaw``. The position is sampled from the flat patches of the terrain.
import omni.replicator.core as rep # noqa: PLC0415

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 Import Text Corrupts Documentation

This line is inside the function's docstring rather than executable code. It will appear as part of the pose_range description in help() and generated API documentation, misleading users with an unrelated Replicator import.

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!

@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.

Isaac Lab Review Bot

The import refactor generally preserves module resolution and runtime behavior across the affected subpackages. One concrete documentation defect remains: a stray import statement was inserted into the public reset_root_state_from_terrain docstring and should be removed before merge.

  • Design and architecture: The relative-import depth across the changed envs/mdp, sim/spawners, sim/utils, benchmark, and utils modules resolves to the same package targets. No architectural issue is established by the import rewrites.
  • API: No public symbol or signature change is evident. However, the added line in reset_root_state_from_terrain corrupts that public event term's rendered API documentation and may trigger a Sphinx warning because it appears as an incorrectly indented docstring line.
  • Implementation: The hoisted standard-library imports are side-effect free, while heavyweight RL dependencies remain deferred inside entrypoints. Remove the stray import omni.replicator.core as rep text from the reset_root_state_from_terrain docstring; it has no runtime purpose there.

Minor fixes needed. Posted 1 actionable finding inline.

Automated review; human maintainers own approval decisions.


* :attr:`pose_range` - a dictionary of pose ranges for each axis. The keys of the dictionary are ``roll``,
``pitch``, and ``yaw``. The position is sampled from the flat patches of the terrain.
import omni.replicator.core as rep # noqa: PLC0415

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.

🟡 Warning · Implementation — Stray code line inserted into public docstring

An import omni.replicator.core as rep # noqa: PLC0415 line was inserted into the reset_root_state_from_terrain docstring, between the pose_range and velocity_range bullets and indented deeper than the list continuation. It has no runtime effect but corrupts the rendered API documentation for a public event term and risks a Sphinx indentation warning in a -W docs build. Remove the line.

@StafaH

StafaH commented Sep 22, 2026

Copy link
Copy Markdown
Collaborator Author

run-ci

@isaaclab-bot isaaclab-bot Bot added ci:run-docker Trigger the on-demand Docker and GPU CI workflow and removed ci:run-docker Trigger the on-demand Docker and GPU CI workflow labels Sep 22, 2026

@ooctipus ooctipus left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

maybe should update this rule to agent.md as well

@StafaH

StafaH commented Sep 23, 2026

Copy link
Copy Markdown
Collaborator Author

run-ci

@isaaclab-bot isaaclab-bot Bot added ci:run-docker Trigger the on-demand Docker and GPU CI workflow and removed ci:run-docker Trigger the on-demand Docker and GPU CI workflow labels Sep 23, 2026
@StafaH

StafaH commented Sep 23, 2026

Copy link
Copy Markdown
Collaborator Author

run-ci

@isaaclab-bot isaaclab-bot Bot added the ci:run-docker Trigger the on-demand Docker and GPU CI workflow label Sep 23, 2026
@isaaclab-bot isaaclab-bot Bot removed the ci:run-docker Trigger the on-demand Docker and GPU CI workflow label Sep 23, 2026
@StafaH
StafaH merged commit cff81e8 into isaac-sim:develop Sep 23, 2026
83 of 84 checks passed
@isaaclab-bot

isaaclab-bot Bot commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

Backported to release/3.0.0 as 5d3e0b6.

isaaclab-bot Bot pushed a commit that referenced this pull request Sep 23, 2026
# Description

First PR in a series that splits the core cleanup in #7949 into small,
reviewable pieces. This PR only changes how imports are written in
`source/isaaclab/isaaclab` and adds the import rules to `AGENTS.md`;
there is no logic change.

**Import rules (new `## Code style` section in `AGENTS.md`)**
- Imports are grouped in PEP 8 order: `__future__`, standard library,
third-party, Omniverse runtime packages, Isaac Lab packages, then local
relative imports. The existing ruff isort config already enforces this.
- Imports from the same package are relative when the target is at most
three leading dots away (e.g. `from ...utils import math as
math_utils`), and absolute for deeper targets and other packages.
- Modules with an `if __name__ == "__main__":` block keep absolute
imports, because some are executed by file path (e.g.
`benchmark/entrypoints/multigpu.py` launches itself as the worker
script), where relative imports fail.

**Changes in the core package**
- Applied the rule above across the package with an AST-based rewrite:
725 imports converted (686 `from isaaclab.x import ...`, 39 `import
isaaclab.x.y as z` -> `from ...x import y as z`), then re-sorted with
ruff. 103 imports that would need more than three dots stay absolute.
- No imports are added, removed, or moved between scopes.
- `test/sensors/test_ray_caster_kernels.py` loaded
`utils/warp/kernels.py` by file path, which cannot resolve relative
imports. It now imports the kernels as regular package modules; they
import without Kit.

Verification:
- Every file's AST is identical to `develop` once relative imports are
resolved to absolute names (520 files).
- Importing every module under `isaaclab` gives the same result as on
`develop`, both in one process and with each of the 203 top-level
modules in a fresh process (checks for import-order-dependent cycles).
- `isaaclab train --rl_library rsl_rl --task Isaac-Cartpole-Direct
--num_envs 16 presets=newton_mjwarp --max_iterations 5` completes.
- `pytest source/isaaclab/test/benchmark source/isaaclab/test/cli
source/isaaclab/test/app/test_app_launcher_argv.py`: 661 passed.
- `ruff check` (including isort) / `ruff format` are clean.

## Type of change

- Code cleanup (non-breaking, no functional change)

## Checklist

- [x] I have read and understood the [contribution
guidelines](https://isaac-sim.github.io/IsaacLab/main/source/refs/contributing.html)
- [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with
`./isaaclab.sh --format`
- [x] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [x] I have added a changelog fragment under
`source/<pkg>/changelog.d/` for every touched package (`.skip`)
- [x] I have added my name to the `CONTRIBUTORS.md` or my name already
exists there

- [x] <!-- backport-active-release --> Backport this pull request to the
active release branch after it merges into `develop`

(cherry picked from commit cff81e8)
ooctipus added a commit that referenced this pull request Sep 24, 2026
…ng docs (#7957)

Backports the three changes from the September 20–23 `develop` audit
that are missing from `release/3.0.0`, alongside the existing
cloning-guide backport:

- #7722 (`4cf439dfeb`): reject a second `SimulationContext` construction
instead of silently discarding its configuration. Includes the original
fixture cleanup and regression coverage.
- #7893 (`22fcd71bc4`): validate DelayBuffer lag values before mutating
its live configuration.
- #7947 (`6e9ef17f59`): make `v3.0.0-EA` the default documentation
version in deployment and local multi-version builds.
- #7129 (`354168560f`): clarify that `replicate_physics=False` skips the
active physics context while other declared replication contexts still
run.

**Compatibility:** repeated `SimulationContext(...)` calls now raise.
Retrieve the live context with `SimulationContext.instance()`, or call
`clear_instance()` before constructing a replacement. The original major
changelog fragment includes this migration.

The runtime and test files match current `develop`. The docs-default
backport adapts the release branch's existing redirect template,
validates the target page, and preserves explicit overrides. The
cloning-guide backport preserves the current release APIs; its obsolete
sections were already removed.

## Release audit

Checked all **35 PRs** merged into `develop` from **2026-09-20 16:43:18
UTC** through `cff81e8473` (September 23), against release head
`5d3e0b695e`. **32 are already covered; the remaining three are included
here.** Git history, patch equivalence, GitHub's merged PR list, and
remaining file differences were checked. Branch-specific
version/changelog compilation and existing release-only changes are
preserved.

<details>
<summary>Already covered PRs</summary>

26 have an equivalent patch in release: #7919, #7922, #7923, #7924,
#7925, #6758, #7928, #7902, #7927, #7891, #7931, #7691, #7861, #7929,
#7916, #7939, #4609, #7942, #7940, #7948, #7937, #7955, #7960, #7961,
#7970, #7958.

Six were squash-merged or adapted: #7530 and #7899 in #7926; #7637 in
#7933; #7860 in #7936; #7954 and #7950 in #7964. Their implementation
differences were checked against the current release tree.

</details>

## Validation

- **276 tests passed**: SimulationContext (51, including CPU/CUDA),
headless context construction (15), nine schema/fragment suites (165),
four manager suites (38), and DelayBuffer (7).
- Both backported regressions reproduce with the original release
implementations.
- Docs redirect recipe: local/deployment EA defaults, explicit override,
and missing-target rejection passed with a stubbed Sphinx builder.
- All 22 changed files match the intended backport scope; `uv run
isaaclab -f` and `git diff --check` passed.
- Fresh Sphinx validation (`-b dummy -W --keep-going`): passed without
warnings, excluding static assets as the HTML builder does. Full HTML
documentation CI is running.

Local runtime validation used PyTorch 2.12.0, CUDA 13.0, Isaac Sim
6.0.1.0, and an RTX 5090. Existing runtime/deprecation warnings
occurred; the CI jobs validate the pinned environments.

The previous [docs CI
failure](https://github.com/isaac-sim/IsaacLab/actions/runs/35795116307/job/106972539281)
was an external connection reset fetching the Omniverse intersphinx
inventory, producing one warning under `-W`. That URL returned HTTP 200
when rechecked. This update starts a fresh docs build.

---------

Co-authored-by: hujc <[email protected]>
Co-authored-by: Zihan Xu <[email protected]>
@StafaH
StafaH deleted the core-cleanup/01-imports branch October 10, 2026 19:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

isaac-lab Related to Isaac Lab team isaac-mimic Related to Isaac Mimic team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants