Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions crates/benchmarks/benches/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use criterion::{Criterion, criterion_group, criterion_main};

mod modules {
pub mod allocation_overhead;
pub mod code_distance;
pub mod cpu_stabilizer_comparison;
pub mod dem_builder;
pub mod dem_sampler;
Expand Down Expand Up @@ -58,14 +59,15 @@ use modules::sparse_stab_vs_cpp;
#[cfg(feature = "stab-tn")]
use modules::stab_mps_vs_stab_vec;
use modules::{
allocation_overhead, cpu_stabilizer_comparison, dem_builder, dem_sampler, dod_statevec,
fault_catalog, measurement_sampling, native_statevec_comparison, noise_models,
allocation_overhead, code_distance, cpu_stabilizer_comparison, dem_builder, dem_sampler,
dod_statevec, fault_catalog, measurement_sampling, native_statevec_comparison, noise_models,
pecos_neo_comparison, quizx_eval, rng, set_ops, sparse_stab_w_vs_y, sparse_state_vec, stab_vec,
stabilizer_sims, state_vec_sims, surface_code, tick_circuit_layout, trig,
};

fn all_benchmarks(c: &mut Criterion) {
allocation_overhead::benchmarks(c);
code_distance::benchmarks(c);
stab_vec::benchmarks(c);
cpu_stabilizer_comparison::benchmarks(c);
quizx_eval::benchmarks(c);
Expand Down
89 changes: 89 additions & 0 deletions crates/benchmarks/benches/modules/code_distance.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// Copyright 2026 The PECOS Developers
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
// in compliance with the License. You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the License
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
// or implied. See the License for the specific language governing permissions and limitations under
// the License.

//! Exhaustive code-distance search benchmarks.

use criterion::{Criterion, measurement::Measurement};
use pecos_core::{Xs, Zs};
use pecos_qec::{
DistanceSearchConfig, StabilizerCode, StabilizerCodeSpec, calculate_distance,
find_shortest_logicals,
};
use std::hint::black_box;

pub fn benchmarks<M: Measurement>(c: &mut Criterion<M>) {
eprintln!(
"code-distance benchmark available parallelism: {}",
std::thread::available_parallelism().map_or(1, std::num::NonZero::get)
);

let five_qubit = standard_code_spec(&StabilizerCode::five_qubit());
let steane = standard_code_spec(&StabilizerCode::steane());
let toric_3 = standard_code_spec(&StabilizerCode::toric(3));
let color_17 = color_code_17();
let config = DistanceSearchConfig::default();

let mut group = c.benchmark_group("code_distance/calculate_distance");
group.sample_size(10);
group.bench_function("five_qubit_5_1_3", |b| {
b.iter(|| calculate_distance(black_box(&five_qubit), black_box(&config)));
});
group.bench_function("steane_7_1_3", |b| {
b.iter(|| calculate_distance(black_box(&steane), black_box(&config)));
});
group.bench_function("toric_3_18_2_3", |b| {
b.iter(|| calculate_distance(black_box(&toric_3), black_box(&config)));
});
group.bench_function("color_17_1_5", |b| {
b.iter(|| calculate_distance(black_box(&color_17), black_box(&config)));
});
group.finish();

let mut group = c.benchmark_group("code_distance/find_shortest_logicals");
group.sample_size(10);
group.bench_function("color_17_1_5_delta_1", |b| {
b.iter(|| find_shortest_logicals(black_box(&color_17), black_box(&config), 1));
});
group.finish();
}

fn standard_code_spec(code: &StabilizerCode) -> StabilizerCodeSpec {
StabilizerCodeSpec::from_stabilizer_code(code)
.expect("standard stabilizer code should have discoverable logicals")
}

fn color_code_17() -> StabilizerCodeSpec {
const SUPPORTS: [&[usize]; 8] = [
&[0, 9, 12, 15],
&[1, 9, 12, 16],
&[2, 11, 13, 14],
&[3, 8, 9, 12],
&[4, 8, 10, 12, 13, 14, 15, 16],
&[5, 10, 11, 13],
&[6, 8, 9, 10, 13, 14, 15, 16],
&[7, 10, 11, 14],
];

let mut builder = StabilizerCodeSpec::builder(17);
for support in SUPPORTS {
builder = builder.check(Xs(support));
}
for support in SUPPORTS {
builder = builder.check(Zs(support));
}

builder
.logical_x(Xs(0..17))
.logical_z(Zs(0..17))
.build()
.expect("[[17,1,5]] color code should be valid")
}
Loading