@@ -37,11 +37,14 @@ pub fn benchmarks<M: Measurement>(c: &mut Criterion<M>) {
3737}
3838
3939/// Create a realistic DEM sampler from a surface-code-like circuit.
40- fn create_surface_code_sampler ( distance : usize , rounds : usize ) -> pecos_qec:: fault_tolerance:: dem_builder:: DemSampler {
40+ fn create_surface_code_sampler (
41+ distance : usize ,
42+ rounds : usize ,
43+ ) -> pecos_qec:: fault_tolerance:: dem_builder:: DemSampler {
4144 // Create a simplified surface code circuit
4245 let num_data = distance * distance;
4346 let num_ancilla = num_data - 1 ;
44- let num_qubits = num_data + num_ancilla;
47+ let _num_qubits = num_data + num_ancilla;
4548
4649 let mut dag = DagCircuit :: new ( ) ;
4750
@@ -80,7 +83,8 @@ fn create_surface_code_sampler(distance: usize, rounds: usize) -> pecos_qec::fau
8083 // Create detector definitions (one per ancilla measurement)
8184 let num_measurements = num_ancilla * rounds;
8285 let mut detector_records = Vec :: new ( ) ;
83- for i in 0 ..num_measurements. min ( 50 ) { // Limit to 50 detectors for benchmark
86+ for i in 0 ..num_measurements. min ( 50 ) {
87+ // Limit to 50 detectors for benchmark
8488 detector_records. push ( vec ! [ -( i as i32 + 1 ) ] ) ;
8589 }
8690
@@ -103,22 +107,18 @@ fn bench_sampler_comparison<M: Measurement>(c: &mut Criterion<M>) {
103107
104108 // Test different shot counts
105109 for shots in [ 1_000 , 10_000 , 100_000 ] {
106- let label = format ! ( "d{}_r{}_{}" , distance , rounds , shots ) ;
110+ let label = format ! ( "d{distance }_r{rounds }_{shots}" ) ;
107111
108112 group. throughput ( Throughput :: Elements ( ( num_mechanisms * shots) as u64 ) ) ;
109113
110114 // Original row-major sampling
111- group. bench_with_input (
112- BenchmarkId :: new ( "row_major" , & label) ,
113- & ( ) ,
114- |b, ( ) | {
115- let mut rng = PecosRng :: seed_from_u64 ( 42 ) ;
116- b. iter ( || {
117- let result = sampler. sample_batch ( shots, & mut rng) ;
118- black_box ( result)
119- } ) ;
120- } ,
121- ) ;
115+ group. bench_with_input ( BenchmarkId :: new ( "row_major" , & label) , & ( ) , |b, ( ) | {
116+ let mut rng = PecosRng :: seed_from_u64 ( 42 ) ;
117+ b. iter ( || {
118+ let result = sampler. sample_batch ( shots, & mut rng) ;
119+ black_box ( result)
120+ } ) ;
121+ } ) ;
122122
123123 // Columnar sampling (accurate - one random per shot per mechanism)
124124 group. bench_with_input (
@@ -136,8 +136,7 @@ fn bench_sampler_comparison<M: Measurement>(c: &mut Criterion<M>) {
136136
137137 // Print info
138138 println ! (
139- " d={} r={}: {} mechanisms, {} detectors" ,
140- distance, rounds, num_mechanisms, num_detectors
139+ " d={distance} r={rounds}: {num_mechanisms} mechanisms, {num_detectors} detectors"
141140 ) ;
142141 }
143142
@@ -152,7 +151,7 @@ fn bench_statistics_comparison<M: Measurement>(c: &mut Criterion<M>) {
152151 let num_mechanisms = sampler. num_mechanisms ( ) ;
153152
154153 for shots in [ 10_000 , 100_000 , 1_000_000 ] {
155- let label = format ! ( "{}shots" , shots ) ;
154+ let label = format ! ( "{shots }shots" ) ;
156155
157156 group. throughput ( Throughput :: Elements ( ( num_mechanisms * shots) as u64 ) ) ;
158157
@@ -170,17 +169,13 @@ fn bench_statistics_comparison<M: Measurement>(c: &mut Criterion<M>) {
170169 ) ;
171170
172171 // Columnar statistics
173- group. bench_with_input (
174- BenchmarkId :: new ( "columnar" , & label) ,
175- & shots,
176- |b, & shots| {
177- let mut rng = PecosRng :: seed_from_u64 ( 42 ) ;
178- b. iter ( || {
179- let result = sampler. sample_statistics_columnar ( shots, & mut rng) ;
180- black_box ( result)
181- } ) ;
182- } ,
183- ) ;
172+ group. bench_with_input ( BenchmarkId :: new ( "columnar" , & label) , & shots, |b, & shots| {
173+ let mut rng = PecosRng :: seed_from_u64 ( 42 ) ;
174+ b. iter ( || {
175+ let result = sampler. sample_statistics_columnar ( shots, & mut rng) ;
176+ black_box ( result)
177+ } ) ;
178+ } ) ;
184179 }
185180
186181 group. finish ( ) ;
@@ -285,47 +280,35 @@ fn bench_parallel_scaling<M: Measurement>(c: &mut Criterion<M>) {
285280 for ( distance, rounds) in [ ( 3 , 2 ) , ( 5 , 3 ) , ( 7 , 5 ) ] {
286281 let sampler = create_surface_code_sampler ( distance, rounds) ;
287282 let num_mechanisms = sampler. num_mechanisms ( ) ;
288- let label = format ! ( "d{}_r{}_{}mech" , distance , rounds , num_mechanisms ) ;
283+ let label = format ! ( "d{distance }_r{rounds }_{num_mechanisms }mech" ) ;
289284
290285 group. throughput ( Throughput :: Elements ( ( num_mechanisms * shots) as u64 ) ) ;
291286
292287 // Sequential geometric (baseline)
293- group. bench_with_input (
294- BenchmarkId :: new ( "sequential" , & label) ,
295- & ( ) ,
296- |b, ( ) | {
297- let mut rng = PecosRng :: seed_from_u64 ( 42 ) ;
298- b. iter ( || {
299- let result = sampler. sample_statistics_geometric ( shots, & mut rng) ;
300- black_box ( result)
301- } ) ;
302- } ,
303- ) ;
288+ group. bench_with_input ( BenchmarkId :: new ( "sequential" , & label) , & ( ) , |b, ( ) | {
289+ let mut rng = PecosRng :: seed_from_u64 ( 42 ) ;
290+ b. iter ( || {
291+ let result = sampler. sample_statistics_geometric ( shots, & mut rng) ;
292+ black_box ( result)
293+ } ) ;
294+ } ) ;
304295
305296 // Parallel
306- group. bench_with_input (
307- BenchmarkId :: new ( "parallel" , & label) ,
308- & ( ) ,
309- |b, ( ) | {
310- b. iter ( || {
311- let result = sampler. sample_statistics_parallel ( shots, 42 ) ;
312- black_box ( result)
313- } ) ;
314- } ,
315- ) ;
297+ group. bench_with_input ( BenchmarkId :: new ( "parallel" , & label) , & ( ) , |b, ( ) | {
298+ b. iter ( || {
299+ let result = sampler. sample_statistics_parallel ( shots, 42 ) ;
300+ black_box ( result)
301+ } ) ;
302+ } ) ;
316303
317304 // Auto (should pick geometric for low p)
318- group. bench_with_input (
319- BenchmarkId :: new ( "auto" , & label) ,
320- & ( ) ,
321- |b, ( ) | {
322- let mut rng = PecosRng :: seed_from_u64 ( 42 ) ;
323- b. iter ( || {
324- let result = sampler. sample_statistics_with_rng ( shots, & mut rng) ;
325- black_box ( result)
326- } ) ;
327- } ,
328- ) ;
305+ group. bench_with_input ( BenchmarkId :: new ( "auto" , & label) , & ( ) , |b, ( ) | {
306+ let mut rng = PecosRng :: seed_from_u64 ( 42 ) ;
307+ b. iter ( || {
308+ let result = sampler. sample_statistics_with_rng ( shots, & mut rng) ;
309+ black_box ( result)
310+ } ) ;
311+ } ) ;
329312 }
330313
331314 group. finish ( ) ;
@@ -336,7 +319,7 @@ fn create_synthetic_dem(num_mechanisms: usize, num_detectors: usize, prob: f64)
336319 let mut dem = String :: new ( ) ;
337320
338321 for i in 0 ..num_detectors {
339- dem. push_str ( & format ! ( "detector({}, 0, 0) D{}\n " , i , i ) ) ;
322+ dem. push_str ( & format ! ( "detector({i }, 0, 0) D{i }\n " ) ) ;
340323 }
341324
342325 for i in 0 ..num_mechanisms {
@@ -345,24 +328,27 @@ fn create_synthetic_dem(num_mechanisms: usize, num_detectors: usize, prob: f64)
345328 let d3 = ( i + 2 ) % num_detectors;
346329
347330 match i % 3 {
348- 0 => dem. push_str ( & format ! ( "error({}) D{}\n " , prob , d1 ) ) ,
349- 1 => dem. push_str ( & format ! ( "error({}) D{} D{}\n " , prob , d1 , d2 ) ) ,
350- _ => dem. push_str ( & format ! ( "error({}) D{} D{} D{}\n " , prob , d1 , d2 , d3 ) ) ,
331+ 0 => dem. push_str ( & format ! ( "error({prob }) D{d1 }\n " ) ) ,
332+ 1 => dem. push_str ( & format ! ( "error({prob }) D{d1 } D{d2 }\n " ) ) ,
333+ _ => dem. push_str ( & format ! ( "error({prob }) D{d1 } D{d2 } D{d3 }\n " ) ) ,
351334 }
352335 }
353336
354337 dem
355338}
356339
357- /// Benchmark ParsedDem sampling (used by equivalence testing).
340+ /// Benchmark ` ParsedDem` sampling (used by equivalence testing).
358341fn bench_parsed_dem_sampling < M : Measurement > ( c : & mut Criterion < M > ) {
359342 let mut group = c. benchmark_group ( "ParsedDem - Sampling" ) ;
360343
361344 let medium_dem = create_synthetic_dem ( 50 , 24 , 0.01 ) ;
362345 let complex_dem = create_synthetic_dem ( 200 , 96 , 0.01 ) ;
363346
364347 let dems: [ ( & str , & str ) ; 3 ] = [
365- ( "simple" , "error(0.01) D0\n error(0.01) D1\n error(0.01) D0 D1" ) ,
348+ (
349+ "simple" ,
350+ "error(0.01) D0\n error(0.01) D1\n error(0.01) D0 D1" ,
351+ ) ,
366352 ( "medium" , & medium_dem) ,
367353 ( "complex" , & complex_dem) ,
368354 ] ;
@@ -389,7 +375,6 @@ fn bench_parsed_dem_sampling<M: Measurement>(c: &mut Criterion<M>) {
389375
390376#[ cfg( test) ]
391377mod tests {
392- use super :: * ;
393378
394379 #[ test]
395380 fn test_sampler_creation ( ) {
0 commit comments