Skip to content

Commit

Permalink
adding the string names in debug mode
Browse files Browse the repository at this point in the history
  • Loading branch information
hecmas committed Dec 20, 2024
1 parent 9147369 commit 15bea65
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
18 changes: 2 additions & 16 deletions pil2-components/lib/std/pil/std_connection.pil
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const int DEFAULT_CONNECTION_N = 0;
* col witness a,b,c;
* connection_init(opid, [a, b, c]);
*/
function connection_init(const int opid, const expr cols[], int default_frame_size = DEFAULT_CONNECTION_N, const int bus_type = 0) {
function connection_init(const int opid, const expr cols[], int default_frame_size = DEFAULT_CONNECTION_N, const int bus_type = PIOP_BUS_DEFAULT) {
if (default_frame_size == DEFAULT_CONNECTION_N) default_frame_size = N;

if (default_frame_size < 1) {
Expand Down Expand Up @@ -484,20 +484,6 @@ private function checkClosed() {
}
}

/**
* TODO
*
* @param {int} opid - The (unique) identifier of the connection
* @param {expr[]} cols - Array of columns to be connected
* @param {expr[]} conn - Fixed columns indicating the connection
* @example
* col witness a,b,c;
* col fixed S1,S2,S3;
* // Compute S1, S2, S3...
* connection(opid, [a, b, c], [S1, S2, S3]);
* connection(opid, [a, b, c], [S1, S2, S3], N/2);
*/

/**
* Connects the columns `cols` with the fixed columns `CONN`.
*
Expand All @@ -510,7 +496,7 @@ private function checkClosed() {
* col fixed S1,S2,S3;
* connection(opid, [a, b, c], [S1, S2, S3]);
*/
function connection(const int opid, const expr cols[], const expr CONN[], const int bus_type = 0) {
function connection(const int opid, const expr cols[], const expr CONN[], const int bus_type = PIOP_BUS_DEFAULT) {
const int len = length(cols);
if (len == 0) {
error(`Connection #${opid} cannot be empty`);
Expand Down
14 changes: 11 additions & 3 deletions pil2-components/lib/std/rs/src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::{
};

use p3_field::PrimeField;
use proofman_common::ProofCtx;
use proofman_hints::{format_vec, HintFieldOutput};

pub type DebugData<F> = Mutex<HashMap<F, HashMap<Vec<HintFieldOutput<F>>, BusValue<F>>>>; // opid -> val -> BusValue
Expand Down Expand Up @@ -81,6 +82,7 @@ pub fn update_debug_data<F: PrimeField>(
}

pub fn print_debug_info<F: PrimeField>(
pctx: &ProofCtx<F>,
name: &str,
max_values_to_print: usize,
print_to_file: bool,
Expand Down Expand Up @@ -151,7 +153,7 @@ pub fn print_debug_info<F: PrimeField>(
}
let shared_data = &data.shared_data;
let grouped_data = &mut data.grouped_data;
print_diffs(val, max_values_to_print, shared_data, grouped_data, false, &mut output);
print_diffs(pctx, val, max_values_to_print, shared_data, grouped_data, false, &mut output);
}

if len_overassumed > 0 {
Expand All @@ -176,7 +178,7 @@ pub fn print_debug_info<F: PrimeField>(

let shared_data = &data.shared_data;
let grouped_data = &mut data.grouped_data;
print_diffs(val, max_values_to_print, shared_data, grouped_data, true, &mut output);
print_diffs(pctx, val, max_values_to_print, shared_data, grouped_data, true, &mut output);
}

if len_overproven > 0 {
Expand All @@ -185,6 +187,7 @@ pub fn print_debug_info<F: PrimeField>(
}

fn print_diffs<F: PrimeField>(
pctx: &ProofCtx<F>,
val: &[HintFieldOutput<F>],
max_values_to_print: usize,
shared_data: &SharedData<F>,
Expand Down Expand Up @@ -230,15 +233,20 @@ pub fn print_debug_info<F: PrimeField>(

// Print grouped rows
for (airgroup_id, air_id, instance_id, mut rows) in organized_rows {
let airgroup_name = pctx.global_info.get_air_group_name(airgroup_id);
let air_name = pctx.global_info.get_air_name(airgroup_id, air_id);

rows.sort();
let rows_display =
rows.iter().map(|x| x.to_string()).take(max_values_to_print).collect::<Vec<_>>().join(",");

let truncated = rows.len() > max_values_to_print;
writeln!(
output,
"\t Airgroup: {:<3} | Air: {:<3} | Instance: {:<3} | Num: {:<9} | Rows: [{}{}]",
"\t Airgroup: {} ({}) | Air: {} ({}) | Instance ID: {} | Num: {} | Rows: [{}{}]",
airgroup_name,
airgroup_id,
air_name,
air_id,
instance_id,
rows.len(),
Expand Down
5 changes: 4 additions & 1 deletion pil2-components/lib/std/rs/src/std_prod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use crate::{
};

pub struct StdProd<F: PrimeField> {
pctx: Arc<ProofCtx<F>>,
mode: StdMode,
stage_wc: Option<Mutex<u32>>,
debug_data: Option<DebugData<F>>,
Expand All @@ -40,6 +41,7 @@ impl<F: PrimeField> AirComponent<F> for StdProd<F> {
// Initialize std_prod with the extracted data
let mode = mode.expect("Mode must be provided");
let std_prod = Arc::new(Self {
pctx: wcm.get_pctx(),
mode: mode.clone(),
stage_wc: match std_prod_users_id.is_empty() {
true => None,
Expand Down Expand Up @@ -324,11 +326,12 @@ impl<F: PrimeField> WitnessComponent<F> for StdProd<F> {
fn end_proof(&self) {
// Print debug info if in debug mode
if self.mode.name == ModeName::Debug {
let pctx = &self.pctx;
let name = Self::MY_NAME;
let max_values_to_print = self.mode.n_vals;
let print_to_file = self.mode.print_to_file;
let debug_data = self.debug_data.as_ref().expect("Debug data missing");
print_debug_info(name, max_values_to_print, print_to_file, debug_data);
print_debug_info(pctx, name, max_values_to_print, print_to_file, debug_data);
}
}
}
5 changes: 4 additions & 1 deletion pil2-components/lib/std/rs/src/std_sum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use crate::{
};

pub struct StdSum<F: PrimeField> {
pctx: Arc<ProofCtx<F>>,
mode: StdMode,
stage_wc: Option<Mutex<u32>>,
debug_data: Option<DebugData<F>>,
Expand All @@ -42,6 +43,7 @@ impl<F: PrimeField> AirComponent<F> for StdSum<F> {
// Initialize std_sum with the extracted data
let mode = mode.expect("Mode must be provided");
let std_sum = Arc::new(Self {
pctx: wcm.get_pctx(),
mode: mode.clone(),
stage_wc: match std_sum_users_id.is_empty() {
true => None,
Expand Down Expand Up @@ -366,11 +368,12 @@ impl<F: PrimeField> WitnessComponent<F> for StdSum<F> {
fn end_proof(&self) {
// Print debug info if in debug mode
if self.mode.name == ModeName::Debug {
let pctx = &self.pctx;
let name = Self::MY_NAME;
let max_values_to_print = self.mode.n_vals;
let print_to_file = self.mode.print_to_file;
let debug_data = self.debug_data.as_ref().expect("Debug data missing");
print_debug_info(name, max_values_to_print, print_to_file, debug_data);
print_debug_info(pctx, name, max_values_to_print, print_to_file, debug_data);
}
}
}

0 comments on commit 15bea65

Please sign in to comment.