Skip to content

Expose Rust stabilizer-code distance search and verification workflow to Python - #415

Open
ciaranra wants to merge 3 commits into
devfrom
code-distance-rust
Open

Expose Rust stabilizer-code distance search and verification workflow to Python#415
ciaranra wants to merge 3 commits into
devfrom
code-distance-rust

Conversation

@ciaranra

@ciaranra ciaranra commented Aug 3, 2026

Copy link
Copy Markdown
Member

Summary

The incremental-weight distance search in pecos-qec (calculate_distance, find_min_weight_logicals_with_info, CSS modes) and the StabilizerCodeSpec verification machinery were fully implemented in Rust but had no Python bindings and no callers. This PR exposes them, giving Python users a supported replacement for the legacy pecos.analysis.VerifyStabilizers development workflow.

New in pecos.quantum:

  • StabilizerCodeSpec: hand construction, from_stabilizer_code(...), plus getters for stabilizers, destabilizers, and paired logical operators. str(spec) prints an [[n, k]] summary with all generators.
  • StabilizerCodeSpec.builder(n): check(op), logical_z(op), logical_x(op), and three build modes — build(), build_verified() (errors name the exact anticommuting generator pair), and build_with_discovered_logicals() (derives paired logicals and destabilizers via stabilizer simulation).
  • spec.distance(max_weight=None, css=False) returning DistanceResult, and spec.min_weight_logicals() returning operators with logical-equivalence info ("X0*Z1"). The search grows error weight from 1, so cost scales with the distance rather than with qubit count, reaching codes the existing StabilizerCode.distance() coset enumeration (capped at k + rank <= 30) cannot.
  • Xs, Ys, Zs multi-qubit Pauli helpers, so checks read as Zs([0, 1]) * Y(2).

Removed: pecos/tools/fault_tolerance_checks.py and pecos/tools/stabilizer_verification.py, byte-identical dead copies of the pecos.analysis modules; pecos.tools has been a deprecation shim re-exporting pecos.analysis and these files were unreachable through the public path.

pecos.analysis.VerifyStabilizers itself is left untouched; retiring it and updating the legacy rst docs are follow-ups once this API has settled.

Verification

  • cargo test -p pecos-qec: all unit, integration, and doc tests pass.
  • New binding tests (17) cross-check the weight search against StabilizerCode.distance() as an exact oracle on the Steane, five-qubit, and Shor codes, and confirm found operators are genuine logicals via syndrome checks.
  • A parity test replays the full docs/examples/stab_code_verification.rst storyline: the invalid check set is rejected with a genuinely anticommuting pair identified, the corrected set yields a [[10, 3, 2]] code, and the final set yields [[10, 1, 3]].
  • just build-debug, full binding test files (32 passed), and whole-repo just lint all clean.

@ciaranra ciaranra added the enhancement New feature or request label Aug 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant