Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
qwang98 committed Oct 19, 2023
1 parent f7782e3 commit 70e2e26
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 31 deletions.
3 changes: 1 addition & 2 deletions examples/factorial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ use halo2_proofs::{dev::MockProver, halo2curves::bn256::Fr};
const MAX_FACTORIAL: usize = 10;

fn generate<F: Field + From<u64> + Hash>() -> (Circuit<F>, Option<AssignmentGenerator<F, u32>>) {
//
// table for the circuit:
// | step_type | i | x |
// ----------------------------------
Expand Down Expand Up @@ -149,7 +148,7 @@ fn main() {

// plaf boilerplate
use chiquito::plonkish::backend::plaf::chiquito2Plaf;
use polyexen::plaf::{backends::halo2::PlafH2Circuit};
use polyexen::plaf::backends::halo2::PlafH2Circuit;

// get Chiquito ir
let (circuit, wit_gen) = generate::<Fr>();
Expand Down
1 change: 0 additions & 1 deletion examples/mimc7.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,6 @@ fn test_pil_super_circuit_mimc7() {
);

print!("{}", chiquito_pil_super_circuit.to_pil());

}

mod mimc7_constants {
Expand Down
6 changes: 3 additions & 3 deletions src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,10 @@ impl<F: Clone, TraceArgs> Circuit<F, TraceArgs> {
halo2_fixed: self.halo2_fixed.clone(),
exposed: self.exposed.clone(),
annotations: self.annotations.clone(),
trace: None, // Remove the trace
trace: None, // Remove the trace.
fixed_assignments: self.fixed_assignments.clone(),
first_step: self.first_step.clone(),
last_step: self.last_step.clone(),
first_step: self.first_step,
last_step: self.last_step,
num_steps: self.num_steps,
q_enable: self.q_enable,
id: self.id,
Expand Down
43 changes: 20 additions & 23 deletions src/plonkish/backend/powdr_pil.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ impl<F: Debug + Clone, TraceArgs> ChiquitoPil<F, TraceArgs> {
// from the AST. Replace space because they will break the constraints in
// PIL.
for (key, value) in &self.ast.annotations {
new_annotations_map.insert(*key, (self.ast.id, value.replace(" ", "_")));
new_annotations_map.insert(*key, (self.ast.id, value.replace(' ', "_")));
}

// Next, add all annotations from each step type.
for (_, step_type) in &self.ast.step_types {
for step_type in self.ast.step_types.values() {
for (key, value) in &step_type.annotations {
new_annotations_map.insert(*key, (self.ast.id, value.replace(" ", "_")));
new_annotations_map.insert(*key, (self.ast.id, value.replace(' ', "_")));
}
}

Expand All @@ -100,7 +100,7 @@ impl<F: Debug + Clone, TraceArgs> ChiquitoPil<F, TraceArgs> {
let mut col_witness_uuids: Vec<UUID> = Vec::new();

// Collect UUIDs of internal signals stored at the step type level.
for (_, step_type) in &self.ast.step_types {
for step_type in self.ast.step_types.values() {
col_witness_uuids.extend::<Vec<UUID>>(
step_type
.signals
Expand Down Expand Up @@ -161,7 +161,7 @@ impl<F: Debug + Clone, TraceArgs> ChiquitoPil<F, TraceArgs> {
annotations_map
.as_ref()
.unwrap()
.get(&uuid)
.get(uuid)
.unwrap()
.clone()
.1
Expand All @@ -185,7 +185,7 @@ impl<F: Debug + Clone, TraceArgs> ChiquitoPil<F, TraceArgs> {
annotations_map
.as_ref()
.unwrap()
.get(&uuid)
.get(uuid)
.unwrap()
.clone()
.1
Expand All @@ -211,7 +211,7 @@ impl<F: Debug + Clone, TraceArgs> ChiquitoPil<F, TraceArgs> {
// Iterate over step types to create constraint statements, fixed columns for step type
// selectors, and lookups.
if !self.ast.step_types.is_empty() && self.witness.is_some() {
for (_, step_type) in &self.ast.step_types {
for step_type in self.ast.step_types.values() {
let step_type_name = annotations_map
.as_ref()
.unwrap()
Expand Down Expand Up @@ -316,8 +316,8 @@ impl<F: Debug + Clone, TraceArgs> ChiquitoPil<F, TraceArgs> {
writeln!(pil, "col fixed {} = [{}];", fixed_name, assignments_string).unwrap();
}
}
writeln!(pil, "").unwrap();
writeln!(pil, "").unwrap(); // Separator rows for the circuit.
writeln!(pil).unwrap();
writeln!(pil).unwrap(); // Separator rows for the circuit.
pil
}
}
Expand Down Expand Up @@ -400,13 +400,13 @@ impl<F: Debug + Clone> ChiquitoPilSuperCircuit<F> {
// Loop over each AST.
for (ast_id, ast) in self.super_ast.iter() {
let mut annotations_map: HashMap<UUID, String> = HashMap::new();
let circuit_name = self.circuit_names.get(&ast_id).unwrap().clone();
let circuit_name = self.circuit_names.get(ast_id).unwrap().clone();

// First, get AST level annotations.
annotations_map.extend(ast.annotations.clone());

// Second, get step level annotations.
for (_, step_type) in &ast.step_types {
for step_type in ast.step_types.values() {
annotations_map.extend(step_type.annotations.clone());
}

Expand All @@ -417,8 +417,8 @@ impl<F: Debug + Clone> ChiquitoPilSuperCircuit<F> {
(
uuid,
(
ast_id.clone(),
format!("{}.{}", circuit_name, annotation.replace(" ", "_")),
*ast_id,
format!("{}.{}", circuit_name, annotation.replace(' ', "_")),
),
)
},
Expand All @@ -433,10 +433,9 @@ impl<F: Debug + Clone> ChiquitoPilSuperCircuit<F> {
for (id, ast) in self.super_ast.iter() {
let witness = self.super_witness.get(id).unwrap();
let chiquito_pil = ChiquitoPil::new(ast.clone(), witness.clone());
pil = pil
+ chiquito_pil
.to_pil_single_circuit(Some(super_circuit_annotations_map.clone()))
.as_str();
pil += chiquito_pil
.to_pil_single_circuit(Some(super_circuit_annotations_map.clone()))
.as_str();
}

pil
Expand Down Expand Up @@ -513,21 +512,19 @@ fn convert_to_pil_expr_string<F: Debug + Clone>(
Expr::Sum(sum) => {
let mut expr_string = String::new();
for (index, expr) in sum.iter().enumerate() {
expr_string = expr_string
+ convert_to_pil_expr_string(expr.clone(), annotations_map).as_str();
expr_string += convert_to_pil_expr_string(expr.clone(), annotations_map).as_str();
if index != sum.len() - 1 {
expr_string = expr_string + " + ";
expr_string += " + ";
}
}
format!("({})", expr_string)
}
Expr::Mul(mul) => {
let mut expr_string = String::new();
for (index, expr) in mul.iter().enumerate() {
expr_string = expr_string
+ convert_to_pil_expr_string(expr.clone(), annotations_map).as_str();
expr_string += convert_to_pil_expr_string(expr.clone(), annotations_map).as_str();
if index != mul.len() - 1 {
expr_string = expr_string + " * ";
expr_string += " * ";
}
}
format!("({})", expr_string)
Expand Down
5 changes: 3 additions & 2 deletions src/plonkish/ir/sc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ impl<F, MappingArgs> SuperCircuit<F, MappingArgs> {
self.sub_circuit_asts.push(sub_circuit_ast);
}

// Mapping from AST id to IR id is needed for the PIL backend to match TraceWitness, which has IR id, to AST.
// Mapping from AST id to IR id is needed for the PIL backend to match TraceWitness, which has
// IR id, to AST.
pub fn get_ast_id_to_ir_id_mapping(&self) -> HashMap<UUID, UUID> {
let mut ast_id_to_ir_id_mapping: HashMap<UUID, UUID> = HashMap::new();
self.sub_circuits.iter().for_each(|circuit| {
Expand Down Expand Up @@ -149,7 +150,7 @@ impl<F: Field, MappingArgs> MappingGenerator<F, MappingArgs> {

ctx.get_super_assignments()
}

// Needed for the PIL backend.
pub fn generate_super_trace_witnesses(&self, args: MappingArgs) -> SuperTraceWitness<F> {
let mut ctx = MappingContext::default();
Expand Down

0 comments on commit 70e2e26

Please sign in to comment.