Skip to content

Commit

Permalink
Check in circuit microbench results
Browse files Browse the repository at this point in the history
  • Loading branch information
sgdxbc committed Apr 21, 2024
1 parent 3ab73f2 commit ce874ca
Show file tree
Hide file tree
Showing 24 changed files with 1,019 additions and 172 deletions.
1 change: 1 addition & 0 deletions crates/boson-circuit/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/boson-circuit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ lto = true
[dependencies]
anyhow = { version = "1.0.81", features = ["backtrace"] }
plonky2 = { git = "https://github.com/sgdxbc/plonky2", version = "0.2.1" }
plonky2_maybe_rayon = { git = "https://github.com/sgdxbc/plonky2", version = "0.2.0" }
tracing = "0.1.40"
log = "0.4.21"
plonky2_u32 = { git = "https://github.com/sgdxbc/plonky2-u32", version = "0.1.0" }
Expand Down
86 changes: 56 additions & 30 deletions crates/boson-circuit/examples/bench-clock.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
use std::{
fmt::Write,
fs::write,
time::{Instant, SystemTime},
};

use boson_circuit::{index_secret, Clock};
use plonky2::plonk::circuit_data::CircuitConfig;
// use plonky2_maybe_rayon::rayon;
use tracing::info;
use plonky2_maybe_rayon::rayon;
use rand::{thread_rng, Rng};
// use tracing::info;

fn main() -> anyhow::Result<()> {
tracing_subscriber::fmt::init();
Expand All @@ -13,8 +20,9 @@ fn main() -> anyhow::Result<()> {
// rayon::current_num_threads(),
// 16
// );
let num_thread = rayon::current_num_threads();

const S: usize = 64;
const S: usize = 1 << 10;
let (clock, circuit) = Clock::<S>::genesis(
[(); S].map({
let mut i = 0;
Expand All @@ -38,45 +46,63 @@ fn main() -> anyhow::Result<()> {
// let clock2 = clock10.merge(&clock11, &circuit)?;

let mut clocks = Vec::new();
for index in 0..4 {
clocks.push(clock.clone());
// for i in 0..max_depth {
for i in 0..10 {
let clock =
clocks
.last()
.as_ref()
.unwrap()
.increment(index, index_secret(index), &circuit)?;
clock.verify(&circuit)?;
let compressed = clock.proof.clone().compress(
&circuit.data.verifier_only.circuit_digest,
&circuit.data.common,
)?;
if index == 0 {
info!(
"depth {i} proof size {} compressed {}",
clock.proof.to_bytes().len(),
compressed.to_bytes().len()
)
}
clocks.push(clock)
}
}
clocks.push(clock);
// for index in 0..4 {
// clocks.push(clock.clone());
// // for i in 0..max_depth {
// for i in 0..10 {
// let clock =
// clocks
// .last()
// .as_ref()
// .unwrap()
// .increment(index, index_secret(index), &circuit)?;
// clock.verify(&circuit)?;
// let compressed = clock.proof.clone().compress(
// &circuit.data.verifier_only.circuit_digest,
// &circuit.data.common,
// )?;
// if index == 0 {
// info!(
// "depth {i} proof size {} compressed {}",
// clock.proof.to_bytes().len(),
// compressed.to_bytes().len()
// )
// }
// clocks.push(clock)
// }
// }
let mut lines = String::new();
for _ in 0..32 {
use rand::seq::SliceRandom;
let clock1 = clocks.choose(&mut rand::thread_rng()).unwrap();
let clock2 = clocks.choose(&mut rand::thread_rng()).unwrap();
// info!(
// "merge {:?} and {:?}",
// "with {:?} and {:?}",
// clock1.counters().collect::<Vec<_>>(),
// clock2.counters().collect::<Vec<_>>(),
// );
let clock = clock1.merge(clock2, &circuit)?;
// let clock = clock1.merge(clock2, &circuit)?;
// info!("merged into {:?}", clock.counters().collect::<Vec<_>>());
let index = thread_rng().gen_range(0..S);
let start = Instant::now();
let clock = clock1.update(index, index_secret(index), clock2, &circuit)?;
// info!("updated into {:?}", clock.counters().collect::<Vec<_>>());
writeln!(
&mut lines,
"{num_thread},{S},{}",
start.elapsed().as_secs_f32()
)?;
clock.verify(&circuit)?;
clocks.push(clock)
}
write(
format!(
"../../tools/boson-control/notebooks/circuit-{}.txt",
SystemTime::UNIX_EPOCH.elapsed()?.as_secs()
),
lines,
)?;

Ok(())
}
Expand Down
Loading

0 comments on commit ce874ca

Please sign in to comment.