Skip to content

Fix typing issues #1109#1338

Merged
shi-eric merged 1 commit into
newton-physics:mainfrom
eric-heiden:fix-type-mismatch
Jan 13, 2026
Merged

Fix typing issues #1109#1338
shi-eric merged 1 commit into
newton-physics:mainfrom
eric-heiden:fix-type-mismatch

Conversation

@eric-heiden

@eric-heiden eric-heiden commented Jan 13, 2026

Copy link
Copy Markdown
Member

Fixes #1109.

Summary by CodeRabbit

  • Improvements
    • Enhanced physics parameter initialization with improved type handling in simulation builders to ensure better compatibility.

✏️ Tip: You can customize this high-level summary in your review settings.

Signed-off-by: Eric Heiden <eric-heiden@outlook.com>
@coderabbitai

coderabbitai Bot commented Jan 13, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This PR addresses a type mismatch error in USD import and fixed joint collapse operations by standardizing inertia representations to Warp mat33 and center-of-mass values to Warp vec3. Changes span the model builder and USD importer to ensure consistent type handling during body merging and finalization.

Changes

Cohort / File(s) Summary
Type Coercion Helper
newton/_src/sim/builder.py
Added static method _coerce_mat33() to convert various mat33-like inputs (Warp matrices, row/column arrays, NumPy arrays) into consistent Warp mat33 format.
Body Link Addition
newton/_src/sim/builder.py
Modified add_link() to coerce inertia I_m and center-of-mass com through _coerce_mat33() and wp.vec3() respectively. Changed inertia identity matrix initialization to use wp.mat33(np.eye(3, dtype=np.float32)).
Fixed Joint Collapse
newton/_src/sim/builder.py
Updated collapse_fixed_joints() to apply _coerce_mat33() on merged inertia values and convert body_com entries to wp.vec3 during body consolidation.
USD Import Data Conversion
newton/_src/utils/import_usd.py
Changed center-of-mass assignment to use wp.vec3(), inertia zero-initialization to wp.mat33(0.0), and inertia accumulation to use wp.mat33(mass * d_squared * np.eye(3, dtype=np.float32)) for consistent Warp-type construction.

Estimated Code Review Effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly Related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Fix typing issues #1109' is fully related to the main change - the PR fixes type mismatch errors in the builder module when collapsing fixed joints during USD import.
Linked Issues check ✅ Passed The PR addresses issue #1109 by ensuring consistent Warp types (vec3, mat33) throughout the collapse_fixed_joints path and USD import, eliminating type mismatches between Warp and NumPy objects during arithmetic operations.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing type consistency issues in the collapse_fixed_joints and USD import workflows; no out-of-scope modifications detected.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov

codecov Bot commented Jan 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 34.61538% with 17 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
newton/_src/sim/builder.py 34.78% 15 Missing ⚠️
newton/_src/utils/import_usd.py 33.33% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

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

Actionable comments posted: 1

📜 Review details

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f8ed713 and 7a942ed.

📒 Files selected for processing (2)
  • newton/_src/sim/builder.py
  • newton/_src/utils/import_usd.py
🧰 Additional context used
🧠 Learnings (12)
📓 Common learnings
Learnt from: nvtw
Repo: newton-physics/newton PR: 1314
File: newton/_src/sim/builder.py:6061-6091
Timestamp: 2026-01-12T10:11:39.312Z
Learning: Repo: newton-physics/newton PR: 1314
File: newton/_src/sim/builder.py (ModelBuilder.finalize)
Learning: The project prefers to keep finalize() validation lightweight; do not add union-find/connected-components validation for loop joints. Current behavior (allow non-articulated joints when the child is in any articulation) is acceptable; avoid overengineering here.
Learnt from: dylanturpin
Repo: newton-physics/newton PR: 806
File: newton/_src/sim/ik/ik_objectives.py:0-0
Timestamp: 2025-09-25T16:14:22.033Z
Learning: wp.transform in NVIDIA Warp supports indexing using numerical indices (e.g., body_tf[0], body_tf[3], etc.) to access translation and rotation components. The indexing approach used in the Newton codebase is valid and compiles correctly.
📚 Learning: 2025-09-22T21:08:31.901Z
Learnt from: dylanturpin
Repo: newton-physics/newton PR: 806
File: newton/examples/ik/example_ik_franka.py:121-123
Timestamp: 2025-09-22T21:08:31.901Z
Learning: In the newton physics framework, when creating warp arrays for IK solver joint variables using wp.array(self.model.joint_q, shape=(1, coord_count)), the resulting array acts as a reference/pointer to the original model's joint coordinates, so updates from the IK solver automatically reflect in the model's joint_q buffer used for rendering, despite the general warp documentation suggesting copies are made by default.

Applied to files:

  • newton/_src/sim/builder.py
  • newton/_src/utils/import_usd.py
