Add mod2 utility module#750
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
I added a test that checks for a matrix with zero rows as it wasn't being covered by existing tests. |
denialhaag
left a comment
There was a problem hiding this comment.
Hi, @orisus42! Thanks a lot for your interest in contributing to MQT QECC! 🙂
While scanning your PR, I noticed one detail, which you can find in the comment below.
I'll also go ahead and trigger a review by CodeRabbit now. We have a section in our documentation that explains a bit how to work with it: https://mqt.readthedocs.io/projects/qecc/en/latest/contributing.html#working-with-coderabbit
|
@coderabbitai full review |
✅ Action performedFull review finished. |
📝 WalkthroughSummary by CodeRabbit
WalkthroughAdds an in-repository ChangesGF(2) utility migration
Estimated code review effort: 3 (Moderate) | ~25 minutes Possibly related PRs
Suggested labels: Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches✨ Simplify code
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/mqt/qecc/circuit_synthesis/transvection.py`:
- Line 18: The phase-1 kernel row selection in the transvection logic is brittle
because nullspace() does not guarantee row order. Update the code that uses the
kernel from mod2.nullspace() to explicitly find the row with a 1 in the last
column using np.where on the kernel matrix, and fail fast if no such row exists
instead of relying on ker[-1] or ker[-1, -1]. Use the relevant transvection
function and its kernel-handling logic to locate the change.
In `@src/mqt/qecc/mod2.py`:
- Line 17: Make the `full` parameter in `row_echelon` keyword-only to eliminate
the FBT001/FBT002 warning. Update the function signature in `row_echelon` so
`full` cannot be passed positionally, and keep the existing named callsites
working since they already use `full=`. Check any nearby helpers or overloads in
`mod2.py` to ensure the API remains consistent with `row_echelon`.
In `@tests/test_mod2.py`:
- Around line 17-25: Add direct coverage for mqt.qecc.mod2 beyond row_echelon by
creating tests that call rank, nullspace, and row_basis from the internal module
instead of only exercising ldpc.mod2.mod2_numpy. Use the existing
row_echelon-style test file as the place to add a few small, deterministic
cases, and verify each function’s expected output shape/content for simple
matrices so the internal implementation is directly tested.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 159743b9-223b-44ca-a751-8d38bf59ce1b
📒 Files selected for processing (15)
src/mqt/qecc/analog_information_decoding/code_construction/code_constructor.pysrc/mqt/qecc/analog_information_decoding/code_construction/sparse_code_constructor.pysrc/mqt/qecc/analog_information_decoding/utils/simulation_utils.pysrc/mqt/qecc/circuit_synthesis/cnot.pysrc/mqt/qecc/circuit_synthesis/encoding.pysrc/mqt/qecc/circuit_synthesis/faults.pysrc/mqt/qecc/circuit_synthesis/state_prep.pysrc/mqt/qecc/circuit_synthesis/state_prep_det.pysrc/mqt/qecc/circuit_synthesis/strategy.pysrc/mqt/qecc/circuit_synthesis/transvection.pysrc/mqt/qecc/codes/css_code.pysrc/mqt/qecc/codes/pauli.pysrc/mqt/qecc/codes/stabilizer_code.pysrc/mqt/qecc/mod2.pytests/test_mod2.py
- Migrate remaining test imports (test_utils, utils, test_cat_states) from ldpc.mod2 to mqt.qecc.mod2 so the internal module fully replaces ldpc.mod2. - Make row_echelon's full parameter keyword-only and use numpy.typing.NDArray annotations (integer inputs; dtype-preserving/int_ outputs). - Locate the phase-correction kernel row explicitly in transvection.py instead of assuming nullspace row ordering (behaviour unchanged). - Add direct unit tests for rank, nullspace, row_basis and full=True mode.
The merge of main brought in the exact-synthesis engine (munich-quantum-toolkit#740), whose css_utils.py and search.py import ldpc.mod2.mod2_numpy. Migrate them to mqt.qecc.mod2 (row_echelon/nullspace) so the ldpc.mod2 removal stays complete after integrating main.
|
I see that a bunch of fixes have been made! I apologize for not looking at review comments earlier, got caught up in something. If there's anything else needed for this PR, let me know! |
|
Hey @orisus42! yes, I did some final fixes and cleanups on your changes, so it's ready to be merged. If you are interested, you can also take a look into other issues of we can also have a chat about other ideas/ways to contribute (also maybe something more interesting/practical than this refactor) 👍 |
|
If you are interested, just drop me an email: ludwig.s.schmid@tum.de |
Description
This PR resolves #735
I added a
mod2.pyfile atsrc/mqt/qecc/which replaces the dependency onldpc.mod2.mod2_numpywith an internal modulemqt.qecc.mod2implementing four functions that are currently used in the project:row_echelonranknullspacerow_basisI replaced all the imports as well from the python files. Ran existing tests after replacing the imports which worked so I didn't add any new tests, but let me know if any new tests might be needed to verify functionality properly (EDIT: Added a test for full coverage of the changes). Removed some dead functionality from the functions as well like the
scipysparse matrix input because QECC only passes a plainnp.ndarrayeverywhere.Haven't yet added any QECC specific improvements like the mentioned
StabilizerCode.compute_logical_ops()improvement in the issue but let me know if I should look into that for this PR.AI Use Disclosure: I used Claude Code (Sonnet 4.6) to assist me with improving code quality, writing the docstrings and in general reviewing the logic of translating the
mod2functions fromldpc.mod2to the internal QECCmod2utilities module. The code logic and general structure is my own where Claude helped with removing unneeded functionality from the functions specific to QECC. Everything has been tested according to the contribution guidelines. No AI generated content has been used to write any portion of the PR description.Checklist
Assisted-by: [Model Name] via [Tool Name]footer.