munich-quantum-toolkit / munich-quantum-toolkit/qmap

Refactor RearrangementGenerator load/store methods to reduce complexity and duplication

Open
#858 1 comment 0 reactions 1 assignee View on GitHub

@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:

  1. buildCoordinateToAodIndex - Common mapping creation from keys to AOD indices
  2. collectQubitsPerLine - Materialize x/y → set
  3. applyVirtualOffsetAndPushNeighbors - Handle virtual offset insertion and neighboring push logic with min/max bounds, parameterized by axis and site kind
  4. packCompatibleLines - 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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.