📚 Learning: 2025-08-12T05:17:34.423Z
Learnt from: shi-eric
Repo: newton-physics/newton PR: 521
File: newton/examples/example_cloth_hanging.py:36-36
Timestamp: 2025-08-12T05:17:34.423Z
Learning: The Newton migration guide (docs/migration.rst) is specifically for documenting how to migrate existing warp.sim functionality to Newton equivalents. New Newton-only features that didn't exist in warp.sim do not need migration documentation.

Applied to files:

  • newton/_src/sim/builder.py
  • newton/_src/utils/import_usd.py
📚 Learning: 2025-08-12T18:04:06.577Z
Learnt from: nvlukasz
Repo: newton-physics/newton PR: 519
File: newton/_src/solvers/featherstone/kernels.py:75-75
Timestamp: 2025-08-12T18:04:06.577Z
Learning: The Newton physics framework requires nightly Warp builds, which means compatibility concerns with older stable Warp versions (like missing functions such as wp.spatial_adjoint) are not relevant for this project.

Applied to files:

  • newton/_src/sim/builder.py
  • newton/_src/utils/import_usd.py
📚 Learning: 2025-09-22T21:08:31.901Z
Learnt from: dylanturpin
Repo: newton-physics/newton PR: 806
File: newton/examples/ik/example_ik_franka.py:121-123
Timestamp: 2025-09-22T21:08:31.901Z
Learning: In the newton physics framework, when creating warp arrays for IK solver joint variables using wp.array(self.model.joint_q, shape=(1, coord_count)), the resulting array acts as a reference/pointer to the original model's joint coordinates, so updates from the IK solver automatically reflect in the model's joint_q buffer used for rendering.

Applied to files:

  • newton/_src/sim/builder.py
📚 Learning: 2026-01-12T10:11:39.312Z
Learnt from: nvtw
Repo: newton-physics/newton PR: 1314
File: newton/_src/sim/builder.py:6061-6091
Timestamp: 2026-01-12T10:11:39.312Z
Learning: In finalize() validation logic (e.g., newton/_src/sim/builder.py and similar files), keep the validation lightweight. Do not add union-find/connected-components validation for loop joints. The current behavior—allowing non-articulated joints when the child is in any articulation—is acceptable. Avoid overengineering here.

Applied to files:

  • newton/_src/sim/builder.py
📚 Learning: 2025-12-13T17:26:39.791Z
Learnt from: lenroe-nv
Repo: newton-physics/newton PR: 1248
File: newton/_src/geometry/contact_data.py:47-49
Timestamp: 2025-12-13T17:26:39.791Z
Learning: In ContactData (newton/_src/geometry/contact_data.py), the fields contact_stiffness, contact_damping, and contact_friction_scale use 0.0 as the "unset" sentinel value. This is intentional: Warp struct fields initialize to 0.0 by default, and solver-side code interprets 0.0 as "use default/unscaled" rather than "disable." This design avoids explicit initialization in contact generation kernels.

Applied to files:

  • newton/_src/utils/import_usd.py
📚 Learning: 2025-09-25T16:14:22.033Z
Learnt from: dylanturpin
Repo: newton-physics/newton PR: 806
File: newton/_src/sim/ik/ik_objectives.py:0-0
Timestamp: 2025-09-25T16:14:22.033Z
Learning: wp.transform in NVIDIA Warp supports indexing using numerical indices (e.g., body_tf[0], body_tf[3], etc.) to access translation and rotation components. The indexing approach used in the Newton codebase is valid and compiles correctly.

Applied to files:

  • newton/_src/utils/import_usd.py
📚 Learning: 2025-08-18T15:56:26.587Z
Learnt from: adenzler-nvidia
Repo: newton-physics/newton PR: 552
File: newton/_src/solvers/mujoco/solver_mujoco.py:0-0
Timestamp: 2025-08-18T15:56:26.587Z
Learning: In Newton's MuJoCo solver, when transforming joint axes from Newton's internal frame to MuJoCo's expected frame, use wp.quat_rotate(joint_rot, axis) not wp.quat_rotate_inv(joint_rot, axis). The joint_rot represents rotation from joint-local to body frame, so forward rotation is correct.

Applied to files:

  • newton/_src/utils/import_usd.py
📚 Learning: 2025-09-26T05:58:21.013Z
Learnt from: WenchaoHuang
Repo: newton-physics/newton PR: 835
File: newton/_src/solvers/style3d/collision/collision.py:49-53
Timestamp: 2025-09-26T05:58:21.013Z
Learning: In newton/_src/solvers/style3d/collision/collision.py, the broad_phase buffers (broad_phase_ee, broad_phase_ef, broad_phase_vf) created with wp.array() don't need zero-initialization because they follow a write-first-read-later pattern: BVH query kernels in frame_begin() populate these buffers completely (write-only operations), and collision kernels only read from them afterward in accumulate_contact_force(), ensuring no undefined reads occur.

