Skip to content

Accelerate and strengthen asset tests [1/13] - #8134

Closed
AntoineRichard wants to merge 7 commits into
isaac-sim:developfrom
AntoineRichard:antoiner/asset-tests-p01-contract
Closed

AntoineRichard wants to merge 7 commits into
isaac-sim:developfrom
AntoineRichard:antoiner/asset-tests-p01-contract

Conversation

@AntoineRichard

@AntoineRichard AntoineRichard commented Sep 29, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Part 1/13 of the asset-test series (tracker: #7282). Scope: shared asset contract. Depends on #8131: the stronger collection writer checks here catch the PhysX set_inertias layout bug that #8131 fixes, so this branch contains its commits until it merges.

This PR moves the mocked *_iface asset tests into a shared contract suite under source/isaaclab/test/assets/contract/:

  • Capabilities: capabilities.py declares what each backend supports. Unsupported paths show up as skips that give the reason.
  • Public-surface inventory: public_surface.py classifies every public member of the asset base classes. There is one enforced inventory, so adding a public member to AssetBase without classifying it fails.
  • Scoped backend patches: each backend's physics manager is patched only for the test that needs it and restored afterwards. On develop these patches are applied at module level and leak into other tests.
  • Writer checks: writers check both the selected and the unselected cells in backend storage, not only that the call does not raise. The PhysX mock views apply TensorAPI-style full-size writes and reject compact data.
  • Entry modules: test_asset_contract_{api,data,writes}.py.
  • New cases on all three backends:
    • partial joint-state writes with int64, unsorted selectors;
    • joint_acc / previous_joint_vel bookkeeping after a partial write;
    • the deprecated write_joint_state_to_sim writes exactly what the public writers write.

PhysX now actually runs in the kitless contract. On develop, the articulation and ordering suites silently drop PhysX because carb/usdrt fail to import. The boot stubs those modules, and test_installed_backend_packages_run_the_contract fails if an installed backend drops out. Removing the carb stub turns that test red.

Every test develop added to these files keeps its assertions, now in contract/. This includes #8022 table tests, aliases, tendon contracts, deprecated friction writers, lazy dynamics buffers and external wrench frames. test_articulation_tendon_contract is split by property family, and Newton now runs the fixed-tendon rows.

Product bugs pinned as strict xfails (not fixed here)

  • OVPhysX RigidObjectCollection partial body pose/velocity writes push whole environment rows from an unrefreshed buffer, so unselected bodies get stale or zero state (4 rows).
  • Newton fixed-tendon mask setters (stiffness, damping, position limits) skip the shape check and silently truncate oversized input, where PhysX and OVPhysX raise (6 rows: three setters with torch or warp input; each row pins only that oversized-input check, and the rest of the tendon writer contract runs normally).

Timing

Warm Warp cache, repository orchestrator, one process per file, RTX 5090.

Files Outcomes Wall
develop 7 696 pass, 80 skip 21.6 s
this PR 6 1,249 pass, 84 skip, 10 xfail 22.2 s

This PR runs 79% more cases in about the same time and adds real PhysX coverage. The skips are declared Newton capability gaps (spatial tendons, extended fixed-tendon properties, tendon target scheduling, mocked task-space dynamics).

Notes

  • pyproject.toml excludes _*.py from ruff, so the _*_contract_cases.py / _*_contract_utils.py modules are not linted by pre-commit. The original *_iface helpers had the same gap.

Type of change

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 uv run isaaclab --format
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have validated the changed behavior with focused coverage and applied the test-audit criteria to any test changes
  • I have added a changelog fragment under source/<pkg>/changelog.d/ for every touched package (do not edit CHANGELOG.rst or bump package versions — CI handles that)
  • I have added my name to the CONTRIBUTORS.md or my name already exists there

RigidObjectCollection.set_coms_index passed wp.transformf data to the
PhysX tensor API, which raises a KeyError. It also marked the lazily
filled body_com_pose_b cache as fresh after a partial write, so the
unselected entries read back as zeros when the cache had not been read
before. set_inertias_index flattened the (num_instances, num_bodies, 9)
inertias with the 2D reshape, which the backend rejects.

Pass the COM poses as float32, let the next read refresh the COM cache
from the view as RigidObject does, and reshape the inertias with the 3D
helper. A new test writes both properties to a non-sorted subset of
(env, body) cells and checks the PhysX view and the data buffers.
Move the mocked cross-backend asset interface tests into a contract package
with api, data, and write entry modules. An explicit capability table gives
every backend a visible row: unavailable backends and unsupported branches
collect as skips with their reason instead of silently dropping out. A
kitless usdrt/carb stub and an availability guard keep PhysX articulations
in the matrix, where they previously were skipped without notice.

Factory manager patches are scoped to one test and restored afterwards.
PhysX views apply TensorAPI writes so partial writers are checked against
unselected backend rows, Newton joins the fixed-tendon contract, the
deprecated command aliases are checked against the actuator collection, and
one enforced inventory classifies the public base-class surface.
Take over what the removed OVPhysX real-backend joint-state test checked, on
every backend: unsorted int64 environment and joint selectors on the fused
writer, the finite-difference baseline it restarts for the written joints,
skip_forward leaving body caches to the caller, and the deprecated combined
writer producing the same state as the public writers.
@greptile-apps

greptile-apps Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

[Medium risk] Reorganizes asset contract tests into a shared module.

The PR should not merge until backend availability handles an installed Newton extension whose runtime dependencies are absent.

Findings

  1. P1 Newton import can stop collection ▶
  2. P2 Xfail masks separate validation failures ▶
  3. P2 Mock accepts invalid write layouts ▶

Summary

The PR reorganizes mocked asset tests into a shared, capability-gated contract suite and fixes PhysX collection COM and inertia write layouts.

  • It adds backend recording doubles, scoped manager patches, public-surface classification, and partial-write checks.
  • Newton availability can still fail collection before the contract's skip mechanism runs.

Reviews (1) · Last reviewed commit: "Cover partial joint-state writes and the..."

),
BackendDeclaration(
name="newton",
required_modules=("isaaclab_newton",),

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 Newton import can stop collection If isaaclab_newton is installed without the newton solver or pxr runtime, this check marks the backend available because it only checks for isaaclab_newton. The contract utilities then import Newton’s articulation module during collection, which raises before pytest can collect the other backends’ cases or show a reasoned Newton skip.

Comment on lines +1514 to +1519
request.applymarker(
pytest.mark.xfail(
raises=pytest.fail.Exception,
strict=True,
reason="Newton fixed-tendon mask setters accept data with extra environments",
)

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 Xfail masks separate validation failures This xfail covers the whole Newton mask-writer test, not just its oversized-shape checks. If the earlier position-limit scalar rejection stops working, its pytest.raises check produces the same pytest.fail.Exception and is reported as the known oversized-input bug. Narrowing the expected failure would keep that separate regression visible.

Comment on lines +59 to +62
if values_np.size == stored_np.size:
stored_np[rows] = values_np.reshape(stored_np.shape)[rows]
else:
stored_np[rows] = values_np.reshape(len(rows), *stored_np.shape[1:])

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 Mock accepts invalid write layouts The recording setter accepts compact data for selected rows, even though the stated PhysX TensorAPI contract requires full-sized data with indices selecting the rows to apply. A future writer could use the compact layout and pass these checks while sending an invalid layout to the real API.

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!

@AntoineRichard
AntoineRichard marked this pull request as draft September 29, 2026 12:54

@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 shared asset-contract restructuring and PhysX RigidObjectCollection COM/inertia fixes are coherent, with no compatibility break identified. Before merge, simplify the copied public-surface manifest and redundant reverse-order test row, replace reason-string matching with the declared CUDA requirement, and complete the new helper annotations.

  • Design and architecture: The capability declarations, per-test manager patch scope, and three focused contract entry modules improve isolation and backend visibility. However, PUBLIC_SURFACE_CONTRACTS duplicates the complete public member inventory while its DATA/WRITE classifications are not connected to coverage, creating a maintenance burden without proving contract ownership.
  • API: The production changes retain the signatures, keywords, accepted shapes, dtypes, full_data behavior, and mask delegation of RigidObjectCollection.set_coms_index and set_inertias_index. The changed conversions remain internal to the PhysX tensor-view boundary.
  • Compatibility and deprecation: Breaking changes: none identified. No public symbol, configuration key, registry ID, or CLI surface was removed or renamed; the COM and inertia paths correct previously invalid layouts while preserving their existing callable contracts.
  • Implementation: The COM path now passes a flat float32 view to PhysX and invalidates dependent caches before refreshing from the view, while the inertia path uses the required three-dimensional body-major reshape. One maintainability issue remains in test_installed_backend_packages_run_the_contract: it recognizes the CUDA-only exclusion by matching the free-form reason text instead of using BackendDeclaration.requires_cuda_runtime.
  • Style consistency: The added helpers generally follow adjacent naming and documentation patterns, but _read_backend_cells lacks the -> torch.Tensor annotation used by its sibling readers. In public_surface.py, _mapping lacks a return annotation and public_surface_mismatches should use the concrete dict[str, list[str]] return type required by the repository typing guidance.
  • Test quality: The partial-write, deprecated-writer, tendon-family, backend-storage, and live PhysX regression cases protect concrete behavior. Two test-quality issues remain: the public-surface test relies on a copied member manifest whose classifications do not demonstrate coverage, and the reverse backend iteration parameter repeats the same disjoint patch/restore paths without reaching a distinct branch.

Minor fixes needed. Posted 5 actionable findings inline.

Automated review; human maintainers own approval decisions.

return {f"{class_name}.{member}": PublicMemberContract(kind, reason) for member in members.split()}


PUBLIC_SURFACE_CONTRACTS = {

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 · Test Quality — Copied public-member inventory proves no behavior

PUBLIC_SURFACE_CONTRACTS restates every public member of seven base classes, and the only consumer diffs those names against vars(cls). The ContractKind values are never asserted on (only the OUT_OF_SCOPE reason is), so classifying a member as DATA or WRITE proves no coverage while every public API addition, rename, or move forces a mirrored edit. The test-audit guidance rejects copied inventories and manifests; drop the manifest or derive ownership from the contract cases.

}


def _read_backend_cells(backend: str, raw_backend, quantity: str, num_instances: int, num_bodies: int):

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 · Style Consistency — Annotate backend reader return type

_read_backend_cells omits its return annotation, unlike the sibling _read_backend_rows helpers added in _rigid_object_contract_cases.py and _articulation_contract_cases.py, which both declare -> torch.Tensor. Add the same annotation so the shared contract helpers stay consistent with adjacent code and the signature-typing rule.

}


def public_surface_mismatches(classes: tuple[type, ...], contracts: dict[str, PublicMemberContract]) -> dict[str, list]:

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 · Style Consistency — Imprecise and missing return annotations

The guide requires concrete built-in collection annotations and return types in signatures. public_surface_mismatches returns sorted member-name lists, so the return type is dict[str, list[str]] rather than dict[str, list], and the _mapping helper at line 53 has no return annotation despite returning dict[str, PublicMemberContract]. Annotate both concretely.

status.declaration.name: status.reason
for status in BACKEND_STATUSES
if not status.available
and status.reason != "CUDA runtime unavailable"

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 — Gate on declared flag, not reason text

This filter compares status.reason against the literal string built in capabilities._evaluate_backend. Rewording that message silently stops excluding CPU-only environments, so ovphysx re-enters unavailable and the test fails on every machine without CUDA. BackendDeclaration.requires_cuda_runtime already models the condition; check status.declaration.requires_cuda_runtime instead of matching free-form text.

return bindings


@pytest.mark.parametrize("reverse", [False, True], ids=["forward", "reverse"])

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 · Test Quality — Reverse parameter row reaches no distinct path

The reverse axis only changes backend iteration order, but each backend patches disjoint owners (PhysxManager, OvPhysxManager, the Newton data modules), so both rows record and restore exactly the same (owner, name) entries through the same code. The extra row doubles the mocked factory builds without selecting a distinct branch. Keep one ordering, or vary the asset-family creation order if cross-family interference is the intended regression.

Replace the static-method fixture helper with a module function, read
backend storage through bound getters instead of getattr on known names,
share one context for suppressing Newton model-change notifications, reuse
the timestamped-cache helpers in the joint-state case, complete return
annotations, and word comments by their current constraint.
Run the index-resolution cases on OVPhysX, which implements the joint and
body helpers, and drop the capability every backend now shares. Make the
PhysX recording setters reject compact data instead of accepting it. Move
the tendon shape negatives into their own case so the Newton mask xfail
covers exactly the torch or warp oversized input it pins.
@AntoineRichard AntoineRichard changed the title Accelerate and strengthen asset tests [1/24] Accelerate and strengthen asset tests [1/13] Sep 29, 2026

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

Can we simplify this, I think we can remove the nested contract folder and just have a flat folder structure for assets/

Also this is largely overengineered. contract boot, mock backends, manager patch scope, we're building a large library inside this test file.

Also in an effort to clean up the tests we are adding new tests for the new helpers of test files.

@@ -6,61 +6,57 @@
# ignore private usage of variables warning

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.

Here and elsewhere, let's avoid _ file names.

@StafaH

StafaH commented Oct 3, 2026

Copy link
Copy Markdown
Collaborator

Closing because the combined PR #7282 has merged. This split PR is superseded by #7282 and is no longer needed.

@StafaH StafaH closed this Oct 3, 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

None yet

Development

Successfully merging this pull request may close these issues.

2 participants