Skip to content

Move external wrench frame selection into WrenchComposer - #7536

Merged
ooctipus merged 12 commits into
isaac-sim:developfrom
AntoineRichard:antoiner/wrench-submission-plan
Sep 24, 2026
Merged

ooctipus merged 12 commits into
isaac-sim:developfrom
AntoineRichard:antoiner/wrench-submission-plan

Conversation

@AntoineRichard

@AntoineRichard AntoineRichard commented Sep 3, 2026 •

Copy link
Copy Markdown
Collaborator

Description

WrenchComposer.compose_to_body_frame() was called unconditionally by every backend writer on every physics step. It reads body_com_pos_w and body_link_quat_w, which on PhysX chains to _ensure_fk_fresh() → update_articulations_kinematic() (a scene-global articulation FK pass) plus root_view.get_link_transforms(), then launches the composition kernel.

That work is unnecessary whenever the buffered wrench is already in a frame the consumer accepts. This PR moves the frame decision into the composer, which hands each writer the cheapest valid representation:

  • all-local content → the local buffers, untouched. An all-local wrench composes to exactly itself, because the pose data is multiplied by zero.
  • all-global-at-CoM content → the global buffers, untouched, submitted in the world frame by backends that accept one.
  • anything else → composed as before.

Writers declare what they can consume once at construction (supports_world_at_com) and call get_forces_and_torques() per step. All frame logic stays inside the composer; no writer touches a raw buffer or knows a frame rule.

New public API

class WrenchComposer:
    def __init__(self, asset, *, supports_world_at_com: bool = False) -> None: ...
    def get_forces_and_torques(self) -> tuple[wp.array, wp.array, bool]: ...

forces, torques, is_global = composer.get_forces_and_torques()

Additive only. compose_to_body_frame(), out_force_b, and out_torque_b remain public and behaviorally unchanged, so no deprecation cycle is needed. supports_world_at_com defaults to False, which is exactly the previous behavior.

The composer tracks local contributions, global contributions, and positioned global forces with plain booleans. These flags stay conservative across partial resets and clear on a full reset(); checking whether a partial reset removed every contribution would require scanning the buffers. The returned is_global boolean follows the existing asset API and is passed directly to the backend. No frame enum, content bitmask, or classification helper is needed.

Equivalence

All three branches are exact, from compose_wrench_to_body_frame:

  • local only: the three global buffers are zero, so both quat_rotate_inv terms vanish and the output is identically (local_force_b, local_torque_b). Note a positioned local force also qualifies — the kernel folds cross(P_b, F_b) straight into local_torque_b.
  • global-at-CoM only: global_force_w and the local buffers are zero, so corrected_torque_w == global_torque_w. Submitting the world buffers is the same wrench, provided the consumer applies force at the CoM — verified against the vendored omni.physics.tensors API, where position_data=None means "at the link transform" for both is_global values, so the flag only reinterprets the vectors' frame and never moves the application point.
  • anything else: unchanged.

Backend coverage

backend supports_world_at_com change
PhysX True writer passes the returned is_global directly
OvPhysX True writer passes is_global to the packing kernel to skip the inline rotate
Newton False (default) writer swaps to get_forces_and_torques(); no constructor change

OvPhysX is the largest win. Its wrench binding wants a world-frame wrench, so a global wrench previously round-tripped: the composer rotated world→body, then the packing kernel rotated body→world. Measured on this branch with a body rotated 90° about +z, a local force (1,0,0) emits (0,1,0) while a global force (1,0,0) emits (1,0,0) — an exact round trip, so skipping both rotations is output-preserving. The packed [6:9] link position is still written unconditionally on both paths.

Newton keeps the body frame because it binds a body-frame array to the solver. Worth noting for a follow-up: its writer kernel already performs the same body→world rotation OvPhysX's does, so Newton could plausibly take the same flag and win the global-at-CoM path too. That is deliberately out of scope here.

Validation

The existing composer rotation, positioned-force, merge, reset, and overwrite tests now exercise get_forces_and_torques() directly. Existing frame/position cases cover the four add/set index/mask APIs. The existing articulation body-ordering test checks local/world forwarding, composition avoidance, and packed link positions. One shared rigid-object writer check replaces the separate backend/equivalence suites and their duplicate rotation kernel.

Local results:

  • test_wrench_composer.py: 375 passed on CPU/CUDA.
  • Articulation ordering and rigid-object wrench writer checks: 24 passed across PhysX, Newton, and OvPhysX.
  • uv run isaaclab -f: all pre-commit checks passed.
  • Structural audit: no new test classes or kernels; no production changes in the test consolidation. The composer architecture regression still rejects frame/content enums, the classification layer, and the old submission alias.

