Skip to content

Fixes for pre-trained anymal-c example/benchmark#687

Merged
eric-heiden merged 3 commits into
newton-physics:mainfrom
adenzler-nvidia:dev/adenzler/no-collision-anymal-bench
Aug 29, 2025
Merged

Fixes for pre-trained anymal-c example/benchmark#687
eric-heiden merged 3 commits into
newton-physics:mainfrom
adenzler-nvidia:dev/adenzler/no-collision-anymal-bench

Conversation

@adenzler-nvidia

@adenzler-nvidia adenzler-nvidia commented Aug 29, 2025

Copy link
Copy Markdown
Member

Don't call collide because we do the collisions in MuJoCo
Enable parallel linesearch.

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

    • Enabled parallel line search in the MuJoCo solver for the ANYmal-C walking example, improving simulation performance.
  • Refactor

    • Removed collision contact computation and usage during simulation in the example.
    • Eliminated contact logging in the viewer, simplifying the example’s output.

Signed-off-by: Alain Denzler <adenzler@nvidia.com>
@coderabbitai

coderabbitai Bot commented Aug 29, 2025

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

The example updates construct SolverMuJoCo with ls_parallel=True, removes contact computation/storage and downstream usage, calls solver.step without contacts, and eliminates contact logging in render. No public API signatures changed.

Changes

Cohort / File(s) Summary
Example robot walk flow adjustments
newton/examples/robot/example_robot_anymal_c_walk.py
- Instantiate SolverMuJoCo with ls_parallel=True
- Remove self.contacts initialization and any contact computations
- Call solver.step with None for contacts
- Remove viewer.log_contacts in render

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant App as Example Script
  participant Solver as SolverMuJoCo
  participant Viewer as Viewer

  rect rgba(230,245,255,0.6)
    note over App,Solver: Initialization
    App->>Solver: new SolverMuJoCo(..., ls_parallel=true)
  end

  loop simulate() step
    note over App,Solver: Contacts no longer computed
    App->>Solver: step(state, controls, contacts=None)
    Solver-->>App: next state
  end

  rect rgba(240,255,240,0.6)
    note over App,Viewer: Rendering
    App->>Viewer: render(state)
    note right of Viewer: No contact logging
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • shi-eric
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbit in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbit in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbit gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbit read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbit help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbit ignore or @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbit summary or @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbit or @coderabbitai anywhere in the PR title to generate the title automatically.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Signed-off-by: Alain Denzler <adenzler@nvidia.com>

@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: 0

🧹 Nitpick comments (2)
newton/examples/robot/example_robot_anymal_c_walk.py (2)

145-148: Make MuJoCo-contacts intent explicit and add a guard.

To prevent future regressions if defaults change, explicitly opt into MuJoCo contacts and assert the expectation at runtime.

-        self.solver = newton.solvers.SolverMuJoCo(self.model, ls_parallel=True)
+        self.solver = newton.solvers.SolverMuJoCo(
+            self.model,
+            ls_parallel=True,
+            use_mujoco_contacts=True,  # collisions handled by MuJoCo
+        )
+        # Defensive: this example expects MuJoCo to run collision detection.
+        if hasattr(self.solver, "mjw_model"):
+            assert bool(self.solver.mjw_model.opt.run_collision_detection), \
+                "Example requires MuJoCo collision detection; don't disable run_collision_detection."

195-195: Guard None contacts on use_mujoco_contacts
By default use_mujoco_contacts=True drives mjw_model.opt.run_collision_detection, so step(..., contacts=None, ...) is safe; if that flag is ever disabled, passing None will break. Around line 195 in newton/examples/robot/example_robot_anymal_c_walk.py, wrap the call in an if use_mujoco_contacts check (or compute/provide contacts when it’s False) before invoking self.solver.step.

📜 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.

📥 Commits

Reviewing files that changed from the base of the PR and between a943c90 and 7f91c66.

📒 Files selected for processing (1)
  • newton/examples/robot/example_robot_anymal_c_walk.py (2 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: preist-nvidia
PR: newton-physics/newton#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: preist-nvidia
PR: newton-physics/newton#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: adenzler-nvidia
PR: newton-physics/newton#479
File: newton/solvers/mujoco/solver_mujoco.py:2147-2149
Timestamp: 2025-07-28T15:04:54.360Z
Learning: In the Newton MuJoCo solver implementation, the ls_parallel option may not be available in the pure MuJoCo mjOption structure, despite being documented in newer MuJoCo versions. The user adenzler-nvidia confirmed that mj_model does not have this attribute in their implementation, so ls_parallel should only be set on mjw_model.opt.
⏰ 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/examples/robot/example_robot_anymal_c_walk.py (1)

145-145: MJWarp parallel line search is wired correctly.

Passing ls_parallel=True to SolverMuJoCo aligns with convert_to_mjc setting mjw_model.opt.ls_parallel; safe for CPU fallback (no effect there).

@eric-heiden eric-heiden enabled auto-merge (squash) August 29, 2025 21:28
@eric-heiden eric-heiden merged commit 74a8b51 into newton-physics:main Aug 29, 2025
10 of 11 checks passed
maxkra15 pushed a commit to maxkra15/newton that referenced this pull request Sep 1, 2025
Signed-off-by: Alain Denzler <adenzler@nvidia.com>
eric-heiden pushed a commit to eric-heiden/newton that referenced this pull request Jan 28, 2026
Signed-off-by: Alain Denzler <adenzler@nvidia.com>
mmacklin pushed a commit to mmacklin/newton that referenced this pull request Apr 7, 2026
Signed-off-by: Alain Denzler <adenzler@nvidia.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.

2 participants