From 9a5093f520f1707a10bbee367d640e6aa9a2f4eb Mon Sep 17 00:00:00 2001 From: Steve Wang Date: Sun, 10 Sep 2023 14:42:31 -0400 Subject: [PATCH] rust id instead of ast id --- src/frontend/python/chiquito/dsl.py | 34 ++++++++++++++--------------- src/frontend/python/mod.rs | 28 ++++++++++++------------ 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/frontend/python/chiquito/dsl.py b/src/frontend/python/chiquito/dsl.py index 55f9469d..a33e429b 100644 --- a/src/frontend/python/chiquito/dsl.py +++ b/src/frontend/python/chiquito/dsl.py @@ -34,7 +34,7 @@ class SuperCircuit: def __init__(self: SuperCircuit): self.ast = ASTSuperCircuit() self.tables: Dict[int, LookupTable] = {} - # self.rust_ast_id: List[int] = [] + # self.rust_id: List[int] = [] self.mode = SuperCircuitMode.SETUP self.setup() self.mode = SuperCircuitMode.NoMode @@ -42,13 +42,13 @@ def __init__(self: SuperCircuit): # called under setup() def sub_circuit(self: SuperCircuit, sub_circuit: Circuit) -> Circuit: assert self.mode == SuperCircuitMode.SETUP - if sub_circuit.rust_ast_id != 0: + if sub_circuit.rust_id != 0: raise ValueError( "SuperCircuit: sub_circuit() cannot be called twice on the same circuit." ) ast_json: str = sub_circuit.get_ast_json() - sub_circuit.rust_ast_id: int = rust_chiquito.ast_to_halo2(ast_json) - self.ast.sub_circuits[sub_circuit.rust_ast_id] = sub_circuit.ast + sub_circuit.rust_id: int = rust_chiquito.ast_to_halo2(ast_json) + self.ast.sub_circuits[sub_circuit.rust_id] = sub_circuit.ast return sub_circuit # called under mapping() @@ -56,11 +56,11 @@ def sub_circuit(self: SuperCircuit, sub_circuit: Circuit) -> Circuit: def map(self: SuperCircuit, sub_circuit: Circuit, args: Any) -> TraceWitness: assert self.mode == SuperCircuitMode.Mapping witness: TraceWitness = sub_circuit.gen_witness(args) - if sub_circuit.rust_ast_id == 0: + if sub_circuit.rust_id == 0: raise ValueError( "SuperCircuit: must call sub_circuit() before calling map() on a Circuit." ) - self.ast.witnesses[sub_circuit.rust_ast_id] = witness + self.ast.witnesses[sub_circuit.rust_id] = witness return witness # called at the outermost level @@ -88,22 +88,22 @@ def gen_witness(self: SuperCircuit, args: Any) -> Dict[int, TraceWitness]: # return json.dumps(self.ast, cls=CustomEncoder, indent=4) def halo2_mock_prover(self: SuperCircuit, witnesses: Dict[int, TraceWitness]): - for rust_ast_id, witness in witnesses.items(): + for rust_id, witness in witnesses.items(): witness_json: str = witness.get_witness_json() - if rust_ast_id not in self.ast.sub_circuits: + if rust_id not in self.ast.sub_circuits: raise ValueError( - f"SuperCircuit.halo2_mock_prover(): TraceWitness with rust_ast_id {rust_ast_id} not found in sub_circuits." + f"SuperCircuit.halo2_mock_prover(): TraceWitness with rust_id {rust_id} not found in sub_circuits." ) - rust_chiquito.add_witness_to_ast(witness_json, rust_ast_id) + rust_chiquito.add_witness_to_ast(witness_json, rust_id) for sub_circuit_id in self.ast.sub_circuits: pass # def halo2_mock_prover(self: Circuit, witness: TraceWitness): - # if self.rust_ast_id == 0: + # if self.rust_id == 0: # ast_json: str = self.get_ast_json() - # self.rust_ast_id: int = rust_chiquito.ast_to_halo2(ast_json) + # self.rust_id: int = rust_chiquito.ast_to_halo2(ast_json) # witness_json: str = witness.get_witness_json() - # rust_chiquito.halo2_mock_prover(witness_json, self.rust_ast_id) + # rust_chiquito.halo2_mock_prover(witness_json, self.rust_id) class CircuitMode(Enum): @@ -117,7 +117,7 @@ class Circuit: def __init__(self: Circuit, super_circuit=None, imports=None): self.ast = ASTCircuit() self.witness = TraceWitness() - self.rust_ast_id = 0 + self.rust_id = 0 self.super_circuit = super_circuit self.imports = imports self.mode = CircuitMode.SETUP @@ -232,11 +232,11 @@ def get_ast_json(self: Circuit) -> str: return json.dumps(self.ast, cls=CustomEncoder, indent=4) def halo2_mock_prover(self: Circuit, witness: TraceWitness): - if self.rust_ast_id == 0: + if self.rust_id == 0: ast_json: str = self.get_ast_json() - self.rust_ast_id: int = rust_chiquito.ast_to_halo2(ast_json) + self.rust_id: int = rust_chiquito.ast_to_halo2(ast_json) witness_json: str = witness.get_witness_json() - rust_chiquito.halo2_mock_prover(witness_json, self.rust_ast_id) + rust_chiquito.halo2_mock_prover(witness_json, self.rust_id) def __str__(self: Circuit) -> str: return self.ast.__str__() diff --git a/src/frontend/python/mod.rs b/src/frontend/python/mod.rs index 23cd5a5c..995ff507 100644 --- a/src/frontend/python/mod.rs +++ b/src/frontend/python/mod.rs @@ -54,47 +54,47 @@ pub fn chiquito_ast_to_halo2(ast_json: &str) -> UUID { uuid } -pub fn chiquito_add_witness_to_ast(witness_json: &str, ast_id: UUID) { +pub fn chiquito_add_witness_to_ast(witness_json: &str, rust_id: UUID) { let witness: TraceWitness = serde_json::from_str(witness_json).expect("Json deserialization to TraceWitness failed."); CIRCUIT_MAP.with(|circuit_map| { let mut circuit_map = circuit_map.borrow_mut(); - let circuit_map_store = circuit_map.get_mut(&ast_id).unwrap(); + let circuit_map_store = circuit_map.get_mut(&rust_id).unwrap(); circuit_map_store.3 = Some(witness); }); - println!("Added TraceWitness to ast_id: {:?}", ast_id); + println!("Added TraceWitness to rust_id: {:?}", rust_id); } -fn add_assignment_generator_to_ast(assignment_generator: AssignmentGenerator, ast_id: UUID) { +fn add_assignment_generator_to_ast(assignment_generator: AssignmentGenerator, rust_id: UUID) { CIRCUIT_MAP.with(|circuit_map| { let mut circuit_map = circuit_map.borrow_mut(); - let circuit_map_store = circuit_map.get_mut(&ast_id).unwrap(); + let circuit_map_store = circuit_map.get_mut(&rust_id).unwrap(); circuit_map_store.2 = Some(assignment_generator); }); - println!("Added AssignmentGenerator to ast_id: {:?}", ast_id); + println!("Added AssignmentGenerator to rust_id: {:?}", rust_id); } -pub fn chiquito_super_circuit_halo2_mock_prover(ast_ids: Vec) { +pub fn chiquito_super_circuit_halo2_mock_prover(rust_ids: Vec) { let mut ctx = SuperCircuitContext::::default(); // super_circuit def let config = config(SingleRowCellManager {}, SimpleStepSelectorBuilder {}); - for ast_id in ast_ids.clone() { - let circuit_map_store = uuid_to_halo2(ast_id); + for rust_id in rust_ids.clone() { + let circuit_map_store = uuid_to_halo2(rust_id); let (circuit, chiquito_halo2, assignment_generator, witness) = circuit_map_store; let assignment = ctx.sub_circuit_with_ast(config.clone(), circuit); - add_assignment_generator_to_ast(assignment, ast_id); + add_assignment_generator_to_ast(assignment, rust_id); } let super_circuit = ctx.compile(); let compiled = chiquitoSuperCircuit2Halo2(&super_circuit); let mut mapping_ctx = MappingContext::default(); - for ast_id in ast_ids { - let circuit_map_store = uuid_to_halo2(ast_id); + for rust_id in rust_ids { + let circuit_map_store = uuid_to_halo2(rust_id); let (circuit, chiquito_halo2, assignment_generator, witness) = circuit_map_store; if witness.is_some() { mapping_ctx.map_with_witness(&assignment_generator.unwrap(), witness.unwrap()); @@ -128,10 +128,10 @@ fn uuid_to_halo2(uuid: UUID) -> CircuitMapStore { }) } -pub fn chiquito_halo2_mock_prover(witness_json: &str, ast_id: UUID) { +pub fn chiquito_halo2_mock_prover(witness_json: &str, rust_id: UUID) { let trace_witness: TraceWitness = serde_json::from_str(witness_json).expect("Json deserialization to TraceWitness failed."); - let (_, compiled, assignment_generator, _) = uuid_to_halo2(ast_id); + let (_, compiled, assignment_generator, _) = uuid_to_halo2(rust_id); let circuit: ChiquitoHalo2Circuit<_> = ChiquitoHalo2Circuit::new( compiled, assignment_generator.map(|g| g.generate_with_witness(trace_witness)),