Add --warp-config KEY=VALUE CLI option to examples#2271
Add --warp-config KEY=VALUE CLI option to examples#2271eric-heiden merged 1 commit intonewton-physics:mainfrom
Conversation
📝 WalkthroughWalkthroughAdds a repeatable Changes
Sequence Diagram(s)sequenceDiagram
participant CLI as User (CLI)
participant Parser as create_parser()/argparse
participant Apply as _apply_warp_config
participant Config as warp.config
participant Init as init()
CLI->>Parser: invoke example with --warp-config KEY=VALUE...
Parser->>Parser: parse args (collect warp_config list)
Parser-->>Apply: init() calls _apply_warp_config(parser, args)
Apply->>Apply: for each entry: ensure "KEY=VALUE", validate key exists
Apply->>Apply: parse VALUE via ast.literal_eval (fallback to string)
Apply->>Config: setattr(warp.config, KEY, parsed_value)
Apply-->>Init: return after applying overrides
Init->>Config: proceed with Warp initialization (e.g., device selection)
Init-->>CLI: example runs using applied config overrides
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
ad728e6 to
62bef1b
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@newton/examples/__init__.py`:
- Around line 544-545: The current validation in _apply_warp_config allows
private or dunder keys because it only uses hasattr(wp.config, key); update the
validation to first reject any key that starts with '_' (e.g., if
key.startswith('_') then call parser.error with a message like "invalid
--warp-config key '{key}': private keys are not allowed") before checking
hasattr, and ensure parser.error is used for both private-key and unknown-key
cases; also add the provided test_private_key_rejected unit test to assert
SystemExit and that the stderr contains the private-key rejection message.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: a64dcbea-57a7-4057-86cd-834dd42a5c2f
📒 Files selected for processing (3)
CHANGELOG.mdnewton/examples/__init__.pynewton/tests/test_warp_config_cli.py
✅ Files skipped from review due to trivial changes (1)
- CHANGELOG.md
🚧 Files skipped from review as they are similar to previous changes (1)
- newton/tests/test_warp_config_cli.py
Allow overriding warp.config attributes from the command line when running Newton examples, without editing source code. The option is repeatable and applies overrides early in init(), before wp.set_device() or any call that triggers kernel compilation. Closes newton-physics#2205 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
62bef1b to
a438316
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@newton/examples/__init__.py`:
- Around line 535-539: The code assumes args has a warp_config attribute and
will raise AttributeError when a custom parser calls init(parser) without it;
update the check around args.warp_config to be defensive (e.g., use
getattr(args, 'warp_config', None) or hasattr(args, 'warp_config') and confirm
it's truthy/iterable) before the early return and before iterating over it so
the loop over args.warp_config only runs when the attribute exists and is
non-empty.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: bffca2cb-91e7-429c-87d0-ed36cde31e99
📒 Files selected for processing (3)
CHANGELOG.mdnewton/examples/__init__.pynewton/tests/test_warp_config_cli.py
✅ Files skipped from review due to trivial changes (1)
- CHANGELOG.md
🚧 Files skipped from review as they are similar to previous changes (1)
- newton/tests/test_warp_config_cli.py
d26dcbd
Description
Add a repeatable
--warp-config KEY=VALUECLI option to the shared exampleargument parser so that
warp.configattributes can be overridden from thecommand line without editing source code.
Closes #2205
Checklist
CHANGELOG.mdhas been updated (if user-facing change)Test plan
11 unit tests covering integer, string, boolean,
None, and empty-stringvalues, repeated overrides, unknown keys, and malformed entries.
Manual smoke test:
uv run -m newton.examples basic_pendulum --warp-config mode=release uv run -m newton.examples basic_pendulum --warp-config optimization_level=2 \ --warp-config verbose=TrueNew feature / API change
Summary by CodeRabbit
New Features
Tests
Documentation