Skip to content

Conversation

@Kenny-Vilella
Copy link
Member

@Kenny-Vilella Kenny-Vilella commented Dec 31, 2025

Description

Updated MjWarp dependency
Updated njmax and nconmax heuristic to follow MjWarp by default.

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

  • Bug Fixes

    • Solver now warns and preserves required contact/joint buffer sizes when user-provided limits are smaller, preventing unintended truncation of simulation contacts.
  • Chores

    • Updated benchmark/environment dependency reference used for performance testing.
    • Increased example contact limits in robot demos to better reflect realistic scenarios.

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

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 31, 2025

📝 Walkthrough

Walkthrough

Updates pinned mujoco_warp commit in ASV config, tightens SolverMuJoCo logic to only override nconmax/njmax when explicit smaller values are passed, and increases nconmax values in two robot example files.

Changes

Cohort / File(s) Change Summary
Build configuration
asv.conf.json
Update mujoco_warp GitHub dependency commit in ASV install_command (pinned commit changed to 24e07def...).
MuJoCo solver logic
newton/_src/solvers/mujoco/solver_mujoco.py
Adjusted contact/jacobian capacity handling: only warn and override nconmax / njmax when the corresponding argument is provided and strictly less than mj_data values; removed previous behavior that implicitly copied mj_data values when args were None.
Example usage
newton/examples/robot/example_robot_anymal_d.py, newton/examples/robot/example_robot_anymal_c_walk.py
Increased SolverMuJoCo nconmax in examples: example_robot_anymal_d.py 20 → 35; example_robot_anymal_c_walk.py adds nconmax=75.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • adenzler-nvidia
  • shi-eric
🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Update MjWarp dependency' is directly related to the main changeset. The PR updates the MjWarp dependency commit hash in asv.conf.json and adjusts nconmax/njmax parameters in solver and example files to align with MjWarp defaults.

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

✨ Finishing touches
  • 📝 Generate docstrings

📜 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 9b2b451 and 5c862a0.

📒 Files selected for processing (1)
  • newton/_src/solvers/mujoco/solver_mujoco.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • newton/_src/solvers/mujoco/solver_mujoco.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 (windows-latest)
  • GitHub Check: run-newton-tests / newton-unittests (ubuntu-latest)

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 Dec 31, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 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/examples/robot/example_robot_anymal_d.py (1)

89-89: Increased nconmax to accommodate MjWarp requirements.

The increase from 20 to 35 aligns with the updated MjWarp integration where explicit values must meet MjWarp's minimum requirements. The previous value of 20 would trigger a warning (lines 1951-1954 in solver_mujoco.py).

Consider using None for automatic sizing:

If the goal is to use MjWarp's automatic heuristic, you could omit nconmax entirely or set it to None, allowing MjWarp to determine the optimal value:

self.solver = newton.solvers.SolverMuJoCo(
    self.model,
    cone=mujoco.mjtCone.mjCONE_ELLIPTIC,
    impratio=100,
    iterations=100,
    ls_iterations=50,
    # nconmax=None,  # Let MjWarp determine the default
    njmax=100,
    use_mujoco_contacts=args.use_mujoco_contacts if args else False,
)
📜 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 dccbc66 and 2794d39.

