Skip to content

Add support for the --help argument in the examples#731

Merged
nvtw merged 6 commits into
newton-physics:mainfrom
nvtw:dev/tw/make_examples_support_help_arg_668
Sep 9, 2025
Merged

Add support for the --help argument in the examples#731
nvtw merged 6 commits into
newton-physics:mainfrom
nvtw:dev/tw/make_examples_support_help_arg_668

Conversation

@nvtw

@nvtw nvtw commented Sep 4, 2025

Copy link
Copy Markdown
Member

Description

Implements #668

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

    • Examples now expose -h/--help with descriptive usage text.
    • Examples use a consistent parser-driven startup so CLI options are applied uniformly.
  • Bug Fixes

    • CLI now properly handles --help and raises errors for unknown options instead of ignoring them.
  • Documentation

    • Parser usage and help text clarified and expanded in docs.

@coderabbitai

coderabbitai Bot commented Sep 4, 2025

Copy link
Copy Markdown
Contributor

Warning

Rate limit exceeded

@nvtw has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 12 minutes and 5 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 2dcd37f and 30fcb18.

📒 Files selected for processing (6)
  • newton/examples/__init__.py (2 hunks)
  • newton/examples/ik/example_ik_franka.py (1 hunks)
  • newton/examples/ik/example_ik_h1.py (1 hunks)
  • newton/examples/robot/example_robot_anymal_c_walk.py (1 hunks)
  • newton/examples/selection/example_selection_articulations.py (0 hunks)
  • newton/examples/selection/example_selection_materials.py (0 hunks)
📝 Walkthrough

Walkthrough

create_parser now accepts add_help and init accepts an external parser; when an external parser is provided init uses parser.parse_args(), otherwise it falls back to create_parser()+parse_known_args(). Many example scripts now build a parser with add_help=True, set descriptions, and pass it into init; one example calls run() after init.

Changes

