Respect USD schema default applicability - #3556
Conversation
📝 WalkthroughWalkthroughUSD schema resolution now gates mapping defaults by schema applicability and preserves resolution provenance. Import paths use this metadata for joint-limit, SDF, and hydroelastic defaults, with updated resolver mappings, documentation, changelog, and tests. ChangesUSD resolution and importer integration
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant USDPrim
participant SchemaResolverManager
participant import_usd
USDPrim->>SchemaResolverManager: resolve attribute
SchemaResolverManager-->>import_usd: value, resolver, and source
import_usd->>import_usd: apply importer fallback semantics
Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
newton/_src/usd/schemas.py (1)
312-322: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winStale comment: "-inf is the unset sentinel" no longer describes several of the fields below it.
The unchanged comment block above this mapping ("
-infis the 'unset' sentinel (same convention as gap / shell_thickness above)") now only applies tosdf_narrow_band_inner/outer,sdf_target_voxel_size, andsdf_padding.sdf_max_resolution(64),sdf_texture_format("uint16"),hydroelastic_enabled(False), andkh(1.0e10) were changed to concrete defaults that are now gated by_is_applicableinstead of using the-infsentinel convention. A reader relying on the comment could wrongly assume all these fields still use-infas "unset".📝 Suggested comment update
- # SDF configuration — from NewtonSDFCollisionAPI. `-inf` is the - # "unset" sentinel (same convention as gap / shell_thickness above). + # SDF configuration — from NewtonSDFCollisionAPI. `-inf` is the + # "unset" sentinel for the narrow-band/voxel-size/padding fields below + # (same convention as gap / shell_thickness above); sdf_max_resolution, + # sdf_texture_format, hydroelastic_enabled, and kh use concrete defaults + # gated by API applicability instead. "sdf_max_resolution": SchemaAttribute("newton:sdfMaxResolution", 64),🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@newton/_src/usd/schemas.py` around lines 312 - 322, Update the comment above the SDF configuration mapping to state that the “-inf” unset sentinel applies only to sdf_narrow_band_inner, sdf_narrow_band_outer, sdf_target_voxel_size, and sdf_padding. Do not imply that sdf_max_resolution, sdf_texture_format, hydroelastic_enabled, or kh use the sentinel, since they have concrete defaults.newton/_src/usd/schema_resolver.py (1)
133-155: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick winConsider caching per-prim applied-schema lookups.
_is_applicablecallsprim.GetAppliedSchemas()and, for every candidate api name,usd.has_applied_api_schema(prim, name)(which itself re-reads the rawapiSchemasmetadata). This is invoked fromresolve()'s schema-default loop for every configured resolver × key that reaches that stage (e.g. a shape can have a dozen+ SDF/margin/gap/mass keys), with no caching across calls for the same prim. On large scenes this repeats USD metadata parsing many times per prim.Also, since
SchemaResolverManager.resolve()now callsresolver._is_applicable(...)externally, consider dropping the leading underscore (e.g.is_applicable) to reflect that it's part of the cross-class contract rather than a resolver-private helper.♻️ Sketch: cache applied-schema set per prim within a resolve session
+ def _cached_applied_schemas(self, prim: Usd.Prim) -> set[str]: + cache = getattr(self, "_applied_schema_cache", None) + if cache is None: + cache = self._applied_schema_cache = {} + path = str(prim.GetPath()) + if path not in cache: + cache[path] = {str(name).split(":", 1)[0] for name in prim.GetAppliedSchemas()} + return cache[path]🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@newton/_src/usd/schema_resolver.py` around lines 133 - 155, Update _is_applicable to is_applicable and adjust SchemaResolverManager.resolve() and all other call sites to use the public cross-class contract. Cache each prim’s applied-schema information once per resolve session, including the data needed by usd.has_applied_api_schema, and reuse it across resolver/key checks while preserving existing applicability and exception behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@newton/_src/usd/schema_resolver.py`:
- Around line 133-155: Update _is_applicable to is_applicable and adjust
SchemaResolverManager.resolve() and all other call sites to use the public
cross-class contract. Cache each prim’s applied-schema information once per
resolve session, including the data needed by usd.has_applied_api_schema, and
reuse it across resolver/key checks while preserving existing applicability and
exception behavior.
In `@newton/_src/usd/schemas.py`:
- Around line 312-322: Update the comment above the SDF configuration mapping to
state that the “-inf” unset sentinel applies only to sdf_narrow_band_inner,
sdf_narrow_band_outer, sdf_target_voxel_size, and sdf_padding. Do not imply that
sdf_max_resolution, sdf_texture_format, hydroelastic_enabled, or kh use the
sentinel, since they have concrete defaults.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: 2cfd199f-884a-4548-b21a-30545eb49018
📒 Files selected for processing (6)
CHANGELOG.mddocs/concepts/usd_parsing.rstnewton/_src/usd/schema_resolver.pynewton/_src/usd/schemas.pynewton/_src/utils/import_usd.pynewton/tests/test_schema_resolver.py
|
@coderabbitai Addressed both valid nits in d26c1c2: applied-schema/type data is cached per manager with metadata-signature invalidation, and the SDF sentinel comment now distinguishes sentinel-backed fields from concrete defaults. I kept |
|
Tip For best results, initiate chat on the files or code changes.
If you found this review helpful, would you consider giving us a shout-out on X? Thank you for using CodeRabbit! |
Track resolver provenance and apply mapping defaults only when their USD schema applies to the prim. Route MuJoCo limit, SDF, and hydroelastic default decisions through the shared resolution contract.
Cache applied-schema and typed-prim metadata across resolver keys while invalidating on authored schema changes. Clarify which SDF fields use sentinel versus concrete defaults.
d26c1c2 to
d68f27e
Compare
|
closing this in favor of #3572. Please excuse the late notice, but I have been working on the same thing for an internal project for a while, and my PR is is part of a series trying to get the pxr- dependency out of the schemaResolvers. |
Description
Give USD resolution a single result carrying the value, winning resolver, and source: authored, importer default, applicable schema default, or unresolved.
Built-in resolvers now declare applicability per prim type and, where necessary, per key. Mapping defaults therefore cannot leak from a configured solver schema onto unrelated prims. MuJoCo joint-limit semantics plus Newton SDF and hydroelastic defaults use the shared provenance-aware path.
Third-party resolver subclasses that do not declare applicability keep their legacy always-applicable behavior.
Closes #3307.
Checklist
CHANGELOG.mdhas been updated (if user-facing change)Test plan
The resolver suite passes 34 tests. The SDF suite passes 10 CPU-capable tests and skips 14 CUDA-only tests on this machine.
Bug fix
Steps to reproduce:
Minimal reproduction:
Summary by CodeRabbit
Bug Fixes
enabled/khdefaults).Documentation
Tests