Skip to content

[Newton] Delegate homogeneous world prefix generation to ModelBuilder.replicate() - #7453

Open
camevor wants to merge 3 commits into
isaac-sim:developfrom
camevor:newton-world-prefixes
Open

[Newton] Delegate homogeneous world prefix generation to ModelBuilder.replicate()#7453
camevor wants to merge 3 commits into
isaac-sim:developfrom
camevor:newton-world-prefixes

Conversation

@camevor

@camevor camevor commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Description

Note: This depends on newton-physics/newton#4012, which is first released with Newton 1.6.

Env-local Newton sites were labelled the same in every environment, and the homogeneous cloning path renamed every replicated entity in a second pass after replication.

Env name in env-local site labels. A bodyless per-environment site carried the label ft_0 in every environment. cl_register_site now takes the destination_template of the clone-plan row that requested the site, so the label names the environment it lands in — /World/envs/env_3/ft_0. Sites are still resolved by index, so consumers that look them up by label and index are unaffected.

ClonePlan.env_template. The destination template for one environment was a constructor argument the plan discarded, leaving a consumer holding a row unable to recover where the environment ends. It is now recorded on the plan and handed to backend replication contexts alongside global_paths.

Replication names its own copies. The homogeneous Newton path rebases the prototype's labels once — a few hundred entries — and passes the per-env roots to ModelBuilder.replicate(), instead of rewriting every label in every world afterwards. That pass cost 215 ms on Isaac-Velocity-Flat-G1 at 4096 environments. The resulting labels are identical either way; a prototype whose labels a per-world prefix cannot spell keeps the previous path, and the string custom attributes are still rewritten in rename_builder_labels.

Type of change

  • (Startup performance enhancement)
  • New feature (non-breaking change which adds functionality)

Release backport

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

Checklist

Docker and GPU tests run on demand. Push the commits you want tested, then
comment run-ci on the pull request.

  • 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 (do not edit CHANGELOG.rst or bump extension.toml — CI handles that)
  • I have added my name to the CONTRIBUTORS.md or my name already exists there

Rewriting every merged label after replication is a second full pass over what
replication just produced, and it scales with environment count. `replicate()`
now takes a per-world label prefix, so the prototype's labels are rebased once
and each copy comes out named for the environment it lands in; `ClonePlan`
records `env_template` to supply that boundary.

A prototype the boundary cannot express keeps the old path, and the string
custom attributes are still rewritten here.
@camevor
camevor requested a review from a team August 31, 2026 17:02
@github-actions github-actions Bot added bug Something isn't working isaac-lab Related to Isaac Lab team infrastructure labels Aug 31, 2026
@greptile-apps

greptile-apps Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR propagates the clone plan’s environment template into backend replication and delegates homogeneous Newton entity naming to ModelBuilder.replicate(). It also qualifies per-world site labels with their destination environment and updates Newton to the required pinned 1.6 development commit.

  • Stores env_template on ClonePlan and passes it to replication contexts.
  • Rebases homogeneous prototype labels once and supplies per-environment label prefixes during Newton replication.
  • Carries destination templates through site registration so bodyless per-world sites receive environment-qualified labels.
  • Preserves the existing rewrite path when labels cannot be represented by a per-world prefix.
  • Updates tests, changelog fragments, and the Newton dependency lock entry.

Confidence Score: 5/5

The PR appears safe to merge, with no actionable changed-code defect identified.

The new template and label-prefix data are propagated consistently through clone planning, backend construction, site registration, replication, and fallback rewriting, while body bindings and custom-attribute rewriting remain intact.

Important Files Changed