Cohort / File(s) Summary
Core examples API
newton/examples/__init__.py
create_parser(add_help=False) added and forwarded to argparse.ArgumentParser(add_help=...). init updated to accept an external parser and to call parser.parse_args() when provided; otherwise it uses create_parser() + parse_known_args(). Docstring expanded.
Examples updated to parser-driven init
newton/examples/basic/* , newton/examples/cloth/(bending,style3d), newton/examples/ik/(franka,h1), newton/examples/robot/example_robot_anymal_c_walk.py, newton/examples/robot/*(some)
In __main__: create parser via newton.examples.create_parser(add_help=True), set parser.description and call newton.examples.init(parser) (replacing no-arg init() calls).
Examples enabling help flag only
newton/examples/basic/example_basic_urdf.py, newton/examples/basic/example_basic_shapes.py, newton/examples/basic/example_basic_joints.py, newton/examples/basic/example_basic_viewer.py, newton/examples/cloth/(franka,hanging,twist), newton/examples/diffsim/(ball,cloth,drone,soft_body,spring_cage), newton/examples/mpm/(anymal,granular), newton/examples/robot/(anymal_d,cartpole,g1,h1,humanoid,policy,ur10), newton/examples/selection/*(articulations,cartpole,materials)
Replace create_parser() calls with create_parser(add_help=True) in __main__; no other runtime changes. (mpm/example_mpm_anymal.py updated two call sites.)
Example adding explicit run step
newton/examples/basic/example_basic_pendulum.py
__main__ now creates parser with add_help=True, calls init(parser), and invokes newton.examples.run(example).
Tests
newton/tests/test_examples.py
_build_command_line_options: changed a second if to elif for list-handling so the list branch is mutually exclusive with the boolean branch.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    actor User
    participant Script as Example Script
    participant Examples as newton.examples
    participant Argparse as argparse
    participant Viewer as Viewer/Env

    User->>Script: run with CLI args
    Script->>Examples: create_parser(add_help=True)
    Examples->>Argparse: ArgumentParser(add_help=True)
    Argparse-->>Examples: parser
    Script->>Examples: init(parser)
    alt external parser provided
        Examples->>Argparse: parser.parse_args()
        Argparse-->>Examples: args (strict)
    else no external parser
        Examples->>Examples: create_parser()
        Examples->>Argparse: parser.parse_known_args()
        Argparse-->>Examples: args + unknown
    end
    Examples->>Viewer: initialize with args
    Viewer-->>Script: viewer, args
    Script->>Viewer: run example loop (optional explicit run)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • shi-eric
  • mmacklin
✨ 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.

@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

Caution

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

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

296-301: Fix Torch device selection API and guard against None.

torch.set_device is not a public API; use torch.cuda.set_device when a CUDA device is requested, and skip otherwise to avoid exceptions when --device is unset or CPU.

 if USE_TORCH:
-    import torch
-
-    torch.set_device(args.device)
+    import torch
+    if getattr(args, "device", None):
+        if str(args.device).startswith("cuda"):
+            import torch.cuda
+            torch.cuda.set_device(torch.device(args.device))
+        # else: CPU or other backends; no-op here to avoid surprising global defaults
🧹 Nitpick comments (28)
newton/examples/__init__.py (2)

104-117: Good: add_help surfaced to callers

Passing add_help through fixes --help in examples. Minor nit: tighten the docstring and inline comment to reflect the parameterized behavior.

Apply:

-def create_parser(add_help=False):
-    """Create a base argument parser with common parameters for Newton examples.
+def create_parser(add_help: bool = False):
+    """Create a base argparse parser with common parameters for Newton examples.
@@
-    Individual examples can use this as a parent parser and add their own
-    specific arguments.
+    Individual examples can use this as a parent parser and add their own specific arguments.
+
+    Args:
+        add_help: If True, enable -h/--help on the returned parser. Keep False when using this
+            as a parent parser to avoid duplicate help.
@@
-        argparse.ArgumentParser: Base parser with common arguments
+        argparse.ArgumentParser: Base parser with common arguments.
     """
@@
-    # add_help=False since this is a parent parser
-    parser = argparse.ArgumentParser(add_help=add_help, formatter_class=argparse.ArgumentDefaultsHelpFormatter)
+    # Pass through add_help so examples can opt-in to -h/--help
+    parser = argparse.ArgumentParser(add_help=add_help, formatter_class=argparse.ArgumentDefaultsHelpFormatter)

139-151: Docstring param type is incorrect

init(parser=None) takes an ArgumentParser, not “Parsed arguments”. Update docstring to avoid confusion.

-    Args:
-        parser: Parsed arguments from argparse (should include arguments from
-              create_parser())
+    Args:
+        parser: An argparse.ArgumentParser configured with create_parser(), or None.
newton/examples/cloth/example_cloth_hanging.py (1)

197-197: LGTM: help enabled for this example

Consider adding a short description so -h output is more informative.

-    parser = newton.examples.create_parser(add_help=True)
+    parser = newton.examples.create_parser(add_help=True)
+    parser.description = "Simulate a hanging cloth under gravity with multiple solver backends."
newton/examples/robot/example_robot_ur10.py (1)

211-211: LGTM: help enabled

Optional: set a description to improve --help UX.

-    parser = newton.examples.create_parser(add_help=True)
+    parser = newton.examples.create_parser(add_help=True)
+    parser.description = "UR10 robot demo with sinusoidal joint targets replicated across environments."
newton/examples/diffsim/example_diffsim_spring_cage.py (1)

243-243: LGTM: help enabled

Optional: add a concise description for the help screen.

-    parser = newton.examples.create_parser(add_help=True)
+    parser = newton.examples.create_parser(add_help=True)
+    parser.description = "Optimize spring rest lengths to pull a particle towards a target (diffsim)."
newton/examples/ik/example_ik_benchmark.py (1)

366-379: LGTM: help enabled; sensible default viewer

Nice touch setting viewer="null" for a non-visual benchmark. Optionally add a brief description.

-    parser = newton.examples.create_parser(add_help=True)
+    parser = newton.examples.create_parser(add_help=True)
+    parser.description = "Benchmark Newton IK on Franka across varying batch sizes and report timing/accuracy."
newton/examples/robot/example_robot_policy.py (1)

410-421: Improve help UX: set description/epilog.

Add a short description and a usage example so --help is more informative.

-    parser = newton.examples.create_parser(add_help=True)
+    parser = newton.examples.create_parser(add_help=True)
+    parser.description = ("Control a pretrained robot policy via keyboard "
+                          "(space=start, p=reset, i/j/k/l/u/o=motion).")
+    parser.epilog = "Example: python -m newton.examples robot_policy --robot go2 --viewer gl"
newton/examples/mpm/example_mpm_granular.py (1)

158-166: Clarify help output with description/epilog.

Make --help output self-explanatory.

-    parser = newton.examples.create_parser(add_help=True)
+    parser = newton.examples.create_parser(add_help=True)
+    parser.description = "Implicit MPM granular demo with optional collider and emission bounds."
+    parser.epilog = "Example: python -m newton.examples mpm_granular --collider cube --viewer gl"
newton/examples/basic/example_basic_urdf.py (1)

136-144: Add description/epilog for clearer --help.

-    parser = newton.examples.create_parser(add_help=True)
+    parser = newton.examples.create_parser(add_help=True)
+    parser.description = "Basic URDF quadruped demo (no trained policy)."
+    parser.epilog = "Example: python -m newton.examples basic_urdf --num-envs 16"
newton/examples/mpm/example_mpm_anymal.py (1)

385-397: Enhance help text.

-    parser = newton.examples.create_parser(add_help=True)
+    parser = newton.examples.create_parser(add_help=True)
+    parser.description = "Anymal C robot walking on implicit MPM sand with a pretrained policy."
+    parser.epilog = "Example: python -m newton.examples mpm_anymal --viewer gl"
newton/examples/robot/example_robot_g1.py (1)

135-141: Polish --help output with description/epilog.

-    parser = newton.examples.create_parser(add_help=True)
+    parser = newton.examples.create_parser(add_help=True)
+    parser.description = "Unitree G1 from USD; replicates multiple environments."
+    parser.epilog = "Example: python -m newton.examples robot_g1 --num-envs 16"
newton/examples/cloth/example_cloth_twist.py (1)

296-301: Optional: surface a concise description in -h output

Add a description so help shows what this example does.

-    parser = newton.examples.create_parser(add_help=True)
+    parser = newton.examples.create_parser(add_help=True)
+    parser.description = "Twist an FEM cloth model with VBD self-contact; intersection-free cloth twisting demo."
newton/examples/selection/example_selection_materials.py (2)

260-271: Avoid double argument parsing; let init(parser) own it

parse_known_args() is redundant and can cause duplicated parsing/early exit on -h. Drop it and rely on init(parser).

-    args = parser.parse_known_args()[0]
-
-    viewer, args = newton.examples.init(parser)
+    viewer, args = newton.examples.init(parser)

260-267: Optional: add a description for clearer --help output

Briefly describe the example for users scanning help.

-    parser = newton.examples.create_parser(add_help=True)
+    parser = newton.examples.create_parser(add_help=True)
+    parser.description = "Batch material edits via Selection API: ants with randomized friction, toggling direction."
newton/examples/robot/example_robot_cartpole.py (1)

117-121: Optional: add a help description

Improves discoverability in CLI help.

-    parser = newton.examples.create_parser(add_help=True)
+    parser = newton.examples.create_parser(add_help=True)
+    parser.description = "USD-based cartpole replication; rigid-body control with MuJoCo solver."
newton/examples/diffsim/example_diffsim_cloth.py (1)

217-221: Optional: set parser.description

Shows the optimization objective in -h output.

-    parser = newton.examples.create_parser(add_help=True)
+    parser = newton.examples.create_parser(add_help=True)
+    parser.description = "Differentiable cloth: optimize initial velocities so COM hits a target."
newton/examples/cloth/example_cloth_franka.py (1)

559-563: Optional: add a CLI description

Helps users quickly identify the demo from -h.

-    parser = newton.examples.create_parser(add_help=True)
+    parser = newton.examples.create_parser(add_help=True)
+    parser.description = "Franka + cloth manipulation: hybrid Featherstone/VBD with cloth self-contact."
newton/examples/diffsim/example_diffsim_soft_body.py (1)

361-361: Good: help enabled; consider adding a description for consistent -h output.

Passing add_help=True is correct. For consistency with other examples, set parser.description so --help shows a useful summary.

 parser = newton.examples.create_parser(add_help=True)
+parser.description = "Optimize soft-body material parameters via differentiable simulation."
newton/examples/selection/example_selection_articulations.py (1)

292-295: Remove redundant pre-parse; let init(parser) own parsing.

parser.parse_known_args() is unnecessary and can confuse future readers since init(parser) re-parses with parse_args() (and handles --help). Remove it.

-args = parser.parse_known_args()[0]
-
 viewer, args = newton.examples.init(parser)
newton/examples/diffsim/example_diffsim_ball.py (1)

248-253: Add a parser.description for consistent help output

Include a description on the parser in this example for uniform help messages:

 parser = newton.examples.create_parser(add_help=True)
+parser.description = "Optimize initial particle velocity via differentiable simulation to hit a target."

Static checks confirm all examples already call create_parser(add_help=True) and pass the parser into init().

newton/examples/basic/example_basic_joints.py (1)

210-210: Avoid unused variable: rename args to underscore

args isn’t used; keep linters quiet by discarding it.

-    viewer, args = newton.examples.init(parser)
+    viewer, _ = newton.examples.init(parser)
newton/examples/basic/example_basic_shapes.py (2)

151-151: Drop unused args binding

args isn’t referenced; prefer underscore.

-    viewer, args = newton.examples.init(parser)
+    viewer, _ = newton.examples.init(parser)

144-148: Doc/test follow-up for migration item

Since the PR description mentions updating docs/migration.rst and tests for examples, confirm those land before merge; I can draft a minimal pytest that asserts each example’s --help exits with code 0.

newton/examples/robot/example_robot_anymal_c_walk.py (1)

237-238: Rename unused args

Minor lint fix.

-    viewer, args = newton.examples.init(parser)
+    viewer, _ = newton.examples.init(parser)
newton/examples/ik/example_ik_franka.py (1)

178-179: Ignore unused args

Keep it tidy.

-    viewer, args = newton.examples.init(parser)
+    viewer, _ = newton.examples.init(parser)
newton/examples/basic/example_basic_pendulum.py (1)

139-139: Use underscore for unused args

-    viewer, args = newton.examples.init(parser)
+    viewer, _ = newton.examples.init(parser)
newton/examples/ik/example_ik_h1.py (1)

190-196: Polish: show the recommended invocation in help usage.

Set parser.prog so the Usage line reflects python -m newton.examples ik_h1 instead of the script path.

Apply this diff:

 parser = newton.examples.create_parser(add_help=True)
 parser.description = "Demonstrates inverse kinematics for H1 humanoid robot using Newton physics."
+parser.prog = "python -m newton.examples ik_h1"
newton/examples/basic/example_basic_viewer.py (1)

192-196: Nit: clarify help usage with the module entrypoint.

Explicitly set parser.prog to the documented command to make the Usage line friendlier.

Apply this diff:

 parser = newton.examples.create_parser(add_help=True)
 parser.description = (
     "Shows how to use different viewer types (GL, USD, Rerun, Null) with Newton physics simulation."
 )
+parser.prog = "python -m newton.examples basic_viewer"
 
-viewer, args = newton.examples.init(parser)
+viewer, args = newton.examples.init(parser)

Also applies to: 199-199

📜 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 0e8ee91 and df1a7bc.

📒 Files selected for processing (32)
  • newton/examples/__init__.py (3 hunks)
  • newton/examples/basic/example_basic_joints.py (1 hunks)
  • newton/examples/basic/example_basic_pendulum.py (1 hunks)
  • newton/examples/basic/example_basic_shapes.py (1 hunks)
  • newton/examples/basic/example_basic_urdf.py (1 hunks)
  • newton/examples/basic/example_basic_viewer.py (1 hunks)
  • newton/examples/cloth/example_cloth_bending.py (1 hunks)
  • newton/examples/cloth/example_cloth_franka.py (1 hunks)
  • newton/examples/cloth/example_cloth_hanging.py (1 hunks)
  • newton/examples/cloth/example_cloth_style3d.py (1 hunks)
  • newton/examples/cloth/example_cloth_twist.py (1 hunks)
  • newton/examples/diffsim/example_diffsim_ball.py (1 hunks)
  • newton/examples/diffsim/example_diffsim_cloth.py (1 hunks)
  • newton/examples/diffsim/example_diffsim_drone.py (1 hunks)
  • newton/examples/diffsim/example_diffsim_soft_body.py (1 hunks)
  • newton/examples/diffsim/example_diffsim_spring_cage.py (1 hunks)
  • newton/examples/ik/example_ik_benchmark.py (1 hunks)
  • newton/examples/ik/example_ik_franka.py (1 hunks)
  • newton/examples/ik/example_ik_h1.py (1 hunks)
  • newton/examples/mpm/example_mpm_anymal.py (1 hunks)
  • newton/examples/mpm/example_mpm_granular.py (1 hunks)
  • newton/examples/robot/example_robot_anymal_c_walk.py (1 hunks)
  • newton/examples/robot/example_robot_anymal_d.py (1 hunks)
  • newton/examples/robot/example_robot_cartpole.py (1 hunks)
  • newton/examples/robot/example_robot_g1.py (1 hunks)
  • newton/examples/robot/example_robot_h1.py (1 hunks)
  • newton/examples/robot/example_robot_humanoid.py (1 hunks)
  • newton/examples/robot/example_robot_policy.py (1 hunks)
  • newton/examples/robot/example_robot_ur10.py (1 hunks)
  • newton/examples/selection/example_selection_articulations.py (1 hunks)
  • newton/examples/selection/example_selection_cartpole.py (1 hunks)
  • newton/examples/selection/example_selection_materials.py (1 hunks)
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: dylanturpin
PR: newton-physics/newton#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.
📚 Learning: 2025-08-25T21:41:45.795Z
Learnt from: dylanturpin
PR: newton-physics/newton#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/cloth/example_cloth_hanging.py
  • newton/examples/mpm/example_mpm_granular.py
  • newton/examples/robot/example_robot_ur10.py
  • newton/examples/robot/example_robot_policy.py
  • newton/examples/robot/example_robot_anymal_d.py
  • newton/examples/robot/example_robot_cartpole.py
  • newton/examples/cloth/example_cloth_twist.py
  • newton/examples/basic/example_basic_urdf.py
  • newton/examples/diffsim/example_diffsim_spring_cage.py
  • newton/examples/basic/example_basic_joints.py
  • newton/examples/robot/example_robot_humanoid.py
  • newton/examples/__init__.py
  • newton/examples/diffsim/example_diffsim_drone.py
  • newton/examples/basic/example_basic_shapes.py
  • newton/examples/basic/example_basic_pendulum.py
  • newton/examples/diffsim/example_diffsim_cloth.py
  • newton/examples/robot/example_robot_anymal_c_walk.py
  • newton/examples/diffsim/example_diffsim_ball.py
  • newton/examples/ik/example_ik_h1.py
  • newton/examples/cloth/example_cloth_bending.py
  • newton/examples/ik/example_ik_benchmark.py
  • newton/examples/diffsim/example_diffsim_soft_body.py
  • newton/examples/robot/example_robot_h1.py
  • newton/examples/robot/example_robot_g1.py
  • newton/examples/mpm/example_mpm_anymal.py
  • newton/examples/selection/example_selection_cartpole.py
  • newton/examples/cloth/example_cloth_franka.py
  • newton/examples/selection/example_selection_articulations.py
  • newton/examples/selection/example_selection_materials.py
  • newton/examples/cloth/example_cloth_style3d.py
  • newton/examples/basic/example_basic_viewer.py
  • newton/examples/ik/example_ik_franka.py
📚 Learning: 2025-08-27T19:05:44.697Z
Learnt from: Milad-Rakhsha-NV
PR: newton-physics/newton#535
File: newton/tests/test_examples.py:320-414
Timestamp: 2025-08-27T19:05:44.697Z
Learning: In newton/examples/__init__.py, the robot policy example is registered with the key "robot_policy" (not "robot.example_robot_policy"), so tests should reference it as name="robot_policy".

Applied to files:

  • newton/examples/robot/example_robot_policy.py
🧬 Code graph analysis (31)
newton/examples/cloth/example_cloth_hanging.py (1)
newton/examples/__init__.py (1)
  • create_parser (104-136)
newton/examples/mpm/example_mpm_granular.py (1)
newton/examples/__init__.py (1)
  • create_parser (104-136)
newton/examples/robot/example_robot_ur10.py (1)
newton/examples/__init__.py (1)
  • create_parser (104-136)
newton/examples/robot/example_robot_policy.py (1)
newton/examples/__init__.py (1)
  • create_parser (104-136)
newton/examples/robot/example_robot_anymal_d.py (1)
newton/examples/__init__.py (1)
  • create_parser (104-136)
newton/examples/robot/example_robot_cartpole.py (1)
newton/examples/__init__.py (1)
  • create_parser (104-136)
newton/examples/cloth/example_cloth_twist.py (1)
newton/examples/__init__.py (1)
  • create_parser (104-136)
newton/examples/basic/example_basic_urdf.py (1)
newton/examples/__init__.py (1)
  • create_parser (104-136)
newton/examples/diffsim/example_diffsim_spring_cage.py (1)
newton/examples/__init__.py (1)
  • create_parser (104-136)
newton/examples/basic/example_basic_joints.py (1)
newton/examples/__init__.py (2)
  • create_parser (104-136)
  • init (139-182)
newton/examples/robot/example_robot_humanoid.py (1)
newton/examples/__init__.py (1)
  • create_parser (104-136)
newton/examples/diffsim/example_diffsim_drone.py (1)
newton/examples/__init__.py (1)
  • create_parser (104-136)
newton/examples/basic/example_basic_shapes.py (1)
newton/examples/__init__.py (2)
  • create_parser (104-136)
  • init (139-182)
newton/examples/basic/example_basic_pendulum.py (1)
newton/examples/__init__.py (2)
  • create_parser (104-136)
  • init (139-182)
newton/examples/diffsim/example_diffsim_cloth.py (1)
newton/examples/__init__.py (1)
  • create_parser (104-136)
newton/examples/robot/example_robot_anymal_c_walk.py (1)
newton/examples/__init__.py (2)
  • create_parser (104-136)
  • init (139-182)
newton/examples/diffsim/example_diffsim_ball.py (1)
newton/examples/__init__.py (1)
  • create_parser (104-136)
newton/examples/ik/example_ik_h1.py (1)
newton/examples/__init__.py (2)
  • create_parser (104-136)
  • init (139-182)
newton/examples/cloth/example_cloth_bending.py (1)
newton/examples/__init__.py (2)
  • create_parser (104-136)
  • init (139-182)
newton/examples/ik/example_ik_benchmark.py (1)
newton/examples/__init__.py (1)
  • create_parser (104-136)
newton/examples/diffsim/example_diffsim_soft_body.py (1)
newton/examples/__init__.py (1)
  • create_parser (104-136)
newton/examples/robot/example_robot_h1.py (1)
newton/examples/__init__.py (1)
  • create_parser (104-136)
newton/examples/robot/example_robot_g1.py (1)
newton/examples/__init__.py (1)
  • create_parser (104-136)
newton/examples/mpm/example_mpm_anymal.py (1)
newton/examples/__init__.py (1)
  • create_parser (104-136)
newton/examples/selection/example_selection_cartpole.py (1)
newton/examples/__init__.py (1)
  • create_parser (104-136)
newton/examples/cloth/example_cloth_franka.py (1)
newton/examples/__init__.py (1)
  • create_parser (104-136)
newton/examples/selection/example_selection_articulations.py (1)
newton/examples/__init__.py (1)
  • create_parser (104-136)
newton/examples/selection/example_selection_materials.py (1)
newton/examples/__init__.py (1)
  • create_parser (104-136)
newton/examples/cloth/example_cloth_style3d.py (1)
newton/examples/__init__.py (2)
  • create_parser (104-136)
  • init (139-182)
newton/examples/basic/example_basic_viewer.py (1)
newton/examples/__init__.py (2)
  • create_parser (104-136)
  • init (139-182)
newton/examples/ik/example_ik_franka.py (1)
newton/examples/__init__.py (2)
  • create_parser (104-136)
  • init (139-182)
⏰ 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 (ubuntu-latest)
  • GitHub Check: run-newton-tests / newton-unittests (windows-latest)
🔇 Additional comments (29)
newton/examples/__init__.py (1)

159-163: All examples pass a parser into init; no flags will be dropped.

newton/examples/robot/example_robot_policy.py (2)

413-413: Enable --help: Good change.

Passing add_help=True correctly exposes -h/--help for this example.


410-421: No remaining create_parser calls missing add_help=True – grep search across newton/examples found no instances of create_parser without add_help=True.

newton/examples/mpm/example_mpm_granular.py (1)

162-162: Enable --help: Good change.

This aligns with the centralized CLI.

newton/examples/basic/example_basic_urdf.py (1)

139-139: Enable --help: Good change.

Consistent with the examples’ parser pattern.

newton/examples/mpm/example_mpm_anymal.py (1)

389-389: Enable --help: Good change.

Matches the add_help-enabled parser API.

newton/examples/robot/example_robot_g1.py (1)

136-136: Enable --help: Good change.

Keeps CLI consistent across examples.

newton/examples/robot/example_robot_h1.py (1)

129-136: Enable --help: LGTM

Using create_parser(add_help=True) is correct and consistent with the centralized parser API.

newton/examples/robot/example_robot_anymal_d.py (1)

141-149: Enable --help: LGTM

add_help=True correctly exposes -h/--help for this example.

newton/examples/robot/example_robot_humanoid.py (1)

120-128: Enable --help: LGTM

Matches the updated create_parser(add_help=False) signature and usage pattern.

newton/examples/diffsim/example_diffsim_drone.py (1)

794-822: Enable --help: LGTM

Help is now available; no further changes needed here.

newton/examples/selection/example_selection_cartpole.py (1)

183-203: Remove redundant manual parse call
Drop the args = parser.parse_known_args()[0] line—newton.examples.init(parser) already performs argument parsing (including help), avoiding a double-parse and hidden flags.

newton/examples/cloth/example_cloth_twist.py (1)

296-301: Enabling --help via add_help=True looks good

Matches the new create_parser(add_help=...) API and keeps per-example defaults via set_defaults.

newton/examples/robot/example_robot_cartpole.py (1)

117-123: Good switch to add_help=True

Enables -h/--help without altering runtime behavior.

newton/examples/diffsim/example_diffsim_cloth.py (1)

217-223: add_help=True adoption LGTM

Consistent with the new parser API; custom --verbose flag integrates cleanly.

newton/examples/cloth/example_cloth_franka.py (1)

559-566: add_help=True change looks correct

Keeps example-specific defaults via set_defaults(num_frames=3850).

newton/examples/selection/example_selection_articulations.py (1)

289-291: LGTM: --help wired correctly.

Creating the parser with add_help=True aligns with the new init flow.

newton/examples/cloth/example_cloth_style3d.py (2)

185-187: Nice: descriptive help text.

Setting add_help=True and parser.description improves UX.


189-190: LGTM: delegate parsing to init(parser).

This ensures -h/--help exits as expected.

newton/examples/cloth/example_cloth_bending.py (2)

135-137: Good: help enabled with summary.

Consistent with other examples; no issues.


139-140: LGTM: central parsing via init(parser).

Correctly switches to the new init contract.

newton/examples/diffsim/example_diffsim_ball.py (1)

248-248: LGTM: help wired in.

add_help=True is correct, and you pass the parser to init(parser).

newton/examples/basic/example_basic_joints.py (1)

205-208: Add --help wiring via external parser: LGTM

Using create_parser(add_help=True), setting description, and passing the parser into init() correctly enables argparse’s built-in help behavior for direct script runs.

newton/examples/basic/example_basic_shapes.py (1)

144-148: Help-enabled CLI in main: looks good

Description is concise and will show up in -h output. Good use of the shared parser.

newton/examples/robot/example_robot_anymal_c_walk.py (1)

233-236: CLI help support change is correct

Parser with add_help=True and description wired before init(parser) is consistent with the shared CLI contract.

newton/examples/ik/example_ik_franka.py (1)

174-177: Help flow LGTM

External parser + description before init(parser) correctly enables --help for direct execution.

newton/examples/basic/example_basic_pendulum.py (1)

134-137: Good: standardized help-enabled parser usage

Matches the new pattern; description is clear.

newton/examples/ik/example_ik_h1.py (1)

190-196: Good adoption of centralized parser with --help support.

Using create_parser(add_help=True) and passing it into init(parser) correctly enables --help and aligns with the examples’ centralized CLI.

newton/examples/basic/example_basic_viewer.py (1)

192-196: Nice, consistent --help plumbing via centralized parser.

This mirrors the new create_parser(...)/init(parser) flow and will print coherent help for viewer options.

Also applies to: 199-199

Comment thread newton/examples/basic/example_basic_joints.py Outdated
Comment thread newton/examples/cloth/example_cloth_franka.py Outdated
@nvtw nvtw requested a review from shi-eric September 4, 2025 08:42
@nvtw nvtw self-assigned this Sep 4, 2025

@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/tests/test_examples.py (1)

56-57: OK to make list handling mutually exclusive; consider tuple support and empty-list guard

Semantics are unchanged, but broadening to tuples and skipping empty sequences avoids emitting a bare --key when [] is passed.

-        elif isinstance(value, list):
-            additional_options.extend([f"--{key.replace('_', '-')}"] + [str(v) for v in value])
+        elif isinstance(value, (list, tuple)):
+            if value:  # avoid emitting a bare flag when the sequence is empty
+                additional_options.extend([f"--{key.replace('_', '-')}"] + [str(v) for v in value])
📜 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 df1a7bc and 9729d45.

📒 Files selected for processing (1)
  • newton/tests/test_examples.py (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: dylanturpin
PR: newton-physics/newton#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.
⏰ 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)

@eric-heiden eric-heiden linked an issue Sep 4, 2025 that may be closed by this pull request
Comment thread newton/examples/basic/example_basic_pendulum.py Outdated
@shi-eric shi-eric requested a review from mmacklin September 6, 2025 05:36

@mmacklin mmacklin 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.

Approved with comment to make add_help=True the default or remove (even better).

@nvtw nvtw enabled auto-merge (squash) September 9, 2025 07:13
@nvtw nvtw disabled auto-merge September 9, 2025 07:13
@nvtw nvtw enabled auto-merge (squash) September 9, 2025 07:51
@nvtw nvtw merged commit d5e94df into newton-physics:main Sep 9, 2025
12 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request Oct 2, 2025
4 tasks
eric-heiden pushed a commit to eric-heiden/newton that referenced this pull request Jan 28, 2026
mmacklin pushed a commit to mmacklin/newton that referenced this pull request Apr 7, 2026
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.

New examples do not respect --help

3 participants