Add save command to the examples#874
Conversation
|
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
How to use the Graphite Merge QueueAdd the label merge-ready to this PR to add it to the merge queue. You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
f244472 to
c224826
Compare
9d18658 to
0c61270
Compare
c224826 to
709b2fd
Compare
0c61270 to
5f45183
Compare
|
@GraDKh Added 3 nits that would actually be nice, assuming you will address them and pre-approving |
5f45183 to
06a3624
Compare
| #[command(flatten)] | ||
| instance: CommandArgs, |
There was a problem hiding this comment.
There appears to be a duplicate command argument flattening issue in the Save command struct. Both params and instance fields have the same type CommandArgs, which will cause clap to register the same argument names twice, resulting in runtime parsing conflicts.
Since both fields serve the same purpose (collecting command arguments), the params field on line 113 should be removed, leaving only the instance field on line 116. This will ensure arguments are properly parsed without conflicts when users run the save command.
/// Save constraint system, public witness, and non-public data to files if paths are provided
Save {
/// Output path for the constraint system binary
#[arg(long = "cs-path")]
cs_path: Option<String>,
/// Output path for the public witness binary
#[arg(long = "pub-witness-path")]
pub_witness_path: Option<String>,
/// Output path for the non-public data (witness + internal) binary
#[arg(long = "non-pub-data-path")]
non_pub_data_path: Option<String>,
// Remove this duplicate field
// #[command(flatten)]
// params: CommandArgs,
#[command(flatten)]
instance: CommandArgs,
}Spotted by Diamond
Is this helpful? React 👍 or 👎 to let us know.
|
Addressed all the comments |
06a3624 to
d112b72
Compare
| if let Some(parent) = Path::new(path).parent() | ||
| && !parent.as_os_str().is_empty() | ||
| { |
There was a problem hiding this comment.
The if let combined with && creates a syntax issue that could lead to unexpected behavior. The current structure:
if let Some(parent) = Path::new(path).parent()
&& !parent.as_os_str().is_empty()
{
// ...
}This attempts to use parent in the second condition, but the variable binding from if let doesn't properly extend through the && operator in this context.
Consider restructuring with either nested conditionals:
if let Some(parent) = Path::new(path).parent() {
if !parent.as_os_str().is_empty() {
// ...
}
}Or with proper parentheses to clarify the intent:
if let Some(parent) = Path::new(path).parent() && (!parent.as_os_str().is_empty()) {
// ...
}| if let Some(parent) = Path::new(path).parent() | |
| && !parent.as_os_str().is_empty() | |
| { | |
| if let Some(parent) = Path::new(path).parent() { | |
| if !parent.as_os_str().is_empty() | |
| { |
Spotted by Diamond
Is this helpful? React 👍 or 👎 to let us know.
d112b72 to
5886785
Compare
709b2fd to
47b98f6
Compare
Merge activity
|
# Add save subcommand to example CLI for artifact export
### TL;DR
Adds a new `save` subcommand to the examples CLI that allows exporting circuit artifacts to files.
### What changed?
- Added a new `save` subcommand to the example CLI that can export:
- Constraint system binary
- Public witness values
- Non-public data values
- Implemented a helper function `write_serialized` to handle serialization and file writing
- Updated the README with documentation for all CLI subcommands, including detailed usage examples for the new `save` command
### How to test?
Run any example with the new save subcommand:
```
# Save only the constraint system
cargo run --release --example my_circuit -- save --cs-path out/cs.bin
# Save public values and non-public values
cargo run --release --example my_circuit -- save \
--pub-witness-path out/public.bin \
--non-pub-data-path out/non_public.bin
# Save all three artifacts
cargo run --release --example my_circuit -- save \
--cs-path out/cs.bin \
--pub-witness-path out/public.bin \
--non-pub-data-path out/non_public.bin
```
### Why make this change?
This change enables developers to export circuit artifacts for external analysis, debugging, or integration with other tools. The ability to save constraint systems and witness data separately provides flexibility for different workflows and testing scenarios.
# Add save subcommand to example CLI for artifact export
### TL;DR
Adds a new `save` subcommand to the examples CLI that allows exporting circuit artifacts to files.
### What changed?
- Added a new `save` subcommand to the example CLI that can export:
- Constraint system binary
- Public witness values
- Non-public data values
- Implemented a helper function `write_serialized` to handle serialization and file writing
- Updated the README with documentation for all CLI subcommands, including detailed usage examples for the new `save` command
### How to test?
Run any example with the new save subcommand:
```
# Save only the constraint system
cargo run --release --example my_circuit -- save --cs-path out/cs.bin
# Save public values and non-public values
cargo run --release --example my_circuit -- save \
--pub-witness-path out/public.bin \
--non-pub-data-path out/non_public.bin
# Save all three artifacts
cargo run --release --example my_circuit -- save \
--cs-path out/cs.bin \
--pub-witness-path out/public.bin \
--non-pub-data-path out/non_public.bin
```
### Why make this change?
This change enables developers to export circuit artifacts for external analysis, debugging, or integration with other tools. The ability to save constraint systems and witness data separately provides flexibility for different workflows and testing scenarios.

Add save subcommand to example CLI for artifact export
TL;DR
Adds a new
savesubcommand to the examples CLI that allows exporting circuit artifacts to files.What changed?
savesubcommand to the example CLI that can export:write_serializedto handle serialization and file writingsavecommandHow to test?
Run any example with the new save subcommand:
Why make this change?
This change enables developers to export circuit artifacts for external analysis, debugging, or integration with other tools. The ability to save constraint systems and witness data separately provides flexibility for different workflows and testing scenarios.