Skip to content

Added a unified script to run mujoco examples#398

Merged
eric-heiden merged 9 commits into
newton-physics:mainfrom
Kenny-Vilella:dev/kvilella/add_unified_script_run_example
Jul 18, 2025
Merged

Added a unified script to run mujoco examples#398
eric-heiden merged 9 commits into
newton-physics:mainfrom
Kenny-Vilella:dev/kvilella/add_unified_script_run_example

Conversation

@Kenny-Vilella

@Kenny-Vilella Kenny-Vilella commented Jul 14, 2025

Copy link
Copy Markdown
Member

Description

Created an example_mujoco.py script that takes several predefined robot and run an example.
Multiple options are available.
This will allow us to avoid code duplication and scale our example to a large number of robots.

Newton Migration Guide

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

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

Before your PR is "Ready for review"

  • All commits are signed-off to indicate that your contribution adheres to the Developer Certificate of Origin requirements
  • [~] 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 a comprehensive example for simulating various articulated robots (humanoid, cartpole, quadruped, etc.) using the Newton physics engine with MuJoCo-style models.
    • Supports configurable simulation parameters, multiple environments, randomization, CUDA acceleration, and optional rendering.
    • Includes command-line interface for customizing robot type, solver options, rendering, and simulation length.

Signed-off-by: Kenny Vilella <kvilella@nvidia.com>
@coderabbitai

coderabbitai Bot commented Jul 14, 2025

Copy link
Copy Markdown
Contributor
📝 Walkthrough

"""

Walkthrough

A new example script for simulating articulated robots using the Newton physics engine with MuJoCo-style models has been added. The script defines an Example class to configure, run, and render simulations for various robot types, supporting multiple environments, CUDA acceleration, and flexible solver and rendering options via a command-line interface.

Changes

File(s) Change Summary
newton/examples/example_mujoco.py Added a comprehensive simulation example for articulated robots using Newton and MuJoCo models, including robot setup, simulation configuration, CUDA graph acceleration, rendering, CLI support, and multiple robot models with randomized initial states.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Example
    participant NewtonEngine
    participant Renderer
    participant MuJoCoViewer

    User->>Example: Initialize (parse args, create Example)
    Example->>NewtonEngine: Load robot model, set up simulation
    loop Simulation steps
        Example->>Example: step()
        Example->>NewtonEngine: simulate()
        alt Rendering enabled
            Example->>Renderer: render()
        end
        alt MuJoCo viewer enabled
            Example->>MuJoCoViewer: sync state and render
        end
    end
Loading

Suggested reviewers

  • eric-heiden
    """
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai 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:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

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

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

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

Documentation and Community

  • 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: Kenny Vilella <kvilella@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: 4

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

16-23: Update module documentation to reflect all supported robot types.

The module documentation mentions only "G1" and "humanoid articulation from xml", but the script actually supports multiple robot types (humanoid, g1, cartpole, quadruped) and both XML and URDF formats.

-# Example Sim G1
+# Example MuJoCo-style Robot Simulations
 #
-# Shows how to set up a simulation of a rigid-body humanoid articulation
-# from a xml using the newton.ModelBuilder().
+# Shows how to set up simulations of various rigid-body articulated robots
+# (humanoid, g1, cartpole, quadruped) from XML or URDF files using the newton.ModelBuilder().
 # Note this example does not include a trained policy.
📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f26eb37 and 6f21afc.

📒 Files selected for processing (1)
  • newton/examples/example_mujoco.py (1 hunks)
🧰 Additional context used
🪛 Ruff (0.11.9)
newton/examples/example_mujoco.py

89-89: Unused noqa directive (non-enabled: PLC0415)

Remove unused noqa directive

(RUF100)

⏰ 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-newton-tests / newton-unittests (windows-latest)
  • GitHub Check: run-newton-tests / newton-unittests (ubuntu-latest)
  • GitHub Check: run-asv-benchmarks
🔇 Additional comments (1)
newton/examples/example_mujoco.py (1)

