munich-quantum-toolkit / munich-quantum-toolkit/qmap
Refactor RearrangementGenerator load/store methods to reduce complexity and duplication
@ystade is already working on this.
Since Dec 3, 2025.
- Dominant language
- C++
- Stars
- 146
- Forks
- 41
- Avg merge
- 6h 47m
- Merged PRs (30d)
- 45
Description
Context
This issue tracks a follow-up refactoring task identified during review of PR #848.
Problem
The loadRowByRow, loadColumnByColumn, storeRowByRow, and storeColumnByColumn methods in src/na/zoned/code_generator/CodeGenerator.cpp are quite large (100-300 lines each) and contain substantial duplicated structure:
- Row vs. column variants share similar logic
- Storage vs. entanglement handling has near-duplicate patterns
- "Pack additional rows/columns if mapped sets match" logic is repeated
- Virtual offset and neighbor-pushing logic appears across all four methods
This complexity makes it hard to reason about correctness and has contributed to subtle bugs in the past.
Proposed Solution
Extract shared patterns into reusable helpers, for example:
buildCoordinateToAodIndex- Common mapping creation from keys to AOD indicescollectQubitsPerLine- Materialize x/y → setapplyVirtualOffsetAndPushNeighbors- Handle virtual offset insertion and neighboring push logic with min/max bounds, parameterized by axis and site kindpackCompatibleLines- Merge additional adjacent lines when isSameMappedSet matches
Then refactor the four large methods to call these helpers with axis/site-specific lambdas.
Requirements
- Observable behavior must remain identical
- Add focused unit tests for each helper (especially neighbor-push and packing)
- Reduce duplication between row/column variants
- Lower the chance of future copy-paste errors
References
- Original PR: #848
- Discussion: https://github.com/munich-quantum-toolkit/qmap/pull/848#discussion_r2576777825
- Requested by: @ystade
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.