Modular restructuring of the package
Refactor Plan (Updated with Completed Changes)
This plan captures the key refactors and API changes implemented so far.
Summary of Key Revisions
- Added modular circuit-construction strategies under
qldpc_code/circuit_construction/. - Introduced
build_circuit(...)as the primary entrypoint, withbuild_graph(...)retained only as a deprecated wrapper. - Added new code family: Lift-connected surface code (
LscCode) and tests. - Renamed
QlpCode2toQlpPolyCodeand updated exports/usages. - Updated tests and notebooks to use
build_circuitinstead ofbuild_graph. - Added canonical logical controls and verbose logging for HGP/BPC.
- Adjusted CSS logical verification criteria and pairing checks.
Current Target Layout
src/quits/
__init__.py
api.py
circuit.py
decoder/
__init__.py
base.py
bposd.py
bplsd.py
sliding_window.py
qldpc_code/
__init__.py
base.py
hgp.py
qlp.py
bpc.py
lsc.py
circuit_construction/
__init__.py
base.py
cardinal.py
xzcoloration.py
freeform.py
gf2_util.py
ldpc_util.py
simulation.py
Implemented Changes (Details)
Circuit construction modularity
- Added
qldpc_code/circuit_construction/with a strategy registry and base interface. - Implemented
CardinalBuilder; added placeholders forXZColorationBuilderandFreeformBuilder. - Moved cardinal graph-building helpers into
CardinalBuilder. QldpcCode.build_circuit()delegates to the selected builder.build_graph()now warns viaDeprecationWarningand callsbuild_circuit(strategy="cardinal", ...).
Code-family updates
HgpCode,QlpCode,QlpPolyCode, andBpcCodeoverridebuild_circuit(...)for the cardinal strategy.QlpCode2renamed toQlpPolyCode(exports updated inqldpc_code/__init__.pyandapi.py).- Added
LscCodeinqldpc_code/lsc.py, parameterized bylift_size(L) andlength(l+1).
Canonical logicals + verbose mode
HgpCodeandBpcCodeacceptverbose; print when canonical logicals are used.HgpCode.get_logicalsrenamed toget_canonical_logicals.BpcCode.get_logicalsrenamed toget_canonical_logicals.BpcCodecanonical logicals now:- Mix Z logicals (default) to enforce weight 2*q.
- Re-pair LX/LZ to make pairing identity.
- Optionally swap to make X logicals weight 2*q (
canonical_weight="x").
CSS logical verification
verify_css_logicalsnow computes pairing using overlap parity (mod 2).pairing_is_identityis required forreport["ok"].- Style updated to store
pairing_is_identityin a local variable like other checks.
Tests and docs
- Tests now call
build_circuit(...)(includingtests/test_codes.py,tests/test_circuit.py, etc.). - Added
LscCodetest insidetests/test_codes.py. - Notebooks updated:
- All
build_graph→build_circuitin docs. 01_codes_basics.ipynbincludes canonical-logicals explanation + print cells for HGP/BPC.old_intro.ipynbupdated toQlpPolyCode.
- All
doc/circuit_distance_search.pyupdated tobuild_circuit.
Compatibility Strategy (Current)
build_graphstill exists as a deprecated wrapper to avoid immediate breakage.- Public imports are maintained via
qldpc_code/__init__.pyandapi.py.
Suggested Next Steps
- Implement
XZColorationBuilderandFreeformBuilder. - Optionally add a small helper to compute full pairing matrices for diagnostics.
- Consider deprecating/removing
build_graphafter a transition period.
Full Changelog: v0.4.0...v0.5.0