-
-
Notifications
You must be signed in to change notification settings - Fork 31
Open
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: ✨ [NA] Enable Code Generation for Relaxed Routing Constraints #848
- Discussion: ✨ [NA] Enable Code Generation for Relaxed Routing Constraints #848 (comment)
- Requested by: @ystade
Metadata
Metadata
Assignees
Labels
No labels