Regression sensitivity was checked by temporarily restoring unconditional composition and stale-pose caching: the updated existing tests fail on unnecessary pose reads and on a second read after the body rotates, respectively.

The previously recorded paired Python dispatch microbenchmark changed local buffer selection from about 99 ns to 46 ns per call, and global-at-CoM selection from 127 ns to 60 ns. This measures buffer selection only, not end-to-end simulation; production code is unchanged by the test consolidation.

Performance

The end-to-end measurements below were recorded for the original optimization; they were not rerun for the boolean/API simplification.

Real PhysX, RTX 5090, ANYMAL-C (17 bodies) × 4096 envs = 69,632 links. Same-process paired A/B with the arm order alternated per iteration, 400–500 pairs, 95% CI on paired differences. Baseline is compose_to_body_frame() — what the writers previously called unconditionally.

scope content baseline patched paired delta 95% CI
composition path only global-at-CoM 0.2194 ms 0.0191 ms −0.2003 ms (−91.3%) [0.1915, 0.2091]
composition path only local 0.1926 ms 0.0159 ms −0.1767 ms (−91.8%) [0.1712, 0.1822]
full write_data_to_sim global-at-CoM 1.0799 ms 0.9897 ms −0.0902 ms (−8.4%) [0.0797, 0.1007]
full write_data_to_sim local 1.0072 ms 0.9305 ms −0.0767 ms (−7.6%) [0.0719, 0.0815]

Read the end-to-end row as the honest headline: ~0.08 ms per asset per physics step. Roughly half the isolated saving does not reach the caller, because other work in write_data_to_sim touches body poses anyway and pays part of that cost regardless. A cuboid rigid-object scene at the same env count saved only ~6.5 µs, as expected — there is no articulation FK pass to skip.

Scope caveat: no in-tree task sets is_global=True today (both shipped apply_external_force_torque events use the local default), so the local path is what delivers value now, and it is the one that reaches every backend.

Supersedes

This replaces two open PRs, both of which found one half of this problem:

  • Optimize PhysX global external wrench submission #7431 (@NeoZng) identified the global-at-CoM case and the cost of the pose read. Its mechanism is correct and its writer-level measurement is corroborated here. It is superseded on placement rather than substance: it put the frame decision in three PhysX writers behind a public eligibility flag, leaving Newton and OvPhysX unserved. The credit for the world-at-CoM half of this mechanism is theirs.
  • [Performance] Cache unchanged local wrench composition #7362 cached composition for unchanged local wrenches. Superseded because not composing at all is strictly stronger — the cache does nothing when the wrench is rewritten every step, which is the common case for a per-step randomized push.

Type of change

  • 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

  • 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
  • I have added my name to the CONTRIBUTORS.md or my name already exists there

🤖 Generated with Claude Code

Strengthen the resolve_submission composer tests to assert composed
values instead of just the frame, tautology-proof the Newton frame
pin, cover the OvPhysX ordered-world articulation path under a
nonidentity body ordering, align the PhysX benchmark fixture with
production composer construction, and drop a dead field setup left
over from a deleted RigidObject attribute.
@github-actions github-actions Bot added the isaac-lab Related to Isaac Lab team label Sep 3, 2026
@AntoineRichard

Copy link
Copy Markdown
Collaborator Author

@NeoZng could you see if this works for you. The bulk of the changes are tests.

@NeoZng

NeoZng commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Thanks @AntoineRichard — I tested the current patch cleanly on the latest develop. It works for our recovery-assist use case, and the architecture is cleaner.

Our reset-mode MDP event writes a persistent [0, 0, 300] N world-frame force at the torso CoM using permanent_wrench_composer.set_forces_and_torques_index(..., is_global=True) without positions; the wrench is then submitted on every physics step. Startup CoM randomization was up to +/-3 cm.

On Isaac Sim 6.0.1 with an RTX 5090, 388 WrenchComposer tests and 14 focused PhysX/Newton interface tests passed. A learner-free profile of the actual MDP term and full ManagerBasedRLEnv.step() path (5 physics substeps, 200 alternating pairs) gave:

Environments Full MDP step Paired saving (95% CI)
4096 67.1557 -> 66.6808 ms (-0.71%) 0.4749 ms [0.3446, 0.6052]
16384 123.2129 -> 122.3709 ms (-0.68%) 0.8420 ms [0.6322, 1.0519]

The patch is correct and ready for our use case.

@greptile-apps

