Skip to content

Switch MuJoCo examples and Benchmarks to Parallel Linesearch#738

Merged
adenzler-nvidia merged 8 commits into
newton-physics:mainfrom
adenzler-nvidia:dev/adenzler/ls-parallel-mujoco
Sep 8, 2025
Merged

Switch MuJoCo examples and Benchmarks to Parallel Linesearch#738
adenzler-nvidia merged 8 commits into
newton-physics:mainfrom
adenzler-nvidia:dev/adenzler/ls-parallel-mujoco

Conversation

@adenzler-nvidia

@adenzler-nvidia adenzler-nvidia commented Sep 4, 2025

Copy link
Copy Markdown
Member

First step towards aligning the benchmarks with IsaacLab configs. There, parallel linesearch is enabled everywhere.

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

    • Per-robot control for parallel line-search in the MuJoCo example with sensible defaults per robot.
    • New CLI flag --ls-parallel to override parallel line-search at runtime.
  • Documentation

    • Example configuration and docs updated to show the parallel line-search setting and per-robot defaults.
    • Configuration summary now prints the active Parallel Line Search setting.
  • Notes

    • No breaking changes; behavior is configurable via defaults or CLI.

@coderabbitai

coderabbitai Bot commented Sep 4, 2025

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Adds a per-robot ls_parallel config and a --ls-parallel CLI flag; the value is resolved (CLI override or robot default) in Example.__init__ and passed into newton.solvers.SolverMuJoCo and the model builder; defaults: humanoid: False, others True.

Changes

Cohort / File(s) Summary
MuJoCo example and CLI wiring
newton/examples/example_mujoco.py
Adds ls_parallel entries to ROBOT_CONFIGS, introduces --ls-parallel CLI arg (BooleanOptionalAction, default True), resolves active ls_parallel in Example.__init__ (CLI override else robot default), passes ls_parallel= into newton.solvers.SolverMuJoCo and the model-builder, and prints the active setting in the configuration summary.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant CLI
    participant Example
    participant SolverMuJoCo
    participant MuJoCoModel

    CLI->>Example: parse args (includes --ls-parallel)
    Note right of Example: choose ls_parallel = CLI value if set else ROBOT_CONFIGS[robot]["ls_parallel"]
    Example->>SolverMuJoCo: init(..., ls_parallel=chosen_value)
    SolverMuJoCo->>MuJoCoModel: create_model_builder(ls_parallel=chosen_value)
    Note right of MuJoCoModel: set opt.ls_parallel = chosen_value
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • eric-heiden
  • shi-eric

📜 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 203eb5e and 5cb2c92.

📒 Files selected for processing (1)
  • newton/examples/example_mujoco.py (7 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • newton/examples/example_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 Unit Tests on AWS EC2 (Pull Request)
  • GitHub Check: Run GPU Benchmarks (Pull Request)
  • GitHub Check: run-newton-tests / newton-unittests (windows-latest)
  • GitHub Check: run-newton-tests / newton-unittests (ubuntu-latest)
✨ 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

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

@eric-heiden

eric-heiden commented Sep 4, 2025

Copy link
Copy Markdown
Member

The benchmarks show a noticeable runtime increase. Is this acceptable for the low env counts we are benchmarking?

@adenzler-nvidia

Copy link
Copy Markdown
Member Author

something is off looking at the benchmarks, will look at it. Thanks for reminding me!

@adenzler-nvidia

Copy link
Copy Markdown
Member Author

#745

I think we should defer this investigation. I found out what happens but couldn't figure out how to fix it - might also be an issue in MjWarp. Given that this is working for the real robots, I suggest to go ahead and follow up in that ticket.

@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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
newton/examples/example_mujoco.py (1)

240-251: Fix undefined variable and wire CLI correctly; also avoid type=bool pitfall.

ls_parallel is referenced before definition (Line 240). The CLI flag is parsed but never passed to Example, and type=bool will misparse strings. Wire the flag through and switch to BooleanOptionalAction.

Apply this diff:

@@
     def __init__(
         self,
         robot="humanoid",
         stage_path=None,
         num_envs=1,
         use_cuda_graph=True,
         use_mujoco_cpu=False,
         randomize=False,
         headless=False,
         actuation="None",
         solver=None,
         integrator=None,
         solver_iteration=None,
         ls_iteration=None,
         njmax=None,
         nconmax=None,
+        ls_parallel=None,
         builder=None,
     ):
@@
-        ls_parallel = ls_parallel if ls_parallel is not None else ROBOT_CONFIGS[robot]["ls_parallel"]
+        ls_parallel = ls_parallel if ls_parallel is not None else ROBOT_CONFIGS[robot]["ls_parallel"]
@@
-    parser.add_argument("--ls-parallel", type=bool, default=None, help="Use parallel line search.")
+    parser.add_argument(
+        "--ls-parallel",
+        default=None,
+        action=argparse.BooleanOptionalAction,
+        help="Use parallel line search.",
+    )
@@
         example = Example(
             robot=args.robot,
             stage_path=args.stage_path,
             num_envs=args.num_envs,
             use_cuda_graph=args.use_cuda_graph,
             use_mujoco_cpu=args.use_mujoco_cpu,
             randomize=args.random_init,
             headless=args.headless,
             actuation=args.actuation,
             solver=args.solver,
             integrator=args.integrator,
             solver_iteration=args.solver_iteration,
             ls_iteration=args.ls_iteration,
             njmax=args.njmax,
             nconmax=args.nconmax,
+            ls_parallel=args.ls_parallel,
         )

Also applies to: 383-384, 391-407

🧹 Nitpick comments (1)
newton/examples/example_mujoco.py (1)

438-446: Optional: print actual ls_parallel in the run summary.

Adds quick visibility to the effective setting and avoids confusion across CPU/Warp paths.

@@
         print(f"{'Line Search Iterations':<{LABEL_WIDTH}}: {example.solver.mj_model.opt.ls_iterations}")
         print(f"{'Max Constraints / env':<{LABEL_WIDTH}}: {actual_njmax}")
         print(f"{'Max Contacts / env':<{LABEL_WIDTH}}: {actual_nconmax}")
+        # Prefer Warp option; fall back to mj_model if present
+        lspar = (
+            getattr(getattr(getattr(example.solver, 'mjw_model', None), 'opt', None), 'ls_parallel', None)
+            if hasattr(example.solver, 'mjw_model') else None
+        )
+        if lspar is None:
+            lspar = getattr(getattr(example.solver.mj_model, 'opt', object()), 'ls_parallel', 'n/a')
+        print(f"{'Parallel Linesearch':<{LABEL_WIDTH}}: {lspar}")
         print(f"{'Joint DOFs':<{LABEL_WIDTH}}: {example.model.joint_dof_count}")
         print(f"{'Body Count':<{LABEL_WIDTH}}: {example.model.body_count}")
📜 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 4bf234d and 8600dec.

📒 Files selected for processing (1)
  • newton/examples/example_mujoco.py (4 hunks)
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
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.
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: The ls_parallel option is specific to MuJoCo Warp and is not available in the pure MuJoCo mjOption structure. It should only be set on mjw_model.opt, not mj_model.opt.
📚 Learning: 2025-07-28T15:04:54.360Z
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.

Applied to files:

  • newton/examples/example_mujoco.py
📚 Learning: 2025-08-19T12:27:30.629Z
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.

Applied to files:

  • newton/examples/example_mujoco.py
🪛 Ruff (0.12.2)
newton/examples/example_mujoco.py

240-240: Undefined name ls_parallel

(F821)


240-240: Undefined name ls_parallel

(F821)

⏰ 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 Unit Tests on AWS EC2 (Pull Request)
  • GitHub Check: Run GPU Benchmarks (Pull Request)
  • GitHub Check: run-newton-tests / newton-unittests (ubuntu-latest)
  • GitHub Check: run-newton-tests / newton-unittests (windows-latest)
🔇 Additional comments (2)
newton/examples/example_mujoco.py (2)

44-44: Confirm per-robot ls_parallel defaults
Defaults are False for humanoid and True for all other robots; ensure this matches IsaacLab guidelines and expected benchmark performance at low environment counts.


241-251: The SolverMuJoCo.__init__ signature does include an ls_parallel parameter and it only applies it on mjw_model.opt, not mj_model.opt. No changes needed.

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: 2

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

209-210: Expose ls_parallel on the Example instance

Useful for introspection and summaries; store it on self.

Apply:

 class Example:
@@
-        ls_parallel=None,
+        ls_parallel=None,

And in the body (see next comment) set self.ls_parallel once.


241-252: Store ls_parallel on self and pass that into the solver

This avoids recomputing and makes the setting accessible.

-        ls_parallel = ls_parallel if ls_parallel is not None else ROBOT_CONFIGS[robot]["ls_parallel"]
+        self.ls_parallel = ls_parallel if ls_parallel is not None else ROBOT_CONFIGS[robot]["ls_parallel"]
         self.solver = newton.solvers.SolverMuJoCo(
@@
-            ls_parallel=ls_parallel,
+            ls_parallel=self.ls_parallel,
         )
📜 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 8600dec and e81931a.

📒 Files selected for processing (1)
  • newton/examples/example_mujoco.py (7 hunks)
🧰 Additional context used
🧠 Learnings (4)
📓 Common learnings
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.
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: The ls_parallel option is specific to MuJoCo Warp and is not available in the pure MuJoCo mjOption structure. It should only be set on mjw_model.opt, not mj_model.opt.
📚 Learning: 2025-07-28T15:04:54.360Z
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.

Applied to files:

  • newton/examples/example_mujoco.py
📚 Learning: 2025-08-19T12:27:30.629Z
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.

Applied to files:

  • newton/examples/example_mujoco.py
📚 Learning: 2025-08-19T12:27:30.629Z
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.

Applied to files:

  • newton/examples/example_mujoco.py
🔇 Additional comments (3)
newton/examples/example_mujoco.py (3)

44-44: Per-robot ls_parallel defaults look good

Defaults align with the PR intent and IsaacLab practice. No issues spotted.

Also applies to: 51-51, 58-58, 65-65, 72-72, 79-79


409-409: CLI plumbing LGTM

The CLI flag is correctly forwarded into Example(...).


242-252: Resolved: SolverMuJoCo init supports ls_parallel Confirmed the constructor signature defines an ls_parallel parameter (default False) and applies it to mjw_model.opt.ls_parallel.

Comment thread newton/examples/example_mujoco.py
Comment thread newton/examples/example_mujoco.py
Signed-off-by: Alain Denzler <adenzler@nvidia.com>
Signed-off-by: Alain Denzler <adenzler@nvidia.com>
@adenzler-nvidia adenzler-nvidia merged commit 20339d3 into newton-physics:main Sep 8, 2025
12 checks passed
eric-heiden pushed a commit to eric-heiden/newton that referenced this pull request Jan 28, 2026
…physics#738)

Signed-off-by: Alain Denzler <adenzler@nvidia.com>
Co-authored-by: Eric Shi <97630937+shi-eric@users.noreply.github.com>
mmacklin pushed a commit to mmacklin/newton that referenced this pull request Apr 7, 2026
…physics#738)

Signed-off-by: Alain Denzler <adenzler@nvidia.com>
Co-authored-by: Eric Shi <97630937+shi-eric@users.noreply.github.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.

3 participants