Repository navigation
Reorganize qldpc.codes.distance into subpackages by method - #845
Merged
Merged
Conversation
Split `_search/` by role. Each method gets one home: `_brute_force.py`, `_brouwer_zimmermann/` (the distance search, its packed instances, the compiled scans of layers, and the coset routes), and `_connected_support/search.py`. The information-set machinery that the searches and counts share moves to `_information_sets/`, where `information_sets.py` splits into `basis_families.py`, `certificates.py`, and `support_stepping.py`. `coset_leader_search.py` moves up to `_coset_leader_search.py`, the private entry module of the coset-leader search. The moves change no behavior. Imports, test helpers, the layers that `layering_test.py` enforces, and the paths that the guides cite follow the new layout. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
`_coset_leader_search.py` keeps `CosetLeaderSearch` and the queries that split a syndrome class into coset searches. The coset searches move to their methods: the Brouwer-Zimmermann ones to `_brouwer_zimmermann/coset.py`, with the tables of their steps and tails in `_brouwer_zimmermann/coset_tables.py`, and the connected-support ones to `_connected_support/coset.py`. What both methods share, including `MinWeightBound`, moves to `_cosets.py`, a layer below the methods. External modules still import from `_coset_leader_search.py`. The tests follow their code, and helpers that several test files use move to `conftest.py`. The moves change no behavior. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Each module must be fully covered by its own test file, and the splits left code that only other modules' tests reached. Add direct tests of the shared coset parts in `_cosets.py`, of the search tables and first steps in `coset_tables.py`, of BZ coset searches by CSS weight, of the certificate checks and work estimates for arrays in `certificates.py`, and of batches of connected-support searches by CSS weight. Two tests of `CosetLeaderSearch` itself move back to its test file. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The README gains a short account of the layout, and its map of where to look and its levels of dependency follow the subpackages, with the order of the modules within each. The code maps of both guides, the module docstrings that described the old modules, and the references of the form `module.name` name the modules where the code now lives. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The splits made 22 underscore names of the new private modules cross module boundaries, and `_WORK_CAP` already did. The code standard asks private modules to use plain names for what other modules use, so these lose their underscore. Two get clearer names: `_CosetSearch` becomes `BrouwerZimmermannCosetSearch`, beside `ConnectedSupportCosetSearch`, and `_get_inverse` becomes `get_unit_syndrome_words`, since its rows are the transpose of a right inverse. `_packed_row_int` becomes `words_to_int`, the inverse of `int_to_words`. `_get_planning` moves after the plain names of `coset_tables.py`. The helpers that several test files share also get plain names, as the other helpers of `distance/conftest.py` have, in a section of their own. No behavior changes. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
perlinm
force-pushed
the
refactor/distance-layout
branch
from
November 12, 2026 15:31
9caa2a8 to
f50c87e
Compare
Docstrings and comments that cite code in another module now give its path, and paragraphs that the edits left ragged are filled. The README describes `_binary.py` and `_counting/` precisely, says that the method name "information_sets" is an alias of "brouwer_zimmermann", and its levels of dependency name the modules without repeating the layout. The code map of the coset searches moves to the end of Section 4.1 of `brouwer_zimmermann.md`, after the terms that it uses, and the tests that the guide cites without a file name their files. Text that called the words with unit syndromes the rows of a right inverse now says what they are. Three test helpers get names that say what they do: `get_product_state` merges into `get_stabilizer_matrix`, which now takes strings too, and `get_css_minima`, which also gives physical weights, becomes `get_exhaustive_minima`, whose callers now pass the weight. The private attributes of `CosetLeaderSearch` that hold its coset searches are named for their methods: `_brouwer_zimmermann_searches` and `_connected_support_searches`. `tabulate_singles` keeps the first word of each syndrome, with X before Z before Y on each qubit. New cases check that order where words on one qubit, or Z errors on two qubits, share a syndrome. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The tests of the import layers of `qldpc.circuits`, `qldpc.decoders`, and `qldpc.codes.distance` test no module of their own, so they get a leading underscore, as `_code_style_test.py` has. The package docstrings, the README of the distance package, the code and decoder standards, and the message that `check_import_layering` prints cite the new names. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
perlinm
force-pushed
the
refactor/distance-layout
branch
from
November 12, 2026 15:43
f50c87e to
3d6922b
Compare
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.
Motivation
The review of
qldpc.codes.distancethat led to #841 also looked at how the package is organized. The package had one_search/subpackage that mixed the drivers of three methods, the information-set machinery that they share, and compiled kernels. Its order was a convention that no test checked. Two hub modules each held several concepts:information_sets.py(1,199 lines) held basis families, certificates, step planning, and the support stepping of every scan, andcoset_leader_search.py(2,210 lines) held the coset-leader query, the Brouwer–Zimmermann coset searches, their tables and tails, the connected-support coset searches, and the helpers they share. Modules outside the package imported the coset-leader search from that deep private path. This PR changes no behavior. It moves code so that each concept that a user or a change request names has one obvious module, and the layers of the package are checked by its layering test.Changes
Layout. The top level of
distance/holds the entry modules (core.py,logical_counts.py, and the private_coset_leader_search.py, whichcircuits/certificationand the experimental residual-weight estimator import),_brute_force.py,_cosets.py,_tuning.py, and_binary.py. The machinery goes into private subpackages:_brouwer_zimmermann/: the distance search (distance.py), the coset searches (coset.py) with their tables and tails (coset_tables.py) and routes (coset_routes.py), and the packed instances and compiled scans that both share;_connected_support/: the search (search.py) and its coset searches (coset.py);_information_sets/:information_sets.pysplit intobasis_families.py,certificates.py, andsupport_stepping.py, beside the existing automorphism-family, completion-bound, and matroid-partition modules;_counting/: unchanged.The README of the package gains a short account of the layout, and its map and dependency levels follow it.
Layers. The layering test of the package, now
_layering_test.py, orders_binary,_tuning, (_brute_force,_information_sets,_cosets), (_brouwer_zimmermann,_connected_support,_counting), (_coset_leader_search,core), andlogical_counts. A unit may import only from itself and lower layers, so the test also records that the methods are independent of each other, and the two entry modules too.Commits 1 and 2 are moves. Moved objects keep their names and bodies, so
git diff -M --color-moved=dimmed-zebrashows them as moves. Imports, string patch targets, and test helpers follow the code.Commit 3 adds tests so that each new module is fully covered by its own test file, as the coverage gate requires. Commit 4 updates the guides, docstrings, and
module.namereferences.Commit 5 renames. The code standard asks private modules to use plain names for what other modules use, so the 23 underscore names that now cross module boundaries lose their underscore, such as
get_stopping_stepandWORK_CAP. Three get clearer names: the Brouwer–Zimmermann coset search becomesBrouwerZimmermannCosetSearch, besideConnectedSupportCosetSearch;_get_inversebecomesget_unit_syndrome_words, since its rows are the transpose of a right inverse; and_packed_row_intbecomeswords_to_int, the inverse ofint_to_words. The test helpers that several test files now share get plain names too.Commit 6 holds the revisions after review: references that the splits left pointing into other modules now give their paths, a few test helpers and private attributes get names that say what they do, the README and guides are tidied, and new cases test the order in which the tables of single errors keep their words.
Commit 7 renames the layering tests of
qldpc.circuits,qldpc.decoders, andqldpc.codes.distanceto_layering_test.py, like_code_style_test.py, since they test no module of their own.Validation
distance/,circuits/certification, the residual-weight estimator, and the style and compilation tests.core.pyor_coset_leader_search.py.Notes
_connected_support/search.pykeeps its distance driver, which is about 110 lines over the shared search; the basis-family transport stays in_counting/scan.py;CosetRouteskeeps its generic parameters, which let its tests use light stand-ins for the tables and tails; and_coset_leader_search.pystill builds the cache keys of the Brouwer–Zimmermann coset searches itself, which factories in_brouwer_zimmermann/coset.pycould hide in a later change._connected_support/coset_test.py, whose module defines no compiled functions, so the--compiled-module-testsrun no longer collects them. They still run compiled in the--compile-search-setuprun of the distance tests, which compiles all compiled code.