Skip to content

Consolidate duplicate distance searches and parallelize the search engine - #439

Merged
ciaranra merged 1 commit into
code-distance-rustfrom
distance-consolidation
Aug 5, 2026
Merged

Consolidate duplicate distance searches and parallelize the search engine#439
ciaranra merged 1 commit into
code-distance-rustfrom
distance-consolidation

Conversation

@ciaranra

@ciaranra ciaranra commented Aug 5, 2026

Copy link
Copy Markdown
Member

Stacked on #415 (base code-distance-rust); retarget to dev once that merges.

Consolidation

PECOS had two independent implementations of the same weight-increasing search: calculate_distance/find_shortest_logicals in pecos-qec/src/distance.rs, and has_undetectable_logical/compute_distance in fault_tolerance/stabilizer_flip_checker.rs with its own enumeration helpers.

Their predicates were verified equivalent -- both test "commutes with every stabilizer generator AND anticommutes with at least one configured logical Z or X" -- so the checker methods now delegate to the shared engine. A new has_logical_error_at_weight covers the exact-weight case the checker needs. The checker's existing unit tests are unchanged and act as the regression guard.

The combinations/pauli_product/build_pauli_string helpers are deliberately retained: analyze_weight still needs them for configurable X/Y/Z subsets that WeightedPauliIterator does not express.

Parallel search

The per-weight candidate scan now runs on rayon, partitioned across support combinations with Pauli assignments enumerated serially within each support. Output is bit-identical to the serial path rather than merely equivalent: reduction is on enumeration index, so calculate_distance returns the same operator the serial search returned and find_shortest_logicals returns the same vector in the same order. Tests cover both the serial and the parallel branch.

Parallelism engages per weight, not per code, so a large code's cheap low weights stay serial.

Measured results

PARALLEL_CANDIDATE_THRESHOLD = 65_536 candidates at a single weight, derived from a sweep rather than chosen by intuition. Below roughly 22k candidates parallelism loses -- forcing the toric [[18, 2, 3]] weight-3 tier (22,032 candidates) parallel made that search 4.6x slower. Above roughly 193k it stops engaging where the time is spent -- the color [[17, 1, 5]] search is dominated by its weight-4 tier (192,780 candidates), and a threshold past that erased the speedup entirely. The chosen value sits near the geometric centre of that window.

Benchmark Serial Parallel Effect
calculate_distance five-qubit [[5,1,3]] 7.70 us 8.46 us 9.9% slower
calculate_distance Steane [[7,1,3]] 15.04 us 16.83 us 11.9% slower
calculate_distance color [[17,1,5]] 41.7 ms 8.6 ms 4.8x faster
find_shortest_logicals delta=1, color [[17,1,5]] 2.77 s 215 ms 12.9x faster

This is a trade, not a free win: microsecond-scale searches pay about 10% for the per-weight threshold check, while the searches long enough for a user to wait on improve by 5-13x. Small-code numbers were confirmed with an A/B/A run after an initial measurement proved to be machine drift.

Adds crates/benchmarks/benches/modules/code_distance.rs; no distance benchmark existed before this.

Verification

  • cargo test -p pecos-qec -p pecos-quantum: 22 test groups, zero failures
  • just build-debug, just lint (with new files staged so pre-commit sees them): clean
  • uv run --frozen pytest on the stabilizer-code binding suites: 28 passed

@ciaranra
ciaranra merged commit 36c9f25 into code-distance-rust Aug 5, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant