Repository navigation
Move external wrench frame selection into WrenchComposer - #7536
Conversation
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.
|
@NeoZng could you see if this works for you. The bulk of the changes are tests. |
|
Thanks @AntoineRichard — I tested the current patch cleanly on the latest Our reset-mode MDP event writes a persistent 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
The patch is correct and ready for our use case. |
Greptile SummaryThis PR moves external-wrench submission-frame selection into
Confidence Score: 4/5The 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
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]
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, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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_indexandset_forces_and_torques_maskcalls pass through partial-reset handling, so obsolete_contentflags 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, andresolve_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 byresolve_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) |
There was a problem hiding this comment.
🔵 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), |
There was a problem hiding this comment.
🔵 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.
There was a problem hiding this comment.
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:
- Set a positioned global wrench →
_content == GLOBAL_POSITIONED. - Set an all-local wrench with the default
env_ids=None. _contentbecomesGLOBAL_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?
|
run-ci |
| else: | ||
| composer = self._permanent_wrench_composer | ||
| composer.compose_to_body_frame() | ||
| force_user, torque_user, frame = composer.resolve_submission() |
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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.
|
run-ci |
|
run-ci |
|
run-ci |
…#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]>
Description
WrenchComposer.compose_to_body_frame()was called unconditionally by every backend writer on every physics step. It readsbody_com_pos_wandbody_link_quat_w, which on PhysX chains to_ensure_fk_fresh()→update_articulations_kinematic()(a scene-global articulation FK pass) plusroot_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:
Writers declare what they can consume once at construction (
supports_world_at_com) and callget_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
Additive only.
compose_to_body_frame(),out_force_b, andout_torque_bremain public and behaviorally unchanged, so no deprecation cycle is needed.supports_world_at_comdefaults toFalse, 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 returnedis_globalboolean 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:quat_rotate_invterms vanish and the output is identically(local_force_b, local_torque_b). Note a positioned local force also qualifies — the kernel foldscross(P_b, F_b)straight intolocal_torque_b.global_force_wand the local buffers are zero, socorrected_torque_w == global_torque_w. Submitting the world buffers is the same wrench, provided the consumer applies force at the CoM — verified against the vendoredomni.physics.tensorsAPI, whereposition_data=Nonemeans "at the link transform" for bothis_globalvalues, so the flag only reinterprets the vectors' frame and never moves the application point.Backend coverage
supports_world_at_comTrueis_globaldirectlyTrueis_globalto the packing kernel to skip the inline rotateFalse(default)get_forces_and_torques(); no constructor changeOvPhysX 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.uv run isaaclab -f: all pre-commit checks passed.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.write_data_to_simwrite_data_to_simRead 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_simtouches 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=Truetoday (both shippedapply_external_force_torqueevents 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:
Type of change
Release backport
developChecklist
pre-commitchecks with./isaaclab.sh --formatsource/<pkg>/changelog.d/for every touched packageCONTRIBUTORS.mdor my name already exists there🤖 Generated with Claude Code