Consolidate duplicate distance searches and parallelize the search engine - #439
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #415 (base
code-distance-rust); retarget todevonce that merges.Consolidation
PECOS had two independent implementations of the same weight-increasing search:
calculate_distance/find_shortest_logicalsinpecos-qec/src/distance.rs, andhas_undetectable_logical/compute_distanceinfault_tolerance/stabilizer_flip_checker.rswith 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_weightcovers 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_stringhelpers are deliberately retained:analyze_weightstill needs them for configurable X/Y/Z subsets thatWeightedPauliIteratordoes 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_distancereturns the same operator the serial search returned andfind_shortest_logicalsreturns 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_536candidates 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.calculate_distancefive-qubit [[5,1,3]]calculate_distanceSteane [[7,1,3]]calculate_distancecolor [[17,1,5]]find_shortest_logicalsdelta=1, color [[17,1,5]]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 failuresjust build-debug,just lint(with new files staged so pre-commit sees them): cleanuv run --frozen pyteston the stabilizer-code binding suites: 28 passed