89-89: Keep the noqa directive - it's correctly suppressing a linting warning.

The noqa: PLC0415 directive is correctly used here to suppress the "import-outside-toplevel" warning for the optional tqdm import. The static analysis tool incorrectly flags this as unused.

Comment thread newton/examples/example_mujoco.py
Comment thread newton/examples/example_mujoco.py Outdated
Comment thread newton/examples/example_mujoco.py Outdated
Comment thread newton/examples/example_mujoco.py

@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

♻️ Duplicate comments (3)
newton/examples/example_mujoco.py (3)

182-183: Raise an exception instead of just printing an error.

When an unrecognized robot name is provided, the method should raise an exception to prevent undefined behavior in the rest of the code.

-            print("Name of the provided robot not recognized: ", robot)
-            return
+            raise ValueError(f"Name of the provided robot not recognized: {robot}")

329-329: Fix AttributeError: use_mujoco attribute doesn't exist.

The Example class doesn't define self.use_mujoco, so referencing example.use_mujoco causes an AttributeError. The solver is created with use_mujoco=False but this parameter isn't stored as an accessible attribute.

Store the use_mujoco value in the Example class or access it from the solver if available:

-        show_mujoco_viewer = args.show_mujoco_viewer and example.use_mujoco
+        # Since solver is created with use_mujoco=False, we can check the args directly
+        show_mujoco_viewer = args.show_mujoco_viewer and False

Or store the value during initialization:

# In __init__ method, add:
+        self.use_mujoco = False  # or pass as parameter

344-345: Fix AttributeError: solver.use_mujoco attribute access.

The code references example.solver.use_mujoco but based on the MuJoCoSolver initialization on line 199, the use_mujoco parameter is passed to the constructor but may not be stored as an accessible attribute.

Since the solver is created with use_mujoco=False, you can either:

  1. Check if the MuJoCoSolver exposes this attribute
  2. Use the known value directly since it's hardcoded to False
-                if not example.solver.use_mujoco:
+                # Since use_mujoco is hardcoded to False in solver creation
+                if True:  # Always true since use_mujoco=False
🧹 Nitpick comments (1)
newton/examples/example_mujoco.py (1)

17-22: Update the header comment to reflect the generic nature of the script.

The comment describes this as "Example Sim G1" but the script actually supports multiple robot types (humanoid, g1, cartpole, quadruped). Update the comment to reflect its generic, unified nature.

-# Example Sim G1
+# Example MuJoCo Unified Script
#
-# Shows how to set up a simulation of a rigid-body humanoid articulation
-# from a xml using the newton.ModelBuilder().
-# Note this example does not include a trained policy.
+# Shows how to set up simulations for various articulated robots
+# (humanoid, g1, cartpole, quadruped) using newton.ModelBuilder().
+# Supports multiple robots to avoid code duplication and enable scaling.
📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6f21afc and 04bb039.

📒 Files selected for processing (1)
  • newton/examples/example_mujoco.py (1 hunks)
🧰 Additional context used
🪛 Ruff (0.11.9)
newton/examples/example_mujoco.py

102-102: Unused noqa directive (non-enabled: PLC0415)

Remove unused noqa directive

(RUF100)

⏰ 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-newton-tests / newton-unittests (windows-latest)
  • GitHub Check: run-newton-tests / newton-unittests (ubuntu-latest)
  • GitHub Check: run-asv-benchmarks
🔇 Additional comments (3)
newton/examples/example_mujoco.py (3)

35-69: Well-structured class initialization.

The constructor provides comprehensive configuration options with sensible defaults. The fixed seed ensures reproducible simulations, and the parameter organization is logical.


185-218: Model setup and solver initialization looks correct.

The multi-environment setup, solver configuration, and state initialization follow Newton best practices. The conditional renderer setup properly handles headless mode.


219-259: Simulation and rendering methods are well-implemented.

The CUDA graph setup properly checks device compatibility, the simulation loop correctly handles substeps with collision detection, and rendering is appropriately optional with contact visualization support.

