Skip to content

Commit

Permalink
add dump circuit test
Browse files Browse the repository at this point in the history
  • Loading branch information
siq1 committed Nov 22, 2024
1 parent eff24c6 commit a102468
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions expander_compiler/src/circuit/ir/dest/mul_fanout_limit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,4 +436,42 @@ mod tests {

do_test(root, vec![2, 3, 4, 5, 6, 7, 8, 9, 10, 16, 64, 2000]);
}

#[test]
fn full_fanout_test_and_dump() {
use crate::circuit::ir::common::rand_gen::{RandomCircuitConfig, RandomRange};
use crate::utils::serde::Serde;

let config = RandomCircuitConfig {
seed: 2,
num_circuits: RandomRange { min: 20, max: 20 },
num_inputs: RandomRange { min: 1, max: 3 },
num_instructions: RandomRange { min: 30, max: 50 },
num_constraints: RandomRange { min: 0, max: 5 },
num_outputs: RandomRange { min: 1, max: 3 },
num_terms: RandomRange { min: 1, max: 5 },
sub_circuit_prob: 0.05,
};
let root = crate::circuit::ir::source::RootCircuit::<C>::random(&config);
assert_eq!(root.validate(), Ok(()));
let (_, circuit) = crate::compile::compile_with_options(
&root,
crate::compile::CompileOptions::default().with_mul_fanout_limit(256),
)
.unwrap();
assert_eq!(circuit.validate(), Ok(()));
for segment in circuit.segments.iter() {
let mut ref_num = vec![0; segment.num_inputs];
for m in segment.gate_muls.iter() {
ref_num[m.inputs[0]] += 1;
ref_num[m.inputs[1]] += 1;
}
for x in ref_num.iter() {
assert!(*x <= 256);
}
}

let mut buf = Vec::new();
circuit.serialize_into(&mut buf).unwrap();
}
}

0 comments on commit a102468

Please sign in to comment.