Skip to content

Commit

Permalink
REPL more info on iterations
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriel-barrett committed Aug 6, 2024
1 parent a772954 commit d5639db
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
17 changes: 17 additions & 0 deletions src/lair/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,23 @@ impl<F: PrimeField32> QueryRecord<F> {
pub fn expect_public_values(&self) -> &[F] {
self.public_values.as_ref().expect("Public values not set")
}

pub fn stats<H: Chipset<F>>(&self, toplevel: &Toplevel<F, H>) -> (usize, usize) {
let mut steps = 0;
let mut width = 0;
for (i, queries) in self.func_queries.iter().enumerate() {
steps += queries.len();
let func = toplevel.get_by_index(i);
let func_width = func.compute_layout_sizes(toplevel).total();
width += queries.len() * func_width;
}
for (i, queries) in self.mem_queries.iter().enumerate() {
steps += queries.len();
let mem_width = 4 + mem_index_to_len(i);
width += queries.len() * mem_width;
}
(steps, width)
}
}

impl<F: PrimeField32, H: Chipset<F>> Toplevel<F, H> {
Expand Down
2 changes: 1 addition & 1 deletion src/lair/func_chip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub type LayoutSizes = ColumnLayout<usize, usize>;

impl LayoutSizes {
#[inline]
fn total(&self) -> usize {
pub fn total(&self) -> usize {
self.nonce + self.input + self.aux + self.sel
}
}
Expand Down
17 changes: 9 additions & 8 deletions src/lurk/cli/repl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ pub(crate) struct Repl<F: PrimeField32, H: Chipset<F>> {
pub(crate) queries: QueryRecord<F>,
pub(crate) toplevel: Toplevel<F, H>,
pub(crate) lurk_main_idx: usize,
eval_idx: usize,
pub(crate) env: ZPtr<F>,
state: StateRcCell,
pwd_path: Utf8PathBuf,
Expand All @@ -54,14 +53,12 @@ impl Repl<BabyBear, LurkChip> {
let (toplevel, mut zstore) = build_lurk_toplevel();
let queries = QueryRecord::new(&toplevel);
let lurk_main_idx = toplevel.get_by_name("lurk_main").index;
let eval_idx = toplevel.get_by_name("eval").index;
let env = zstore.intern_empty_env();
Self {
zstore,
queries,
toplevel,
lurk_main_idx,
eval_idx,
env,
state: State::init_lurk_state().rccell(),
pwd_path: current_dir().expect("Couldn't get current directory"),
Expand All @@ -70,11 +67,15 @@ impl Repl<BabyBear, LurkChip> {
}
}

fn pretty_iterations_display(iterations: usize) -> String {
fn pretty_iterations_display(iterations: usize, width: usize) -> String {
if iterations != 1 {
format!("{iterations} iterations")
let average_width = width as f64 / iterations as f64;
format!(
"{iterations} iterations, average step size {:.2}",
average_width
)
} else {
"1 iteration".into()
format!("1 iteration, width {width}")
}
}

Expand Down Expand Up @@ -163,10 +164,10 @@ impl<F: PrimeField32, H: Chipset<F>> Repl<F, H> {
self.queries.get_inv_queries("hash_32_8", &self.toplevel),
self.queries.get_inv_queries("hash_48_8", &self.toplevel),
);
let iterations = self.queries.func_queries[self.eval_idx].len();
let (iterations, width) = self.queries.stats(&self.toplevel);
println!(
"[{}] => {}",
pretty_iterations_display(iterations),
pretty_iterations_display(iterations, width),
self.fmt(&output)
);
}
Expand Down

0 comments on commit d5639db

Please sign in to comment.