Signed-off-by: Kenny Vilella <kvilella@nvidia.com>
Signed-off-by: Kenny Vilella <kvilella@nvidia.com>
@eric-heiden eric-heiden linked an issue Jul 14, 2025 that may be closed by this pull request
@eric-heiden eric-heiden requested a review from mmacklin July 14, 2025 03:38
@Kenny-Vilella Kenny-Vilella linked an issue Jul 14, 2025 that may be closed by this pull request

@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

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

360-361: Fix AttributeError: solver.use_mujoco attribute access.

The code references example.solver.use_mujoco but based on the MuJoCoSolver initialization on lines 199-208, the use_mujoco parameter is passed to the constructor, not stored as an attribute.

Either store the use_mujoco value in the Example class during initialization or check if the MuJoCoSolver exposes this attribute.

-                if not example.solver.use_mujoco:
+                if not example.use_mujoco:
🧹 Nitpick comments (2)
newton/examples/example_mujoco.py (2)

104-104: Remove unused noqa directive.

The noqa directive is unnecessary since the import error handling makes the PLC0415 rule irrelevant here.

-                import tqdm  # noqa: PLC0415
+                import tqdm

36-229: Consider refactoring the constructor for better maintainability.

The __init__ method is quite long (~194 lines) and handles multiple robot configurations. Consider extracting robot-specific setup into separate methods (e.g., _setup_humanoid(), _setup_g1(), etc.) to improve readability and maintainability.

This would also make it easier to add new robot types in the future and reduce the complexity of the main constructor.

📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 04bb039 and 2a5e77d.

📒 Files selected for processing (1)
  • newton/examples/example_mujoco.py (1 hunks)
🧰 Additional context used
🪛 Ruff (0.11.9)
newton/examples/example_mujoco.py

104-104: Unused noqa directive (non-enabled: PLC0415)

Remove unused noqa directive

(RUF100)

⏰ 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-asv-benchmarks
  • GitHub Check: run-newton-tests / newton-unittests (ubuntu-latest)
  • GitHub Check: run-newton-tests / newton-unittests (windows-latest)
🔇 Additional comments (5)
newton/examples/example_mujoco.py (5)

1-33: LGTM: Clean imports and setup.

The license header, imports, and initial configuration are well-structured and appropriate for this physics simulation example.


230-236: LGTM: Clean simulation stepping logic.

The simulation method correctly implements the physics stepping sequence with force clearing, collision detection, solver stepping, and state buffer swapping.


237-248: LGTM: Proper step implementation with CUDA graph support.

The method correctly handles both CUDA graph capture and direct simulation execution, with appropriate random actuation when specified.


249-259: LGTM: Clean rendering implementation.

The render method properly handles null renderer checks and implements the standard rendering sequence with optional contact visualization.


261-369: Well-structured main script with comprehensive CLI options.

The main script provides excellent configurability through command-line arguments and handles device setup properly. The simulation loop is clean and includes appropriate MuJoCo viewer integration when requested.

Signed-off-by: Kenny Vilella <kvilella@nvidia.com>
@Kenny-Vilella Kenny-Vilella temporarily deployed to external-pr-approval July 14, 2025 03:45 — with GitHub Actions Inactive

@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

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

367-367: Fix AttributeError: solver.use_mujoco attribute access.

Based on the MuJoCoSolver initialization, the use_mujoco parameter is passed to the constructor but not stored as an attribute. Use the value stored in the Example class instead.

-                if not example.solver.use_mujoco:
+                if not example.use_mujoco:
🧹 Nitpick comments (2)
newton/examples/example_mujoco.py (2)

111-111: Remove unused noqa directive.

The noqa: PLC0415 directive is not needed here as PLC0415 is not enabled in your linting configuration.

-                import tqdm  # noqa: PLC0415
+                import tqdm

93-188: Consider refactoring repetitive parameter initialization.

The parameter initialization code is repeated for each robot type with different default values. This could be simplified using a configuration dictionary to improve maintainability and reduce code duplication.

Define a configuration dictionary at the class level:

