Skip to content

Commit

Permalink
add --to-stdout flag to feat/axiom-std-2 (#29)
Browse files Browse the repository at this point in the history
* WIP: add to_stdout cli param

* stdout for all write fns

* Update  for witnessgen only

* Update readme
  • Loading branch information
ytham authored Jun 3, 2024
1 parent 16a0fd7 commit fe76d66
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 10 deletions.
14 changes: 13 additions & 1 deletion sdk/src/run/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ pub fn run_cli_on_scaffold<
>(
cli: AxiomCircuitRunnerOptions,
) {
match cli.command {
SnarkCmd::WitnessGen => {}
_ => {
if cli.to_stdout {
panic!("The `to_stdout` argument is only valid for the `witness-gen` command.");
}
}
}
match cli.command {
SnarkCmd::Mock | SnarkCmd::Prove | SnarkCmd::WitnessGen => {
if cli.input_path.is_none() {
Expand Down Expand Up @@ -236,7 +244,11 @@ pub fn run_cli_on_scaffold<
}
SnarkCmd::WitnessGen => {
let output = witness_gen(&mut runner);
write_witness_gen_output(output, cli.data_path.join(PathBuf::from("compute.json")));
write_witness_gen_output(
output,
cli.data_path.join(PathBuf::from("compute.json")),
cli.to_stdout,
);
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions sdk/src/run/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ Options:
-n, --name <NAME> Name of the output metadata file [default: circuit]
-d, --data-path <DATA_PATH> For saving build artifacts [default: data]
-c, --config <CONFIG> For specifying custom circuit parameters
--srs <SRS> For specifying custom KZG params directory [default: params]
--aggregate Whether to aggregate the output (defaults to false)
--auto-config-aggregation Whether to aggregate the output (defaults to false)
--srs <SRS> For specifying custom KZG params directory
--aggregate Whether to aggregate the output [default: false]
--auto-config-aggregation Whether to aggregate the output [default: false]
-s, --to-stdout (witness-gen only) Output to stdout (true) or json (false) [default: false]
-h, --help Print help
-V, --version Print version
```
13 changes: 11 additions & 2 deletions sdk/src/run/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,26 @@ pub struct AxiomCircuitRunnerOptions {

#[arg(
long = "aggregate",
help = "Whether to aggregate the output (defaults to false)",
help = "Whether to aggregate the output [default: false]",
action
)]
/// Whether to aggregate the output
pub should_aggregate: bool,

#[arg(
long = "auto-config-aggregation",
help = "Whether to aggregate the output (defaults to false)",
help = "Whether to aggregate the output [default: false]",
action
)]
/// Whether to auto calculate the aggregation params
pub should_auto_config_aggregation_circuit: bool,

#[arg(
short = 's',
long = "to-stdout",
help = "(witness-gen only) Output to stdout (true) or json (false) [default: false]",
action
)]
/// Whether to output to stdout (true) or json file (false)
pub to_stdout: bool,
}
14 changes: 10 additions & 4 deletions sdk/src/utils/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,15 +203,21 @@ pub fn write_output(
info!("Writing JSON output to {:?}", &json_output_path);
let f = File::create(&json_output_path)
.unwrap_or_else(|_| panic!("Could not create file at {json_output_path:?}"));
serde_json::to_writer_pretty(&f, &output).expect("Writing output should not fail");

serde_json::to_writer_pretty(&f, &output).expect("Writing output should not fail");
}

pub fn write_witness_gen_output(
output: AxiomV2DataAndResults,
json_output_path: PathBuf,
to_stdout: bool,
) {
info!("Writing JSON output to {:?}", &json_output_path);
let f = File::create(&json_output_path)
if to_stdout {
serde_json::to_writer_pretty(&std::io::stdout(), &output.compute_results).expect("Writing output should not fail");
} else {
info!("Writing JSON output to {:?}", &json_output_path);
let f = File::create(&json_output_path)
.unwrap_or_else(|_| panic!("Could not create file at {json_output_path:?}"));
serde_json::to_writer_pretty(&f, &output.compute_results).expect("Writing output should not fail");
serde_json::to_writer_pretty(&f, &output.compute_results).expect("Writing output should not fail");
}
}

0 comments on commit fe76d66

Please sign in to comment.