Remove import functions from newton.utils#646
Conversation
Signed-off-by: Eric Heiden <eric-heiden@outlook.com>
📝 WalkthroughWalkthroughMultiple public API and implementation moves: removed deprecated parser exports from Changes
Sequence Diagram(s)mermaid mermaid Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. ✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
Status, Documentation and Community
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (3)
newton/utils.py (3)
112-119: API removal looks good; consider a gentle compat shim for clearer errors.Removing
parse_{usd,urdf,mjcf}fromnewton.utilsaligns with the PR objective. To reduce friction for downstream users importing these names, consider adding a module-level__getattr__shim that raises a targeted error with migration guidance. This preserves the removal while yielding a crisp, actionable message on import.Example addition (place near the end of the module):
# Compat shim for removed importer helpers (intentional: names are gone from __all__) def __getattr__(name: str): removed = { "parse_usd": "ModelBuilder.add_usd(...)", "parse_urdf": "ModelBuilder.add_urdf(...)", "parse_mjcf": "ModelBuilder.add_mjcf(...)", } if name in removed: # Keep AttributeError so 'from newton.utils import parse_usd' fails, # but with a helpful, migration-oriented message. raise AttributeError( f"newton.utils.{name} was removed. Use {removed[name]} instead. " "See docs/migration.rst for examples." ) raise AttributeError(name)
112-119: Update migration guide with before/after snippets.Per the PR description, ensure
docs/migration.rstincludes concise examples mapping the old helpers toModelBuilder.add_*. Keep it minimal and copy-pasteable.Proposed outline:
- Old:
from newton.utils import parse_usd→ New:ModelBuilder.add_usd(path, ...)- Old:
parse_urdf(path, ...)→ New:ModelBuilder.add_urdf(path, ...)- Old:
parse_mjcf(path, ...)→ New:ModelBuilder.add_mjcf(path, ...)- Note about the removal date and a one-line rationale.
24-48: Optional: freeze all at the end to avoid accidental mutation.Small hygiene improvement: convert
__all__to a tuple at the end of the module. This prevents accidental in-place mutations elsewhere.Apply at EOF:
__all__ = tuple(__all__)Also applies to: 67-110, 117-129
📜 Review details
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
newton/utils.py(1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: nvlukasz
PR: newton-physics/newton#519
File: newton/utils.py:30-33
Timestamp: 2025-08-12T18:07:17.267Z
Learning: In newton/_src/utils/import_usd.py, the PXR/USD modules are lazily loaded using try-except blocks within the functions rather than at module import time, making it safe to import parse_usd at the module level without causing import-time failures for users without USD dependencies.
Learnt from: nvlukasz
PR: newton-physics/newton#519
File: newton/utils.py:30-33
Timestamp: 2025-08-12T18:07:17.267Z
Learning: In newton/_src/utils/import_usd.py, the PXR/USD modules are lazily loaded using try-except blocks within the functions rather than at module import time, making it safe to import parse_usd at the module level without causing import-time failures for users without USD dependencies.
Learnt from: nvlukasz
PR: newton-physics/newton#519
File: newton/utils.py:30-33
Timestamp: 2025-08-12T18:07:17.267Z
Learning: In newton/_src/utils/import_usd.py, the PXR/USD modules are lazily loaded using try-except blocks within the functions (lines 109-111 and 1289-1291) rather than at module import time, making it safe to import parse_usd at the module level without causing import-time failures for users without USD dependencies.
⏰ 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 Benchmarks (Pull Request)
- GitHub Check: Run GPU Unit Tests on AWS EC2 (Pull Request)
- GitHub Check: run-newton-tests / newton-unittests (windows-latest)
- GitHub Check: run-newton-tests / newton-unittests (ubuntu-latest)
🔇 Additional comments (1)
newton/utils.py (1)
112-119: No lingeringparse_*references detected across the repository
A full repo-wide search (includingnewton/,docs/, and all top-level files) for calls and imports ofnewton.utils.parse_usd,parse_urdf, andparse_mjcfreturned zero matches. All deprecated helpers have been cleanly removed—no further action needed.
Signed-off-by: Eric Heiden <eric-heiden@outlook.com>
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
newton/_src/geometry/inertia.py (1)
42-43: Docstrings return tuple are inaccurate (missing center of mass entry)These helpers return (mass, com, inertia) but the text says (mass, inertia).
Update returns sections:
- A tuple of (mass, inertia) with inertia specified around the origin + A tuple of (mass, center of mass, inertia) with inertia specified around the origin(Apply to sphere, capsule, cylinder, and box helpers.)
Also applies to: 65-66, 94-95, 171-172
🧹 Nitpick comments (6)
newton/_src/core/spatial.py (1)
243-245: Unify skew-matrix notation ([p]× vs [p]_x).Use the same [p]_{×} symbol in the prose as in the equation to avoid confusion.
- where *R* and *p* are the rotation and translation components of ``t`` and - ``[p]_x`` is the skew-symmetric matrix of *p*. + where *R* and *p* are the rotation and translation components of ``t`` and + ``[p]_{\\times}`` is the skew-symmetric matrix of *p*.newton/utils.py (1)
111-118: Optional: add a helpful deprecation shim for removed symbols.Provide a targeted AttributeError with migration guidance to reduce user friction.
+def __getattr__(name: str): + mapping = { + "parse_usd": "ModelBuilder.add_usd(...)", + "parse_urdf": "ModelBuilder.add_urdf(...)", + "parse_mjcf": "ModelBuilder.add_mjcf(...)", + "transform_inertia": "newton.geometry.transform_inertia(...)", + } + if name in mapping: + raise AttributeError( + f"newton.utils.{name} was removed. Use {mapping[name]} instead. " + "See docs/migration.rst for details." + ) + raise AttributeError(f"module 'newton.utils' has no attribute '{name}'")newton/_src/solvers/featherstone/kernels.py (1)
61-96: Semantics are correct; simplify matrix construction.Compute R directly from the quaternion to reduce ops and match style used in geometry/inertia.
- q = wp.transform_get_rotation(t_inv) - p = wp.transform_get_translation(t_inv) - - r1 = wp.quat_rotate(q, wp.vec3(1.0, 0.0, 0.0)) - r2 = wp.quat_rotate(q, wp.vec3(0.0, 1.0, 0.0)) - r3 = wp.quat_rotate(q, wp.vec3(0.0, 0.0, 1.0)) - - R = wp.matrix_from_cols(r1, r2, r3) + q = wp.transform_get_rotation(t_inv) + p = wp.transform_get_translation(t_inv) + R = wp.quat_to_matrix(q) S = wp.skew(p) @ R T = wp.spatial_adjoint(R, S) return wp.mul(wp.mul(wp.transpose(T), I), T)docs/api/newton_geometry.rst (1)
22-25: Docs entry additions look good; consider adding a versionchange note.Add a short directive to signal the move from newton.utils to newton.geometry for transform_inertia.
Example (adjust version as appropriate):
.. versionchanged:: 0.x ``transform_inertia`` moved from ``newton.utils`` to ``newton.geometry``.newton/_src/geometry/inertia.py (2)
421-423: Prefer wp.matmul to ensure device-side matmul portabilitySome Warp builds don’t support the Python “@” operator in device code. Using wp.matmul avoids ambiguity.
Apply:
- return R @ I @ wp.transpose(R) + m * ( + return wp.matmul(wp.matmul(R, I), wp.transpose(R)) + m * ( wp.dot(p, p) * wp.mat33(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0) - wp.outer(p, p) )
387-416: Add minimal unit tests for transform_inertiaCover identity rotation/shift, pure shift, and a simple rotation case to lock behavior.
I can draft tests exercising:
- q = identity, p = 0 → I’ == I
- q = identity, p = (a,0,0) → I’ adds m a^2 to yy/zz, zero to xx
- q = 90° about z → I’ == R I R^T
Want me to open a small test PR?
📜 Review details
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
⛔ Files ignored due to path filters (3)
docs/api/_generated/newton.geometry.compute_shape_inertia.rstis excluded by!**/_generated/**docs/api/_generated/newton.geometry.transform_inertia.rstis excluded by!**/_generated/**docs/api/_generated/newton.utils.transform_inertia.rstis excluded by!**/_generated/**
📒 Files selected for processing (8)
docs/api/newton_geometry.rst(1 hunks)docs/api/newton_utils.rst(0 hunks)newton/_src/core/spatial.py(3 hunks)newton/_src/geometry/inertia.py(1 hunks)newton/_src/solvers/featherstone/kernels.py(2 hunks)newton/_src/utils/__init__.py(0 hunks)newton/geometry.py(1 hunks)newton/utils.py(1 hunks)
💤 Files with no reviewable changes (2)
- docs/api/newton_utils.rst
- newton/_src/utils/init.py
🧰 Additional context used
🧠 Learnings (6)
📓 Common learnings
Learnt from: nvlukasz
PR: newton-physics/newton#519
File: newton/geometry.py:16-22
Timestamp: 2025-08-12T17:51:37.474Z
Learning: In the Newton public API refactor, common geometry symbols like ParticleFlags and ShapeFlags are now exposed at the top level in newton/__init__.py rather than through newton.geometry. The newton/geometry.py module is intentionally focused only on broad-phase collision detection classes (BroadPhaseAllPairs, BroadPhaseExplicit, BroadPhaseSAP).
Learnt from: shi-eric
PR: newton-physics/newton#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.
📚 Learning: 2025-08-12T17:51:37.474Z
Learnt from: nvlukasz
PR: newton-physics/newton#519
File: newton/geometry.py:16-22
Timestamp: 2025-08-12T17:51:37.474Z
Learning: In the Newton public API refactor, common geometry symbols like ParticleFlags and ShapeFlags are now exposed at the top level in newton/__init__.py rather than through newton.geometry. The newton/geometry.py module is intentionally focused only on broad-phase collision detection classes (BroadPhaseAllPairs, BroadPhaseExplicit, BroadPhaseSAP).
Applied to files:
docs/api/newton_geometry.rstnewton/geometry.py
📚 Learning: 2025-08-12T17:58:00.815Z
Learnt from: nvlukasz
PR: newton-physics/newton#519
File: newton/_src/solvers/featherstone/kernels.py:18-20
Timestamp: 2025-08-12T17:58:00.815Z
Learning: In newton/_src/core/__init__.py, the function transform_twist is properly re-exported from the spatial module via "from .spatial import (..., transform_twist, ...)" and included in __all__, making it available for import as "from ...core import transform_twist" from other modules.
Applied to files:
newton/geometry.pynewton/_src/core/spatial.pynewton/_src/solvers/featherstone/kernels.py
📚 Learning: 2025-08-12T17:58:00.815Z
Learnt from: nvlukasz
PR: newton-physics/newton#519
File: newton/_src/solvers/featherstone/kernels.py:18-20
Timestamp: 2025-08-12T17:58:00.815Z
Learning: In newton/_src/core/__init__.py, the function transform_twist is re-exported from the spatial module via "from .spatial import transform_twist", making it available for import as "from ...core import transform_twist" from other modules.
Applied to files:
newton/geometry.pynewton/_src/core/spatial.pynewton/_src/solvers/featherstone/kernels.py
📚 Learning: 2025-08-14T17:38:36.106Z
Learnt from: nvlukasz
PR: newton-physics/newton#519
File: newton/__init__.py:25-29
Timestamp: 2025-08-14T17:38:36.106Z
Learning: The Newton project prefers incremental __all__ building using __all__ += [...] pattern to group exports with their related imports, rather than a single consolidated __all__ at the end of the file.
Applied to files:
newton/geometry.py
📚 Learning: 2025-08-12T05:17:34.423Z
Learnt from: shi-eric
PR: newton-physics/newton#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/geometry/inertia.py
🧬 Code graph analysis (1)
newton/geometry.py (1)
newton/_src/geometry/inertia.py (2)
compute_shape_inertia(426-522)transform_inertia(388-423)
⏰ 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 Benchmarks (Pull Request)
- GitHub Check: Run GPU Unit Tests on AWS EC2 (Pull Request)
- GitHub Check: run-newton-tests / newton-unittests (ubuntu-latest)
- GitHub Check: run-newton-tests / newton-unittests (windows-latest)
🔇 Additional comments (6)
newton/_src/core/spatial.py (1)
241-242: Docstring LaTeX escaping and content look correct.The twist/wrench transformation formulas and “source → destination” semantics are consistent with the implementation.
Also applies to: 269-281
newton/utils.py (1)
111-118: No action needed for parser helpers removalI confirmed that
parse_{usd,urdf,mjcf}andtransform_inertiaare no longer exported fromnewton.utils, and there are no remaining references in the code, docs, or examples pointing tonewton.utils.parse_*ornewton.utils.transform_inertia. The migration guide already maps the old Warp sim importers to the newModelBuildermethods, and the inertia transform helper now lives undernewton.geometry. You can safely ignore the original suggestion to update the migration guide for these helpers.Likely an incorrect or invalid review comment.
newton/_src/solvers/featherstone/kernels.py (1)
716-717: Rename complete; no lingering references tospatial_transform_inertiaRan
rg -nP '\bspatial_transform_inertia\b' -g '!*site*'across the codebase and verified there are no remaining matches.
newton/geometry.py (1)
17-27: Re-exports for inertia utilities look good.Public surface matches the docs and the intended migration path.
newton/_src/geometry/inertia.py (2)
387-416: Solid refactor: math, typing, and docs of transform_inertia look correctThe rotation + parallel-axis formula and typed @wp.func signature are correct and consistent with the docstring. Nice move out of utils.
387-388: Add migration entry for transform_inertia in docs/migration.rstNo stale imports of
newton.utils.transform_inertiaremain in the codebase, and the API docs already reference the function under its new path. However, the migration guide (docs/migration.rst) doesn’t yet document this breaking change. Please insert a row in the “Renamed functions” table (around line 34) to point users from the old to the new location:docs/migration.rst … |:func:`warp.sim.parse_urdf` |:meth:`newton.ModelBuilder.add_urdf` | |:func:`warp.sim.parse_mjcf` |:meth:`newton.ModelBuilder.add_mjcf` | |:func:`warp.sim.parse_usd` |:meth:`newton.ModelBuilder.add_usd` | +|:func:`newton.utils.transform_inertia` |:func:`newton.geometry.transform_inertia`| …⛔ Skipped due to learnings
Learnt from: shi-eric PR: newton-physics/newton#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.
|
The |
This is already updated to point users to those |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Signed-off-by: Eric Heiden <eric-heiden@outlook.com>
Signed-off-by: Eric Heiden <eric-heiden@outlook.com>
Signed-off-by: Eric Heiden <eric-heiden@outlook.com>
Description
Users should use
ModelBuilder.add_usd()rather thannewton.utils.parse_usd()(same for URDF, MJCF importing).Clean up API, expose the more useful
transform_inertiafunction.Newton Migration Guide
Please ensure the migration guide for warp.sim users is up-to-date with the changes made in this PR.
docs/migration.rstis up-to dateBefore your PR is "Ready for review"
newton/tests/test_examples.py)pre-commit run -aSummary by CodeRabbit
Breaking Changes
New Features
Refactor
Documentation