Applied to files:

  • newton/_src/utils/import_usd.py
📚 Learning: 2025-12-01T17:00:28.889Z
Learnt from: camevor
Repo: newton-physics/newton PR: 1161
File: newton/_src/solvers/mujoco/kernels.py:1268-1268
Timestamp: 2025-12-01T17:00:28.889Z
Learning: MuJoCo Warp spatial vectors (e.g., cacc, cvel) use the convention (angular, linear), which is opposite to Newton's (linear, angular) convention. When converting from MuJoCo Warp to Newton format, spatial_top() on MuJoCo Warp data extracts the angular component, and spatial_bottom() extracts the linear component.

Applied to files:

  • newton/_src/utils/import_usd.py
📚 Learning: 2025-11-28T11:12:40.805Z
Learnt from: camevor
Repo: newton-physics/newton PR: 1146
File: newton/examples/basic/example_basic_joints.py:206-213
Timestamp: 2025-11-28T11:12:40.805Z
Learning: In Newton's standard solvers (XPBD, SemiImplicit, SolverMuJoCo), spatial vectors in State.body_qd use the ordering (linear, angular): wp.spatial_top(qd) returns linear velocity and wp.spatial_bottom(qd) returns angular velocity. This is the opposite of typical Modern Robotics spatial twist notation where (angular, linear) is used.

Applied to files:

  • newton/_src/utils/import_usd.py
⏰ Context from checks skipped due to timeout of 900000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Run GPU Tests / Run GPU Unit Tests on AWS EC2
  • GitHub Check: Run GPU Benchmarks / Run GPU Benchmarks on AWS EC2
  • GitHub Check: run-newton-tests / newton-unittests (ubuntu-latest)
  • GitHub Check: run-newton-tests / newton-unittests (windows-latest)
🔇 Additional comments (5)
newton/_src/utils/import_usd.py (3)

1562-1564: LGTM - COM correctly converted to Warp vec3.

This change ensures the center-of-mass is stored as a Warp vec3 type, preventing type mismatches during subsequent operations like collapse_fixed_joints that perform arithmetic on body properties.


1571-1574: LGTM - Zero inverse inertia correctly typed as Warp mat33.

Using wp.mat33(0.0) ensures type consistency with other Warp-typed inertia matrices, preventing type mismatches during body merging operations.


1588-1598: Verify numpy operation compatibility with wp.vec3 in the parallel axis theorem calculation.

The compute_sphere_inertia function explicitly returns a wp.mat33 as the third tuple element, so the += operation on line 1595 between two wp.mat33 objects is type-safe. However, lines 1592–1594 apply numpy operations (np.linalg.norm, np.sum, **2) directly to com, which is a wp.vec3. While Warp's types support array-like interfaces, test patterns elsewhere in the codebase show explicit conversion via np.array() before using numpy functions. This code path (parallel axis theorem with a non-zero center of mass offset) lacks test coverage and should be verified to ensure compatibility with Warp's vec3 type under the nightly Warp builds used by this project.

newton/_src/sim/builder.py (2)

3309-3323: Good: coercing inertia + COM to Warp types in collapse_fixed_joints() addresses the reported merge-time TypeError.
This should prevent mixed-type arithmetic (e.g., wp.vec3/wp.mat33 vs np.ndarray) during DFS body merges.


2204-2219: The pattern wp.mat33(np.eye(3, dtype=np.float32)) is used successfully throughout the Newton codebase (60+ test files and utility functions), with no evidence of runtime failures or unintended behavior. This contradicts the review claim that it is "very likely to either throw or produce unintended constructor behavior." The current implementation is correct and consistent with established Newton patterns.

Comment thread newton/_src/sim/builder.py

Copilot AI 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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@eric-heiden eric-heiden added this pull request to the merge queue Jan 13, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jan 13, 2026
@shi-eric shi-eric added this pull request to the merge queue Jan 13, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jan 13, 2026
@shi-eric shi-eric added this pull request to the merge queue Jan 13, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jan 13, 2026
@shi-eric shi-eric added this pull request to the merge queue Jan 13, 2026
Merged via the queue into newton-physics:main with commit dc77145 Jan 13, 2026
23 of 24 checks passed
eric-heiden added a commit to eric-heiden/newton that referenced this pull request Jan 28, 2026
Signed-off-by: Eric Heiden <eric-heiden@outlook.com>
mmacklin pushed a commit to mmacklin/newton that referenced this pull request Apr 7, 2026
Signed-off-by: Eric Heiden <eric-heiden@outlook.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Type Mismatch Error When Adding Data During parse_usd and collapse_fixed_joints Operations via DFS

3 participants