Skip to content

Conversation

MatthiasReumann
Copy link
Collaborator

@MatthiasReumann MatthiasReumann commented Oct 2, 2025

Description

This pull requests adds the MLIRized QMAP algorithm to the routing pass. A sub-goal of this pull request is to improve and simplify the existing implementation for performance and maintainability. The name of this "enhanced" QMAP algorithm isn't determined yet.

Noteworthy Changes

  • Router: A router now is simply a (configurable) combination of a Layerizer and a Planner.
    • The layerizer decides which gates to route.
    • The planner searches / determines the sequence of SWAPs necessary to make the gates executable.
    • The router itself simply inserts SWAPs.
    • Moreover, the router is now also the primary driver of the pass. The RoutingContext has been removed and all member variables have been moved to the router implementation. This way, I think, we should be able to use this router also for layout-ing (To be shown).
  • ThinLayout and Layout: The search nodes in the QMAP algorithm don't have to care about SSA values. Hence I added a new data structure, the ThinLayout, that simply maps program indices to hardware indices. The old Layout now inherits from this ThinLayout (Essentially a Layout is a fat ThinLayout). This way we can simply pass a Layout as ThinLayout and reduce the memory footprint of nodes.
  • Pass Statistics: I've added a statistic nadd which counts the number of SWAPs added. Using statistics, we can also quite easily track the amount of milliseconds / seconds the routing took and print it via the -mlir-pass-statistics flag.

Algorithmic Changes:
Instead of computing all layers at startup, layers are computed on-demand. Moreover, the algorithm simply "steps over" already executable gates and doesn't include them in a layer (which to my knowledge the previous algorithm didn't). In other words, a layer always starts with a non-executable gate and crawls its way forward.

The (updated) cost function is

$$f\left(x\right) = \left(\alpha \cdot n_{swaps}\right) + \left(\beta \cdot n_{depth}\right) + \frac{1}{|gates|}\sum_{g \in gates}D[\pi(g.q1)][\pi (g.q2)] + \frac{\lambda}{|lookahead|}\sum_{g \in lookahead}D[\pi(g.q1)][\pi (g.q2)]$$

where $$n_{swaps}$$ is the number of swaps added, $$n_{depth}$$ is the additional "circuit" depth added by the swaps, and $$D$$ is the nearest neighbor length between $$g.q1$$ and $$g.q2$$.

$$\alpha, \beta, \gamma$$ are configurable variables.

Checklist:

  • The pull request only contains commits that are focused and relevant to this change.
  • I have added appropriate tests that cover the new/changed functionality.
  • I have updated the documentation to reflect these changes.
  • I have added entries to the changelog for any noteworthy additions, changes, fixes, or removals.
  • I have added migration instructions to the upgrade guide (if needed).
  • The changes follow the project's style guidelines and introduce no new warnings.
  • The changes are fully tested and pass the CI checks.
  • I have reviewed my own code changes.

@MatthiasReumann MatthiasReumann changed the title 🚧 MLIR | Implement / Integrate QMAP Algorithm 🚧 MLIR | Implement QMAP Algorithm Oct 2, 2025
Copy link

codecov bot commented Oct 3, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant