Skip to content

Conversation

@jvonmuralt
Copy link
Member

@jvonmuralt jvonmuralt commented Nov 27, 2025

Description

Newton Migration Guide

Please ensure the migration guide for warp.sim users is up-to-date with the changes made in this PR.

  • The migration guide in docs/migration.rst is up-to date

Before your PR is "Ready for review"

  • Necessary tests have been added and new examples are tested (see newton/tests/test_examples.py)
  • Documentation is up-to-date
  • Code passes formatting and linting checks with pre-commit run -a

Summary by CodeRabbit

  • New Features

    • Added an optional verbose flag to model finalization to enable conditional diagnostic output.
  • Improvements

    • Diagnostic warnings (inertia corrections, early termination, deprecation notices) are now gated by verbosity to reduce noisy logs; runtime behavior unchanged otherwise.
    • Style3D finalization now propagates the verbose option consistently.
  • Tests / Examples

    • Tests updated to exercise verbose finalization; examples and test setup mute or restore logging by default.

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

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 27, 2025

📝 Walkthrough

Walkthrough

Added an optional verbose parameter to ModelBuilder and Style3D builder finalize methods, gated several runtime warnings behind the verbosity flag, set Warp quiet mode in examples/tests, and updated tests to pass verbose where needed.

Changes

Cohort / File(s) Summary
ModelBuilder.finalize signature
newton/_src/sim/builder.py
Added `verbose: bool
Style3D builder finalize passthrough
newton/_src/sim/style3d/builder_style3d.py
Style3DModelBuilder.finalize signature extended with `verbose: bool
Warning gating behind verbose
newton/_src/sim/graph_coloring.py, newton/_src/solvers/vbd/solver_vbd.py
Early-termination and tiled-solve deprecation warnings now check verbosity (wp.config.verbose) before emitting; core algorithmic behavior unchanged.
Quiet-mode configuration
newton/examples/__init__.py, newton/tests/thirdparty/unittest_parallel.py
Added _quiet_warp_context() context manager and set wp.config.quiet = True in test harness to suppress Warp logs during example execution and test initialization.
Tests updated to use verbose
newton/tests/test_inertia_validation.py
Tests updated to call ModelBuilder.finalize(..., verbose=True) so expected warnings are produced during the test runs.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Review focus:
    • newton/_src/sim/builder.py — verify verbose defaulting to wp.config.verbose and correct gating of inertia warnings
    • newton/_src/sim/style3d/builder_style3d.py — confirm verbose is forwarded and docstring matches signature
    • newton/_src/sim/graph_coloring.py and newton/_src/solvers/vbd/solver_vbd.py — ensure only warning emission is gated and functional behavior unchanged
    • newton/examples/__init__.py, newton/tests/thirdparty/unittest_parallel.py — ensure quiet-mode handling doesn't suppress needed CI/test output

Suggested reviewers

  • mmacklin
  • adenzler-nvidia

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Cleanup warnings' accurately captures the main purpose of the changeset, which systematizes warning output through a verbose parameter across multiple files.
Docstring Coverage ✅ Passed Docstring coverage is 84.62% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent 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 306ecbd and fea1bc8.

📒 Files selected for processing (1)
  • newton/examples/__init__.py (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • newton/examples/init.py

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
Copy link

codecov bot commented Nov 27, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
newton/_src/sim/builder.py (1)

5907-5929: Add documentation for the new verbose parameter.

The verbose parameter is added to the method signature but is not documented in the docstring's Args section.

         Args:
             device: The simulation device to use (e.g., 'cpu', 'cuda'). If None, uses the current Warp device.
             requires_grad: If True, enables gradient computation for the model (for differentiable simulation).
+            verbose: If True, emit warnings for inertia corrections and other diagnostic messages.
+                Defaults to `wp.config.verbose`.
 
         Returns:
             Model: A fully constructed Model object containing all simulation data on the specified device.
📜 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 8924f29 and faeb80b.

📒 Files selected for processing (6)
  • newton/_src/sim/builder.py (2 hunks)
  • newton/_src/sim/graph_coloring.py (1 hunks)
  • newton/_src/solvers/vbd/solver_vbd.py (1 hunks)
  • newton/examples/__init__.py (1 hunks)
  • newton/tests/test_inertia_validation.py (2 hunks)
  • newton/tests/thirdparty/unittest_parallel.py (2 hunks)
🧰 Additional context used
🧠 Learnings (3)
📚 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/examples/__init__.py
📚 Learning: 2025-08-12T17:51:37.474Z
Learnt from: nvlukasz
Repo: newton-physics/newton PR: 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:

  • newton/examples/__init__.py
📚 Learning: 2025-07-23T14:36:42.182Z
Learnt from: shi-eric
Repo: newton-physics/newton PR: 461
File: asv/benchmarks/envs/example_humanoid.py:40-41
Timestamp: 2025-07-23T14:36:42.182Z
Learning: In Warp benchmarks, explicit wp.init() calls are not needed in most circumstances since the first Warp API call that requires initialization will automatically call wp.init(). Explicit wp.init() in setup() methods is helpful when the ASV benchmark is measuring a Warp API call, as wp.init() has non-trivial overhead that should be excluded from the benchmark timing.

Applied to files:

  • newton/tests/thirdparty/unittest_parallel.py
🧬 Code graph analysis (2)
newton/tests/test_inertia_validation.py (1)
newton/_src/sim/builder.py (1)
  • finalize (4907-5299)
newton/_src/solvers/vbd/solver_vbd.py (1)
newton/_src/solvers/solver.py (1)
  • device (169-176)
⏰ 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). (2)
  • GitHub Check: Run GPU Tests / Run GPU Unit Tests on AWS EC2
  • GitHub Check: Run GPU Benchmarks / Run GPU Benchmarks on AWS EC2
🔇 Additional comments (8)
newton/tests/thirdparty/unittest_parallel.py (2)

177-178: LGTM!

Setting wp.config.quiet = True here appropriately suppresses Warp logs in the main test runner process.


577-578: LGTM!

Setting wp.config.quiet = True in each test worker process ensures consistent log suppression across parallel test execution.

newton/examples/__init__.py (1)

25-26: LGTM!

Setting wp.config.quiet = True at the module level appropriately suppresses Warp logs for all examples.

newton/_src/sim/graph_coloring.py (1)

249-255: LGTM!

The warning is now appropriately gated behind the verbose flag, allowing users to suppress informational warnings about color balancing early termination when running in quiet mode.

newton/_src/solvers/vbd/solver_vbd.py (1)

2333-2334: LGTM!

The deprecation warning is now appropriately gated behind the verbose flag, allowing users to suppress this informational message when running in quiet mode. The functional behavior remains unchanged—tiled solve is still disabled on CPU at line 2336.

newton/tests/test_inertia_validation.py (2)

178-178: LGTM!

Passing verbose=True is necessary here to ensure the inertia validation warning is emitted during the fast validation path, allowing the test to verify the warning behavior.


250-250: LGTM!

Passing verbose=True is necessary here to ensure the inertia validation warning is emitted when testing default validation behavior, allowing the test to verify that critical issues like negative mass are caught and reported.

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

5133-5138: LGTM!

The verbose gating is correctly applied. Warnings for inertia corrections are now only emitted when verbose=True, which aligns with the PR objective of cleaning up warnings while still allowing users to opt-in to diagnostic output.

@jvonmuralt jvonmuralt marked this pull request as ready for review December 1, 2025 09:08
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
newton/_src/sim/builder.py (1)

4907-4921: Finalize’s new verbose parameter: API shape looks fine; consider minor polish

Extending finalize with verbose: bool = wp.config.verbose is backward compatible and nicely documented. Two optional tweaks you might consider:

  • The default is captured at import time; if wp.config.verbose is toggled later, calls like builder.finalize() will not reflect that change. A more dynamic pattern would be verbose: bool | None = None and if verbose is None: verbose = wp.config.verbose inside the method, though this is consistent with collapse_fixed_joints today.
  • Style3D’s builder override (builder_style3d.ModelBuilder.finalize(self, device=None, requires_grad=False)) does not accept verbose and therefore can’t be called as finalize(verbose=...). To keep the subclass LSP‑compatible with ModelBuilder, you may want to add verbose: bool = wp.config.verbose there as well and pass it through to super().finalize(...).
📜 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 faeb80b and cda7469.

📒 Files selected for processing (1)
  • newton/_src/sim/builder.py (3 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
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.
🧬 Code graph analysis (1)
newton/_src/sim/builder.py (2)
newton/_src/geometry/types.py (2)
  • finalize (102-109)
  • finalize (251-268)
newton/_src/sim/style3d/builder_style3d.py (1)
  • finalize (675-698)
⏰ 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). (2)
  • GitHub Check: Run GPU Tests / Run GPU Unit Tests on AWS EC2
  • GitHub Check: Run GPU Benchmarks / Run GPU Benchmarks on AWS EC2
🔇 Additional comments (1)
newton/_src/sim/builder.py (1)

5134-5139: Verbose‑gated inertia correction warning behaves as intended

Conditioning the inertia‑correction warning on num_corrections > 0 and verbose preserves diagnostics when needed while respecting quiet mode; the fast path still applies corrections regardless of verbosity.

@jvonmuralt jvonmuralt marked this pull request as draft December 1, 2025 09:25
@jvonmuralt jvonmuralt marked this pull request as ready for review December 1, 2025 10:17
import newton
from newton.tests.unittest_utils import find_nan_members

wp.config.quiet = True
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should not change this for the newton.examples module here. There can be scenarios where newton.examples is imported, so changing global Warp config is not intended.


import warp as wp # noqa: PLC0415 NVIDIA Modification

wp.config.quiet = True
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have this line also below in this file, can we remove either of those?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may be mistaken, but I think we need both, the one in main is needed when running tests with --serial-fallback, and in each process is needed when tests are run in parallel

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

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 4f00996 and c7e58c0.

📒 Files selected for processing (1)
  • newton/examples/__init__.py (2 hunks)
🧰 Additional context used
🧠 Learnings (2)
📚 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/examples/__init__.py
📚 Learning: 2025-08-25T21:41:45.795Z
Learnt from: dylanturpin
Repo: newton-physics/newton PR: 634
File: newton/tests/test_examples.py:329-333
Timestamp: 2025-08-25T21:41:45.795Z
Learning: Newton examples use a centralized CLI argument parsing system in newton/examples/__init__.py. The create_parser() function defines common arguments like --device, --viewer, --output-path, and --num-frames, while init(parser) creates viewers based on parsed arguments. Individual example scripts don't need to define these flags themselves - they inherit them from the centralized system via the example_map and runpy execution.

Applied to files:

  • newton/examples/__init__.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). (2)
  • GitHub Check: Run GPU Tests / Run GPU Unit Tests on AWS EC2
  • GitHub Check: Run GPU Benchmarks / Run GPU Benchmarks on AWS EC2
🔇 Additional comments (1)
newton/examples/__init__.py (1)

383-384: Unable to complete verification due to repository access failure. Manual verification or code context is needed.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

♻️ Duplicate comments (1)
newton/examples/__init__.py (1)

373-375: Global wp.config.quiet mutation in init() is still fragile and surprising

init() now unconditionally does:

args._original_warp_quiet = wp.config.quiet
wp.config.quiet = True

and relies on _quiet_warp_context(args) in run() to restore the original value. This has a few issues:

  • Any caller that uses newton.examples.init() but never calls run(example, args) will leave wp.config.quiet permanently set to True for the rest of the process.
  • If run() is called with a different args object than the one returned from init(), the original state is also not restored.
  • It still conflicts with the earlier review feedback that newton.examples shouldn’t change global Warp config in general, since this is a library-style helper that can be imported and used outside the CLI path.

To avoid surprising global side effects and fragile coupling between init() and run(), consider one of the following:

  • Remove the wp.config.quiet mutation from init() and have _quiet_warp_context fully manage both setting and restoring wp.config.quiet around whatever region you want muted (perhaps only under args.test, or only from the main() CLI entrypoint), or
  • Gate this behind an explicit, opt-in flag (e.g., --quiet / args.quiet) so that library-style usage of newton.examples.init() doesn’t silently alter global Warp logging.

This would better align with the prior concern about not letting newton.examples change Warp global state.

🧹 Nitpick comments (2)
newton/examples/__init__.py (2)

18-34: Tight coupling between _quiet_warp_context and init()’s side effect

_quiet_warp_context(args) only restores wp.config.quiet based on args._original_warp_quiet and never sets it, so it implicitly relies on init() having already set both args._original_warp_quiet and wp.config.quiet. That hidden coupling makes the lifecycle harder to reason about (e.g., if run() is ever called with args that didn’t come from init(), this context manager becomes a no-op).

Consider making _quiet_warp_context self-contained (capture current wp.config.quiet, set it to the desired value on __enter__, always restore on __exit__) and/or documenting that it assumes init() has run.


184-224: run() logic looks sound; Ruff TRY003 on NaN checks is stylistic only

The refactored run() flow (GUI registration, main loop with ScopedTimers, viewer close, and optional args.test validations) is straightforward and functionally coherent. The generic NaN checks via find_nan_members for state_0, state_1, model, control, and contacts gated behind args.test are a nice addition for test-mode robustness.

Ruff’s TRY003 warnings on the ValueError messages at lines 208/212/216/220/224 are style-only; given these errors are specific diagnostics for tests, keeping the explicit messages is reasonable. If you prefer to satisfy TRY003, you could introduce a small helper like raise_nan_error(label, nan_members) instead of inlining similar ValueError constructions five times.

📜 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 c7e58c0 and 306ecbd.

📒 Files selected for processing (1)
  • newton/examples/__init__.py (4 hunks)
🧰 Additional context used
🧠 Learnings (2)
📚 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/examples/__init__.py
📚 Learning: 2025-08-25T21:41:45.795Z
Learnt from: dylanturpin
Repo: newton-physics/newton PR: 634
File: newton/tests/test_examples.py:329-333
Timestamp: 2025-08-25T21:41:45.795Z
Learning: Newton examples use a centralized CLI argument parsing system in newton/examples/__init__.py. The create_parser() function defines common arguments like --device, --viewer, --output-path, and --num-frames, while init(parser) creates viewers based on parsed arguments. Individual example scripts don't need to define these flags themselves - they inherit them from the centralized system via the example_map and runpy execution.

Applied to files:

  • newton/examples/__init__.py
🧬 Code graph analysis (1)
newton/examples/__init__.py (1)
newton/tests/unittest_utils.py (1)
  • find_nan_members (256-265)
🪛 Ruff (0.14.7)
newton/examples/__init__.py

208-208: Avoid specifying long messages outside the exception class

(TRY003)


212-212: Avoid specifying long messages outside the exception class

(TRY003)


216-216: Avoid specifying long messages outside the exception class

(TRY003)


220-220: Avoid specifying long messages outside the exception class

(TRY003)


224-224: Avoid specifying long messages outside the exception class

(TRY003)

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.

Clean up warnings/errors printed when running unit tests and examples

2 participants