greptile-apps Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR moves external-wrench submission-frame selection into WrenchComposer and updates PhysX, OvPhysX, and Newton writers to avoid unnecessary body-pose composition.

  • Adds conservative content-family tracking and a public resolve_submission() API.
  • Allows PhysX and OvPhysX to consume world-frame, center-of-mass wrenches directly.
  • Preserves body-frame submission for Newton and mixed or positioned inputs.
  • Adds composer and cross-backend tests, though the PhysX world-frame contract still lacks coverage with a nonzero COM offset.

Confidence Score: 4/5

The PR appears safe to merge, with a non-blocking request to cover PhysX world-frame submission for bodies whose center of mass differs from the link origin.

Content classification and backend frame propagation are internally consistent, and no behavioral regression was established; the remaining concern is a concrete integration-test gap around the external PhysX application-point contract.

Files Needing Attention: source/isaaclab_physx/isaaclab_physx/assets/articulation/articulation.py

Important Files Changed

Filename Overview
source/isaaclab/isaaclab/utils/wrench_composer.py Adds conservative wrench-content tracking and resolves the cheapest valid body- or world-frame representation.
source/isaaclab_ov/isaaclab_ov/assets/kernels.py Extends wrench-packing kernels to bypass rotation when input vectors are already world-frame.
source/isaaclab_physx/isaaclab_physx/assets/articulation/articulation.py Submits resolved wrench buffers in the selected frame; the world-frame application-point contract needs nonzero-COM integration coverage.
source/isaaclab_physx/isaaclab_physx/assets/rigid_object/rigid_object.py Uses direct resolved buffers and removes cached views tied specifically to composed outputs.
source/isaaclab_newton/isaaclab_newton/assets/articulation/articulation.py Uses resolved body-frame buffers while retaining Newton's default lack of world-frame support.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Buffered wrench contributions] --> B{Content family}
    B -->|Local only| C[Return local buffers<br/>BODY]
    B -->|Global-at-CoM only| D{Consumer supports world frame?}
    D -->|Yes| E[Return global buffers<br/>WORLD_AT_COM]
    D -->|No| F[Compose through body poses<br/>BODY]
    B -->|Mixed or globally positioned| F
    C --> G[Backend writer]
    E --> G
    F --> G
    G --> H[PhysX / OvPhysX / Newton submission]
Loading

Reviews (1): Last reviewed commit: "Fix wrench submission review gaps in tes..." | Re-trigger Greptile

position_data=None,
indices=self._ALL_INDICES,
is_global=False,
is_global=is_global,

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 COM Offset Coverage Missing

The new world-frame fast path submits the world-at-CoM force with position_data=None and is_global=True, without a positional torque correction. The added PhysX test only inspects mocked call arguments, while existing physical tests use bodies whose link origin and center of mass coincide. If the backend interprets position_data=None as the link origin for global forces, a body with a nonzero COM offset will receive an unintended moment and the current tests will not catch it. Please add an integration case with a nonzero COM offset that verifies the physical angular response.

@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 frame-selection design is centralized cleanly in WrenchComposer, but two performance regressions remain on the optimized path: full-coverage set_* operations can retain stale content classifications and disable fast paths indefinitely, while the PhysX rigid-object writer recreates flattened Warp views every simulation step.

  • Design and architecture: The composer-owned frame decision and backend capability declaration are sound. However, default full-coverage set_forces_and_torques_index and set_forces_and_torques_mask calls pass through partial-reset handling, so obsolete _content flags survive even though all wrench buffers were replaced. This can permanently prevent the optimization after earlier mixed or positioned-global content; full-coverage replacements should reset the classification.
  • API: The additive Frame, supports_world_at_com, and resolve_submission() surfaces preserve the existing body-frame APIs and default behavior. No actionable API compatibility issue was established.
  • Implementation: The backend frame propagation is coherent, including Newton retaining body-frame submissions and PhysX/OvPhysX accepting world-at-CoM submissions. The PhysX rigid-object writer nevertheless removes its cached flattened wrench views and now evaluates flatten().view(wp.float32) for force and torque on every write; cache views for each possible buffer returned by resolve_submission() to avoid reintroducing per-step metadata allocation.

Minor fixes needed. Posted 2 actionable findings inline.

Automated review; human maintainers own approval decisions.


self._active = True
self._dirty = True
self._content |= self._classify(forces, torques, positions, is_global)

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.

🔵 Suggestion · Design Architecture — Full-coverage set keeps stale content mask

With the default env_ids=None, _resolve_env_ids returns _ALL_ENV_INDICES, so the preceding self.reset(env_ids=env_ids) takes the partial-index branch and leaves _content untouched even though every buffer was zeroed. OR-ing the new classification then permanently pins the composer off the fast path after any earlier global/mixed content. The mask setter has the same behavior with its all-true default. Consider clearing _content when the selection covers all environments.