ROBOT_CONFIGS = {
    "humanoid": {
        "solver": "newton",
        "integrator": "euler", 
        "solver_iteration": 10,
        "ls_iteration": 5,
        "njmax": 100,
        "nconmax": 50,
    },
    "g1": {
        "solver": "newton",
        "integrator": "euler",
        "solver_iteration": 5,
        "ls_iteration": 5,
        "njmax": 300,
        "nconmax": 150,
    },
    # ... other robots
}

Then replace the repetitive code with:

-            # Setting mujoco_warp parameters
-            solver = solver if solver is not None else "newton"
-            integrator = integrator if integrator is not None else "euler"
-            solver_iteration = solver_iteration if solver_iteration is not None else 10
-            ls_iteration = ls_iteration if ls_iteration is not None else 5
-            njmax = njmax if njmax is not None else 100
-            nconmax = nconmax if nconmax is not None else 50
+            # Setting mujoco_warp parameters
+            config = self.ROBOT_CONFIGS[robot]
+            solver = solver if solver is not None else config["solver"]
+            integrator = integrator if integrator is not None else config["integrator"]
+            solver_iteration = solver_iteration if solver_iteration is not None else config["solver_iteration"]
+            ls_iteration = ls_iteration if ls_iteration is not None else config["ls_iteration"]
+            njmax = njmax if njmax is not None else config["njmax"]
+            nconmax = nconmax if nconmax is not None else config["nconmax"]
📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2a5e77d and a19905c.

📒 Files selected for processing (1)
  • newton/examples/example_mujoco.py (1 hunks)
🧰 Additional context used
🪛 Ruff (0.11.9)
newton/examples/example_mujoco.py

111-111: Unused noqa directive (non-enabled: PLC0415)

Remove unused noqa directive

(RUF100)

⏰ 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-newton-tests / newton-unittests (ubuntu-latest)
  • GitHub Check: run-newton-tests / newton-unittests (windows-latest)
  • GitHub Check: run-asv-benchmarks

@adenzler-nvidia adenzler-nvidia left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks - left some comments. High-level question for me is whether all the robot-specific config should be in some config file or a dict/list at the top of the file? Also to make it easier to configure a new robot?

Comment thread newton/examples/example_mujoco.py Outdated
Comment thread newton/examples/example_mujoco.py Outdated
Comment thread newton/examples/example_mujoco.py Outdated
Comment thread newton/examples/example_mujoco.py Outdated

@Kenny-Vilella Kenny-Vilella left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

For your high level questions, I actually though about it.
My impression is that with the current number of robots the current approach was more readable and that we should switch to your suggestion when increasing the number of robots.

But maybe I can just do it right now in order to not let the situation worsen.

Comment thread newton/examples/example_mujoco.py Outdated
Comment thread newton/examples/example_mujoco.py Outdated
Comment thread newton/examples/example_mujoco.py Outdated
Comment thread newton/examples/example_mujoco.py Outdated
Signed-off-by: Kenny Vilella <kvilella@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 (1)
newton/examples/example_mujoco.py (1)

97-97: Remove unused noqa directive.

The noqa directive is not needed since PLC0415 is not enabled in the linting configuration.

-        import tqdm  # noqa: PLC0415
+        import tqdm
📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a19905c and bb4ebe0.