⛔ Files ignored due to path filters (1)
  • uv.lock is excluded by !**/*.lock
📒 Files selected for processing (3)
  • asv.conf.json
  • newton/_src/solvers/mujoco/solver_mujoco.py
  • newton/examples/robot/example_robot_anymal_d.py
🧰 Additional context used
🧠 Learnings (8)
📓 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.
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.
Learnt from: preist-nvidia
Repo: newton-physics/newton PR: 579
File: newton/examples/example_mujoco.py:350-354
Timestamp: 2025-08-19T12:27:30.629Z
Learning: In Newton examples, Example.use_mujoco is a high-level attribute that controls whether to use MuJoCo solver vs other solvers (like XPBD), while SolverMuJoCo.use_mujoco_cpu controls the backend within MuJoCo (CPU vs Warp). These are separate concepts serving different purposes - the PR rename only applies to the solver parameter, not the Example class attributes.
Learnt from: preist-nvidia
Repo: newton-physics/newton PR: 579
File: newton/examples/example_mujoco.py:350-354
Timestamp: 2025-08-19T12:27:30.629Z
Learning: In Newton examples, there's a distinction between solver parameters and Example class attributes. The Example class can have its own use_mujoco attribute for controlling example-level behavior (like CUDA graphs, rendering logic), while the solver uses use_mujoco_cpu for backend selection. These serve different purposes and should not be conflated during API renames.
Learnt from: Kenny-Vilella
Repo: newton-physics/newton PR: 398
File: newton/examples/example_mujoco.py:352-352
Timestamp: 2025-07-14T03:57:29.670Z
Learning: The use_mujoco option in newton/examples/example_mujoco.py is currently unsupported and causes crashes. The code automatically disables this option with a warning message when users attempt to enable it. This is intentionally kept as a placeholder for future implementation.
📚 Learning: 2025-11-24T08:05:21.390Z
Learnt from: adenzler-nvidia
Repo: newton-physics/newton PR: 1107
File: newton/_src/solvers/mujoco/kernels.py:973-974
Timestamp: 2025-11-24T08:05:21.390Z
Learning: In Newton's MuJoCo solver integration (newton/_src/solvers/mujoco/), the mapping between Newton joints and MuJoCo joints is not 1-to-1. Instead, each Newton DOF maps to a distinct MuJoCo joint. This means that for multi-DOF joints (like D6 with 6 DOFs), there will be 6 corresponding MuJoCo joints, each with its own properties (margin, solimp, solref, etc.). The mapping is done via dof_to_mjc_joint array, ensuring each DOF's properties are written to its own MuJoCo joint without overwriting.

Applied to files:

  • newton/_src/solvers/mujoco/solver_mujoco.py
📚 Learning: 2025-08-19T12:27:30.629Z
Learnt from: preist-nvidia
Repo: newton-physics/newton PR: 579
File: newton/examples/example_mujoco.py:350-354
Timestamp: 2025-08-19T12:27:30.629Z
Learning: In Newton examples, Example.use_mujoco is a high-level attribute that controls whether to use MuJoCo solver vs other solvers (like XPBD), while SolverMuJoCo.use_mujoco_cpu controls the backend within MuJoCo (CPU vs Warp). These are separate concepts serving different purposes - the PR rename only applies to the solver parameter, not the Example class attributes.

Applied to files:

  • newton/_src/solvers/mujoco/solver_mujoco.py
  • newton/examples/robot/example_robot_anymal_d.py
📚 Learning: 2025-07-14T03:57:29.670Z
Learnt from: Kenny-Vilella
Repo: newton-physics/newton PR: 398
File: newton/examples/example_mujoco.py:352-352
Timestamp: 2025-07-14T03:57:29.670Z
Learning: The use_mujoco option in newton/examples/example_mujoco.py is currently unsupported and causes crashes. The code automatically disables this option with a warning message when users attempt to enable it. This is intentionally kept as a placeholder for future implementation.

Applied to files:

  • newton/_src/solvers/mujoco/solver_mujoco.py
📚 Learning: 2025-09-18T07:05:56.836Z
Learnt from: gdaviet
Repo: newton-physics/newton PR: 750
File: newton/_src/solvers/implicit_mpm/solve_rheology.py:969-986
Timestamp: 2025-09-18T07:05:56.836Z
Learning: In newton/_src/solvers/implicit_mpm/solve_rheology.py, transposed_strain_mat parameter cannot be None - the type signature was corrected to reflect this guarantee, eliminating the need for None checks when accessing transposed_strain_mat.offsets.

Applied to files:

  • newton/_src/solvers/mujoco/solver_mujoco.py
📚 Learning: 2025-08-19T12:27:30.629Z
Learnt from: preist-nvidia
Repo: newton-physics/newton PR: 579
File: newton/examples/example_mujoco.py:350-354
Timestamp: 2025-08-19T12:27:30.629Z
Learning: In Newton examples, there's a distinction between solver parameters and Example class attributes. The Example class can have its own use_mujoco attribute for controlling example-level behavior (like CUDA graphs, rendering logic), while the solver uses use_mujoco_cpu for backend selection. These serve different purposes and should not be conflated during API renames.

Applied to files:

  • newton/_src/solvers/mujoco/solver_mujoco.py
  • newton/examples/robot/example_robot_anymal_d.py
📚 Learning: 2025-12-12T08:45:43.428Z
Learnt from: nvtw
Repo: newton-physics/newton PR: 1221
File: newton/examples/example_sdf.py:277-287
Timestamp: 2025-12-12T08:45:43.428Z
Learning: In Newtown (Newton) example code, specifically files under newton/examples, computing contacts once per frame and reusing them across all substeps is an intentional design choice, not a bug. Reviewers should verify that contacts are computed before the substep loop and reused for every substep within the same frame. This pattern reduces redundant work and preserves frame-consistency; do not flag as a regression unless the behavior is changed for correctness or performance reasons.

Applied to files:

  • newton/examples/robot/example_robot_anymal_d.py
📚 Learning: 2025-08-27T23:33:32.527Z
Learnt from: shi-eric
Repo: newton-physics/newton PR: 660
File: pyproject.toml:28-28
Timestamp: 2025-08-27T23:33:32.527Z
Learning: In Python projects, it's normal and correct to have different warp-lang version specifications across files: pyproject.toml should specify minimum compatible versions using >= for flexibility, while specific environments like asv.conf.json can pin exact versions using == for reproducibility. These serve different purposes and should not be "aligned" to the same version.

Applied to files:

  • asv.conf.json
⏰ 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). (3)
  • 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 (windows-latest)
🔇 Additional comments (3)
newton/_src/solvers/mujoco/solver_mujoco.py (2)

1948-1955: LGTM! Delegates nconmax default to MjWarp.

The updated logic now only validates and warns when nconmax is explicitly provided and is smaller than MjWarp's computed value. When nconmax is None, it's passed through to mujoco_warp.put_data (line 1968), allowing MjWarp to determine the default value. This aligns with the PR objective to "follow MjWarp by default."


1957-1962: LGTM! Delegates njmax default to MjWarp.

Similar to nconmax, the updated logic now only validates and warns when njmax is explicitly provided and is smaller than MjWarp's computed value. When njmax is None, it's passed through to mujoco_warp.put_data (line 1969), allowing MjWarp to determine the default value. This aligns with the PR objective to "follow MjWarp by default."

asv.conf.json (1)

22-22: Verify the mujoco_warp commit is valid and compatible.

The commit hash 24e07def301f3c073d8bc0f948831c5611737ff0 is pinned in both asv.conf.json and uv.lock, suggesting the dependency was successfully resolved. However, the commit should be verified directly in the mujoco_warp repository to ensure it exists and doesn't introduce breaking changes with the current Newton codebase, particularly given the extensive mujoco_warp integration across test suites and the MuJoCo solver implementation.

@Kenny-Vilella
Copy link
Member Author

The failing benchmark is an artifact because of a mismatch between MjWarp dep in the asv file and the njmax and nconmax heuristic. We are using the same asv file for both trunk and this branch instead of using their own asv file.
If I run the benchmark locally, I do not have any regression.
I also do not have all the warning messages.

@adenzler-nvidia
Copy link
Member

change is looking good and I agree with using MjWarp defaults.

Will approve once the benchmark failures are addressed/investigated.

@Kenny-Vilella
Copy link
Member Author

@adenzler-nvidia I think that the failing benchmarks are just artifacts.
Can you try to verify my observation by running the benchmark locally on the main branch and on this branch?

@adenzler-nvidia
Copy link
Member

I can reproduce locally. The reason for the perf regression is that njmax changes from 0 to 64 with the new defaults. So to restore perf we could just set njmax to 0.

The other question is whether that asset really does not have any constraints. Are there no joint limits? We explicitly disable contacts, but to me it seems like the proper thing would actually be to change the asset to make sure we have proper collision filtering.

Either way I think it's both ok to merge like this or to go hardcode njmax to 0. I don't think we low a lot of signal in the benchmarks.

The additional follow-up is whether the selection example and the standalone cartpole example should somehow be merged to avoid these 2 diverging all the time.

@Kenny-Vilella
Copy link
Member Author

Kenny-Vilella commented Jan 12, 2026

@adenzler-nvidia For the Cartpole issue, are you sure that you purged the asv/env folder between the two runs?
If I follow this process:

  • Clone repository
  • Run benchmark on my branch
  • Checkout main
  • Run benchmark on main

I will see the regression.
If I remove the asv/env folder and rerun the benchmark on main, then the regression is not there anymore.

In those cases, I always run on two different fresh clones to be sure there is no clash at all.

On proper main njmax is actually equal to 5, which makes more sense than 0.
The update still increases njmax from 5 to 64, but the impact on perf should be negligible.

It's actually worse than that, IsaacLab also use another Cartpole, one has a single pendulum and the other a double pendulum.
Never took the time to change that because I would prefer to stop using cartpole and switch to a franka arm.
We could probably organize the switch after release.

Copy link
Member

@adenzler-nvidia adenzler-nvidia left a comment

Choose a reason for hiding this comment

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

Can confirm, with a fresh env folder I'm getting the same numbers for both branches. Let's merge this.

@eric-heiden eric-heiden merged commit 349a1c2 into newton-physics:main Jan 12, 2026
21 of 22 checks passed
@Kenny-Vilella Kenny-Vilella deleted the dev/kvilella/update_mujoco_warp_dependency branch January 13, 2026 05:27
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.

3 participants