self.root_view.apply_forces_and_torques_at_position(
force_data=get_force_data(),
torque_data=get_torque_data(),
force_data=force_user.flatten().view(wp.float32),

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.

🔵 Suggestion · Implementation — Per-step wrench view allocation reintroduced

The removed _get_inst/perm_wrench_force/torque_f32 helpers existed specifically to avoid per-call wp.array metadata allocation in this writer (the sibling _root_link_pose_w_f32 caches are kept). The new code calls .flatten().view(wp.float32) on both buffers every write_data_to_sim, adding allocations on the exact hot path this PR optimizes. Cache the flattened views keyed on the returned buffer identity, since resolve_submission() may return either the local or composed arrays.

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

Full-coverage set_* operations retain stale content flags

With the default env_ids=None, set_forces_and_torques_index() first resolves it to _ALL_ENV_INDICES. It then calls reset(env_ids=env_ids), which takes the partial-reset path and does not clear _content, even though every environment has been reset.

As a result, replacing all buffered content does not replace its classification. For example:

  1. Set a positioned global wrench → _content == GLOBAL_POSITIONED.
  2. Set an all-local wrench with the default env_ids=None.
  3. _content becomes GLOBAL_POSITIONED | LOCAL.

The buffers now contain only local content, but resolve_submission() treats them as mixed and continues composing through the body poses. The same issue exists in set_forces_and_torques_mask() when its default all-true environment mask is used.

This is correctness-safe, but it can disable the fast path indefinitely—the behavior this PR is intended to optimize.

Could we preserve whether the original selection covered all environments and replace _content with the new classification in that case, while retaining the conservative OR behavior for genuinely partial updates?

@marcodiiga

Copy link
Copy Markdown
Collaborator

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 7, 2026
else:
composer = self._permanent_wrench_composer
composer.compose_to_body_frame()
force_user, torque_user, frame = composer.resolve_submission()

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.

Non-blocking correctness issue: this local-frame fast path skips the body_link_quat_w read that previously called _ensure_fk_fresh(). After a root or joint state write, PhysX requires update_articulations_kinematic() before link transforms reflect the new state. Because apply_forces_and_torques_at_position(..., is_global=False) rotates the wrench using those link transforms, the first local wrench after a reset can be rotated using the pre-reset orientation. Please call self.data._ensure_fk_fresh() before submission when frame is WrenchComposer.Frame.BODY; the timestamp guard makes this a no-op in steady state.

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

Reviewed the exact head. The frame-selection math and backend mappings are sound, and I found no blocking issue. I left one non-blocking PhysX articulation reset/FK edge case; the existing content-mask and flattened-view notes are performance follow-ups.

@AntoineRichard

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 11, 2026
@ooctipus ooctipus 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
@ooctipus

Copy link
Copy Markdown
Collaborator

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

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
@ooctipus
ooctipus merged commit 726f045 into isaac-sim:develop Sep 24, 2026
52 of 53 checks passed
ooctipus added a commit that referenced this pull request Sep 24, 2026
…#7536, #7971) (#7993)

## Description

Backports two merged changes to `release/3.0.0`:

- #7536 — Move external wrench frame selection into `WrenchComposer`
(`726f045a7dd2052311bf64099b096391468f0292`). Avoid unnecessary pose
reads and composition for local wrenches and supported world-frame
wrenches at the center of mass; preserve current-pose composition for
mixed or positioned global forces. Includes the PhysX, Newton, and
OvPhysX writers and regression tests.
- #7971 — Migrate remaining legacy schema configuration call sites to
fragments (`1370bb6f7ce1ab57b8939dd9e9b8bfde6f425000`). Updates
tutorials, demos, conversion tools, benchmarks, task configurations, and
test fixtures while retaining the original migration's exclusions.

Both backports apply unchanged, with no conflicts. All source changelog
fragments are included.

## Validation

- #7536: 375 composer tests and 24 backend writer tests passed before
adding #7971.
- #7971: 9 schema parity tests, 14 schema fragment tests, and the
OvPhysX gravity integration test passed on the combined branch.
- All 38 Python files changed by #7971 compile; the migrated NIST, UR10
particle-push, and reach task configurations import and instantiate
successfully.
- `uv run --no-sync isaaclab -f` and `git diff --check` passed on the
combined branch.
- Full Docker/GPU CI requested for the updated head.

---------

Co-authored-by: Antoine RICHARD <[email protected]>
Co-authored-by: vidurv-nvidia <[email protected]>
@ooctipus ooctipus self-assigned this Sep 25, 2026
@ooctipus ooctipus added this to the Isaac Lab 3.0 GA milestone Sep 25, 2026
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

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

7 participants