📒 Files selected for processing (1)
  • newton/examples/example_mujoco.py (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: Kenny-Vilella
PR: newton-physics/newton#398
File: newton/examples/example_mujoco.py:352-352
Timestamp: 2025-07-14T03:57:29.659Z
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.
newton/examples/example_mujoco.py (1)
Learnt from: Kenny-Vilella
PR: newton-physics/newton#398
File: newton/examples/example_mujoco.py:352-352
Timestamp: 2025-07-14T03:57:29.659Z
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.
🪛 Ruff (0.11.9)
newton/examples/example_mujoco.py

97-97: Unused noqa directive (non-enabled: PLC0415)

Remove unused noqa directive

(RUF100)

⏰ 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-newton-tests / newton-unittests (ubuntu-latest)
  • GitHub Check: run-newton-tests / newton-unittests (windows-latest)
  • GitHub Check: run-asv-benchmarks
🔇 Additional comments (5)
newton/examples/example_mujoco.py (5)

42-67: Well-structured robot configuration dictionary.

The ROBOT_CONFIGS dictionary provides a clean, maintainable way to define robot-specific parameters. This aligns well with the PR objective of avoiding code duplication across robot examples.


70-155: Robot setup functions are well-implemented.

The individual robot setup functions (_setup_humanoid, _setup_g1, _setup_cartpole, _setup_quadruped) are well-structured and handle robot-specific initialization properly. The G1 setup includes mesh simplification which is a good performance optimization.


158-286: Example class provides comprehensive simulation functionality.

The Example class is well-designed with:

  • Proper initialization of simulation parameters
  • CUDA graph support for performance optimization
  • Flexible configuration options
  • Clean separation of concerns between simulation, stepping, and rendering

The implementation correctly handles the disabled use_mujoco and render_contact options as noted in the retrieved learnings.


347-352: Appropriate handling of unsupported options.

The code correctly disables the use_mujoco and render_contact options with clear warning messages, which aligns with the retrieved learnings about these features being unsupported and causing crashes.


289-397: Comprehensive command-line interface.

The argument parsing and main execution loop provide a flexible interface that supports:

  • Multiple robot types
  • Configurable simulation parameters
  • Optional rendering and MuJoCo viewer integration
  • CUDA graph optimization

This successfully achieves the PR objective of creating a unified script with extensive customization options while avoiding code duplication.

Signed-off-by: Kenny Vilella <kvilella@nvidia.com>
@Kenny-Vilella Kenny-Vilella temporarily deployed to external-pr-approval July 14, 2025 09:00 — with GitHub Actions Inactive

@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 (3)
newton/examples/example_mujoco.py (3)

96-96: Remove unused noqa directive.

The noqa directive for PLC0415 is unused and should be removed to keep the code clean.

-        import tqdm  # noqa: PLC0415
+        import tqdm

41-66: Consider increasing default solver iteration counts.

The current default solver iteration counts (e.g., 100 for humanoid) are relatively low. Based on the past review discussions, these could be set higher by default since conditional termination is available, and users ideally shouldn't need to worry about these details.

Consider increasing the default iteration counts across all robot configurations to ensure better convergence while maintaining the conditional termination safety net.


185-186: Consider making iteration defaults more explicit.

The solver and line search iteration defaults are set inline. Consider moving these to the robot configuration constants or making them named constants for better maintainability.

+DEFAULT_SOLVER_ITERATION = 100
+DEFAULT_LS_ITERATION = 50
+
# In __init__ method:
-        solver_iteration = solver_iteration if solver_iteration is not None else 100
-        ls_iteration = ls_iteration if ls_iteration is not None else 50
+        solver_iteration = solver_iteration if solver_iteration is not None else DEFAULT_SOLVER_ITERATION
+        ls_iteration = ls_iteration if ls_iteration is not None else DEFAULT_LS_ITERATION
📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bb4ebe0 and 850b541.

📒 Files selected for processing (1)
  • newton/examples/example_mujoco.py (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: Kenny-Vilella
PR: newton-physics/newton#398
File: newton/examples/example_mujoco.py:352-352
Timestamp: 2025-07-14T03:57:29.659Z
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.
newton/examples/example_mujoco.py (1)
Learnt from: Kenny-Vilella
PR: newton-physics/newton#398
File: newton/examples/example_mujoco.py:352-352
Timestamp: 2025-07-14T03:57:29.659Z
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.
🪛 Ruff (0.11.9)
newton/examples/example_mujoco.py

96-96: Unused noqa directive (non-enabled: PLC0415)

Remove unused noqa directive

(RUF100)

⏰ 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-asv-benchmarks
  • GitHub Check: run-newton-tests / newton-unittests (windows-latest)
  • GitHub Check: run-newton-tests / newton-unittests (ubuntu-latest)
🔇 Additional comments (4)
newton/examples/example_mujoco.py (4)

334-336: LGTM: Proper handling of unsupported use_mujoco option.

The code correctly disables the unsupported use_mujoco option with a clear warning message. This is a good approach to prevent crashes while keeping the option available for future implementation.


248-250: Good CUDA graph compatibility check.

The code properly validates CUDA graph compatibility by checking both CUDA device availability and mempool support, with appropriate fallback messaging.


358-373: Robust MuJoCo viewer integration.

The MuJoCo viewer integration properly handles the conditional viewer launch and synchronization, with appropriate checks for the solver state.


205-205: Excellent error handling for unrecognized robots.

The code properly raises a ValueError with a descriptive message for unrecognized robot names, which is much better than the previous print/return pattern.

Comment thread newton/examples/example_mujoco.py
@eric-heiden

Copy link
Copy Markdown
Member

I think it would be better to turn this example into unit tests. These hard coded settings will be difficult to keep updated in the future otherwise. The examples are really just meant to show how one can set up an asset and simulate it in Newton, as a tutorial. Having this boilerplate code around it makes it really complicated.

@Kenny-Vilella

Copy link
Copy Markdown
Member Author

@eric-heiden The main reason of this PR is for benchmarking. So maybe this script is not at the correct place, or with the correct name, but we still need something equivalent to that.

@eric-heiden

Copy link
Copy Markdown
Member

@eric-heiden The main reason of this PR is for benchmarking. So maybe this script is not at the correct place, or with the correct name, but we still need something equivalent to that.

Does it makes sense then to turn this into a benchmark script? Maybe those could benefit from more code reuse? Although we have some of these models already in the benchmarks. What might be more useful is if the assets came from USD files so we make sure they run properly and fast.

@eric-heiden eric-heiden merged commit 4e44c45 into newton-physics:main Jul 18, 2025
10 checks passed
@Kenny-Vilella Kenny-Vilella deleted the dev/kvilella/add_unified_script_run_example branch July 21, 2025 06:12
This was referenced Aug 20, 2025
@coderabbitai coderabbitai Bot mentioned this pull request Oct 20, 2025
4 tasks
eric-heiden added a commit to eric-heiden/newton that referenced this pull request Jan 28, 2026
Signed-off-by: Kenny Vilella <kvilella@nvidia.com>
Co-authored-by: Eric Heiden <eheiden@nvidia.com>
vidurv-nvidia pushed a commit to vidurv-nvidia/newton that referenced this pull request Mar 6, 2026
# Description

This change enables the Fabric Scene Delegate (FSD), which should help
speed up workflows requiring rendering as it optimizes the
transformation updates for rendering.

Fixes # (issue)

<!-- As a practice, it is recommended to open an issue to have
discussions on the proposed pull request.
This makes it easier for the community to keep track of what is being
developed or added, and if a given feature
is demanded by more than one party. -->

## Type of change

<!-- As you go through the list, delete the ones that are not
applicable. -->

- New feature (non-breaking change which adds functionality)
- Breaking change (fix or feature that would cause existing
functionality to not work as expected)

## Checklist

- [ ] I have run the [`pre-commit` checks](https://pre-commit.com/) with
`./isaaclab.sh --format`
- [ ] I have made corresponding changes to the documentation
- [ ] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] I have updated the changelog and the corresponding version in the
extension's `config/extension.toml` file
- [ ] I have added my name to the `CONTRIBUTORS.md` or my name already
exists there

<!--
As you go through the checklist above, you can mark something as done by
putting an x character in it

For example,
- [x] I have done this task
- [ ] I have not done this task
-->

---------

Co-authored-by: Kelly Guo <kellyg@nvidia.com>
mmacklin pushed a commit to mmacklin/newton that referenced this pull request Apr 7, 2026
Signed-off-by: Kenny Vilella <kvilella@nvidia.com>
Co-authored-by: Eric Heiden <eheiden@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.

Consider a common abstraction layer for examples Create benchmarking scripts in Newton for KPI

3 participants