Filename Overview
source/isaaclab/isaaclab/cloner/clone_plan.py Persists the environment destination template in every clone-plan construction path.
source/isaaclab/isaaclab/cloner/replicate_session.py Propagates the clone plan’s environment template to each backend replication context.
source/isaaclab_newton/isaaclab_newton/cloner/newton_clone_utils.py Adds prototype-label rebasing, delegated per-environment naming, and environment-qualified site-label generation while retaining fallback rewriting.
source/isaaclab_newton/isaaclab_newton/cloner/replicate.py Threads the environment template through Newton model construction and skips redundant entity rewriting only when replication already named the copies.
source/isaaclab_newton/isaaclab_newton/physics/newton_manager.py Extends pending site registrations with destination-template identity and carries it into injected per-world sites.
source/isaaclab_newton/isaaclab_newton/sim/views/newton_site_frame_view.py Includes destination templates in resolved bodyless-site specifications and registration.
pyproject.toml Pins Newton to the development commit providing label-prefix replication support.
uv.lock Updates only Newton’s source and version while preserving its resolved dependency set.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart LR
    A[ClonePlan with env_template] --> B[Backend replication context]
    B --> C[Build Newton source prototypes]
    C --> D{Homogeneous and labels rebase cleanly?}
    D -- Yes --> E[ModelBuilder.replicate with per-env prefixes]
    D -- No --> F[Replicate then rewrite labels]
    E --> G[Rewrite string custom attributes]
    F --> G
    B --> H[Register per-world sites with destination template]
    H --> I[Environment-qualified site labels]
    G --> J[Final Newton model]
    I --> J
Loading

Reviews (1): Last reviewed commit: "Update newton pin" | Re-trigger Greptile

@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 replication-prefix optimization is well scoped, but two compatibility issues need correction: the fast path mutates retained prototype labels, and NewtonReplicateContext.__init__ silently rebinds existing positional arguments by inserting env_template before device.

  • Design and architecture: Delegating homogeneous label prefixing to ModelBuilder.replicate() with a guarded fallback is sound, but rebasing the source builder in place makes retained prototype state depend on the replication path. Rebase a copy or restore labels after replication.
  • API: ClonePlan.env_template is defaulted and propagated consistently to in-tree contexts. However, inserting env_template before existing positional parameters in NewtonReplicateContext.__init__ breaks positional-call compatibility and the new argument is omitted from the docstring. Preserve the existing parameter order or make the new argument keyword-only.
  • Implementation: The batched and per-world site paths and three-value replication result are wired through their consumers and tests. The remaining implementation defect is that _rebase_to_env permanently changes builders later retained in NewtonManager._cl_protos, exposing environment-relative labels to single-model consumers.

Minor fixes needed. Posted 2 actionable findings inline.

Automated review; human maintainers own approval decisions.

# env root, instead of rewriting every label in every world afterwards.
label_prefixes = None
prototype_env = clone_path.match(sources[0], env_template) if env_ids is not None else None
if prototype_env is not None and _rebase_to_env(source_builder, env_template.format(prototype_env.instance)):

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 — Rebase mutates retained prototype builders

_rebase_to_env rewrites source_builder labels in place, and that same object is returned in source_builders, stored as NewtonManager._cl_protos, and handed out by copy_newton_clone_source for single-model consumers. On the delegated path the retained prototype now carries env-relative labels (Robot/base) instead of the clone-plan source path, so prototype label state differs between the two cloning paths. Rebase a copy, or restore the labels after replicate().

self,
stage: Usd.Stage,
global_paths: tuple[str, ...] = (),
env_template: str = DEFAULT_ENV_TEMPLATE,

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 · Api — New parameter inserted before existing positional arguments

env_template is inserted between global_paths and device in NewtonReplicateContext.__init__, so an existing positional call such as NewtonReplicateContext(stage, paths, "cuda:0") silently binds the device string to the template and falls back to device="cpu". The USD and OvPhysX contexts append the parameter last. Append it after the existing parameters (or make it keyword-only) and document it in the Args block, which currently omits it.

@camevor camevor self-assigned this Aug 31, 2026
@camevor camevor removed the bug Something isn't working label Aug 31, 2026

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

Since this is moving the newton pin, we won't be able to backport this to our release branch, it'll have to stay in develop until GA. Is that okay?

from pxr import Gf, Sdf, Usd, UsdGeom, Vt

from ._fabric_notices import disabled_fabric_change_notifies
from .cloner_cfg import DEFAULT_ENV_TEMPLATE

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.

Please use absolute imports here and elsewhere (feel free to change other imports in the file to match)

xforms = _compose_world_xforms(positions_np, quaternions_np, source_xform_inv)
builder.replicate(source_builder, num_worlds, xforms=xforms)

# One source populating every world is the shape replication can name itself: rebase the

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.

The wording here is a bit confusing "every world is the shape replication can name itself:"

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

Labels

infrastructure isaac-lab Related to Isaac Lab team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants