Skip to content

Commit 1bf0581

Browse files
committed
cleanup
1 parent 33d2860 commit 1bf0581

68 files changed

Lines changed: 2297 additions & 1452 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

crates/benchmarks/benches/modules/dem_sampler.rs

Lines changed: 54 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -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).
358341
fn 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\nerror(0.01) D1\nerror(0.01) D0 D1"),
348+
(
349+
"simple",
350+
"error(0.01) D0\nerror(0.01) D1\nerror(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)]
391377
mod tests {
392-
use super::*;
393378

394379
#[test]
395380
fn test_sampler_creation() {

crates/pecos-cuquantum/build.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,17 @@
66
fn main() {
77
// cuQuantum
88
if let Some(cuquantum_path) = pecos_build::cuquantum::find_cuquantum()
9-
&& let Some(lib_dir) = pecos_build::cuquantum::get_lib_dir(&cuquantum_path) {
10-
println!("cargo:rustc-link-arg=-Wl,-rpath,{}", lib_dir.display());
11-
}
9+
&& let Some(lib_dir) = pecos_build::cuquantum::get_lib_dir(&cuquantum_path)
10+
{
11+
println!("cargo:rustc-link-arg=-Wl,-rpath,{}", lib_dir.display());
12+
}
1213

1314
// cuTensor (transitive dependency of cuTensorNet)
1415
if let Ok(cutensor_path) = pecos_build::cutensor::ensure_cutensor()
15-
&& let Some(lib_dir) = pecos_build::cutensor::get_lib_dir(&cutensor_path) {
16-
println!("cargo:rustc-link-arg=-Wl,-rpath,{}", lib_dir.display());
17-
}
16+
&& let Some(lib_dir) = pecos_build::cutensor::get_lib_dir(&cutensor_path)
17+
{
18+
println!("cargo:rustc-link-arg=-Wl,-rpath,{}", lib_dir.display());
19+
}
1820

1921
// CUDA runtime
2022
if let Some(cuda_path) = pecos_build::cuda::find_cuda() {

crates/pecos-cuquantum/src/statevec.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,10 @@ impl CliffordGateable for CuStateVec {
596596
}
597597

598598
fn cx(&mut self, qubits: &[QubitId]) -> &mut Self {
599-
debug_assert!(qubits.len().is_multiple_of(2), "CX requires pairs of qubits");
599+
debug_assert!(
600+
qubits.len().is_multiple_of(2),
601+
"CX requires pairs of qubits"
602+
);
600603
// CNOT matrix (4x4)
601604
// [[1,0,0,0], [0,1,0,0], [0,0,0,1], [0,0,1,0]]
602605
#[rustfmt::skip]
@@ -652,7 +655,10 @@ impl CliffordGateable for CuStateVec {
652655
}
653656

654657
fn cz(&mut self, qubits: &[QubitId]) -> &mut Self {
655-
debug_assert!(qubits.len().is_multiple_of(2), "CZ requires pairs of qubits");
658+
debug_assert!(
659+
qubits.len().is_multiple_of(2),
660+
"CZ requires pairs of qubits"
661+
);
656662
// CZ matrix (4x4)
657663
// [[1,0,0,0], [0,1,0,0], [0,0,1,0], [0,0,0,-1]]
658664
#[rustfmt::skip]
@@ -669,7 +675,10 @@ impl CliffordGateable for CuStateVec {
669675
}
670676

671677
fn swap(&mut self, qubits: &[QubitId]) -> &mut Self {
672-
debug_assert!(qubits.len().is_multiple_of(2), "SWAP requires pairs of qubits");
678+
debug_assert!(
679+
qubits.len().is_multiple_of(2),
680+
"SWAP requires pairs of qubits"
681+
);
673682
// SWAP matrix (4x4)
674683
// [[1,0,0,0], [0,0,1,0], [0,1,0,0], [0,0,0,1]]
675684
#[rustfmt::skip]
@@ -713,7 +722,10 @@ impl ArbitraryRotationGateable for CuStateVec {
713722

714723
fn rzz(&mut self, theta: Angle64, qubits: &[QubitId]) -> &mut Self {
715724
let theta = theta.to_radians_signed();
716-
debug_assert!(qubits.len().is_multiple_of(2), "RZZ requires pairs of qubits");
725+
debug_assert!(
726+
qubits.len().is_multiple_of(2),
727+
"RZZ requires pairs of qubits"
728+
);
717729
// RZZ(theta) = diag(e^(-i*theta/2), e^(i*theta/2), e^(i*theta/2), e^(-i*theta/2))
718730
let c = (theta / 2.0).cos();
719731
let s = (theta / 2.0).sin();

crates/pecos-decoders/src/lib.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,32 +22,32 @@ pub use pecos_decoder_core::{
2222
pub use pecos_ldpc_decoders::{
2323
// Builders
2424
BeliefFindBuilder,
25-
BpLsdBuilder,
26-
BpOsdBuilder,
27-
FlipBuilder,
28-
SoftInfoBpBuilder,
29-
UnionFindBuilder,
3025
// Decoders
3126
BeliefFindDecoder,
27+
BpLsdBuilder,
3228
BpLsdDecoder,
33-
BpOsdDecoder,
34-
FlipDecoder,
35-
SoftInfoBpDecoder,
36-
UnionFindDecoder,
3729
// Types
3830
BpMethod,
31+
BpOsdBuilder,
32+
BpOsdDecoder,
3933
BpSchedule,
4034
ClusterStatistics,
4135
CssCode,
4236
DecodingResult as LdpcDecodingResult,
37+
FlipBuilder,
38+
FlipDecoder,
4339
InputVectorType,
4440
// Errors
4541
LdpcError,
4642
LsdStatistics,
4743
MbpDecoder,
4844
OsdMethod,
45+
SoftInfoBpBuilder,
46+
SoftInfoBpDecoder,
4947
SparseMatrix,
5048
UfMethod,
49+
UnionFindBuilder,
50+
UnionFindDecoder,
5151
};
5252

5353
// Re-export Fusion Blossom decoder when feature is enabled

crates/pecos-ldpc-decoders/src/builders.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,37 +95,37 @@ impl<'a> BpOsdBuilder<'a> {
9595
self
9696
}
9797

98-
/// Set the BP method (ProductSum or MinimumSum)
98+
/// Set the BP method (`ProductSum` or `MinimumSum`)
9999
pub fn bp_method(mut self, method: BpMethod) -> Self {
100100
self.bp_method = method;
101101
self
102102
}
103103

104-
/// Set the BP schedule (Serial, Parallel, or SerialRelative)
104+
/// Set the BP schedule (Serial, Parallel, or `SerialRelative`)
105105
pub fn bp_schedule(mut self, schedule: BpSchedule) -> Self {
106106
self.bp_schedule = schedule;
107107
self
108108
}
109109

110-
/// Set the minimum-sum scaling factor (only used with MinimumSum)
110+
/// Set the minimum-sum scaling factor (only used with `MinimumSum`)
111111
pub fn ms_scaling_factor(mut self, factor: f64) -> Self {
112112
self.ms_scaling_factor = factor;
113113
self
114114
}
115115

116-
/// Set the OSD method (Off, Osd0, OsdE, or OsdCs)
116+
/// Set the OSD method (Off, Osd0, `OsdE`, or `OsdCs`)
117117
pub fn osd_method(mut self, method: OsdMethod) -> Self {
118118
self.osd_method = method;
119119
self
120120
}
121121

122-
/// Set the OSD order (only used with OsdE or OsdCs)
122+
/// Set the OSD order (only used with `OsdE` or `OsdCs`)
123123
pub fn osd_order(mut self, order: usize) -> Self {
124124
self.osd_order = order;
125125
self
126126
}
127127

128-
/// Set the input vector type (Syndrome, ReceivedVector, or Auto)
128+
/// Set the input vector type (Syndrome, `ReceivedVector`, or Auto)
129129
pub fn input_vector_type(mut self, input_type: InputVectorType) -> Self {
130130
self.input_vector_type = input_type;
131131
self
@@ -540,7 +540,7 @@ impl<'a> UnionFindBuilder<'a> {
540540

541541
/// Builder for `BeliefFindDecoder`
542542
///
543-
/// BeliefFind combines BP with Union-Find: it first tries BP, and if that fails
543+
/// `BeliefFind` combines BP with Union-Find: it first tries BP, and if that fails
544544
/// to converge, it falls back to Union-Find using the soft information from BP.
545545
#[must_use]
546546
pub struct BeliefFindBuilder<'a> {

crates/pecos-ldpc-decoders/src/decoders.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -955,9 +955,9 @@ pub struct BeliefFindDecoder {
955955
}
956956

957957
impl BeliefFindDecoder {
958-
/// Create a builder for configuring a new BeliefFind decoder
958+
/// Create a builder for configuring a new `BeliefFind` decoder
959959
///
960-
/// BeliefFind combines BP with Union-Find: it first tries BP, and if that
960+
/// `BeliefFind` combines BP with Union-Find: it first tries BP, and if that
961961
/// fails to converge, it falls back to Union-Find using soft information from BP.
962962
#[must_use]
963963
pub fn builder(pcm: &SparseMatrix) -> crate::builders::BeliefFindBuilder<'_> {

0 commit comments

Comments
 (0)