Skip to content

Commit 9d4f091

Browse files
✨ Improve Mapping Pass (#1600)
## Description This pull request updates the mapping pass in various ways: 1) Use `walkProgramGraph` driver - Benefit: Code quality and code duplication 2) Compute layers on demand - Benefit: Memory 3) Use trials to improve initial layout and perform final "hot" routing left-to-right pass - Benefit: Memory - No more auxiliary data structure for each trial. 4) Remove unnecessary overhead of `LayoutInfo` and simply use the program-to-hardware vector as map key. - Benefit: Memory 5) Injectable Architecture - Benefit: Easier benchmarking and testing. 6) Single `route` function for cold and hot routing - Benefit: Code duplication and maintenance later on. 7) Optimized for "individual gates" strategy. - For "utility-scale" circuits finding solution for full layers is impractical in terms of runtime. ## Checklist <!--- This checklist serves as a reminder of a couple of things that ensure your pull request will be merged swiftly. --> - [x] The pull request only contains commits that are focused and relevant to this change. - [x] I have added appropriate tests that cover the new/changed functionality. - [x] I have updated the documentation to reflect these changes. - [x] I have added entries to the changelog for any noteworthy additions, changes, fixes, or removals. - [x] I have added migration instructions to the upgrade guide (if needed). - [x] The changes follow the project's style guidelines and introduce no new warnings. - [x] The changes are fully tested and pass the CI checks. - [x] I have reviewed my own code changes. **If PR contains AI-assisted content:** - [x] I have disclosed the use of AI tools in the PR description as per our [AI Usage Guidelines](https://github.com/munich-quantum-toolkit/core/blob/main/docs/ai_usage.md). - [x] AI-assisted commits include an `Assisted-by: [Model Name] via [Tool Name]` footer. - [x] I confirm that I have personally reviewed and understood all AI-generated content, and accept full responsibility for it.
2 parents 7dfcbea + f051ac6 commit 9d4f091

10 files changed

Lines changed: 527 additions & 500 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ This project adheres to [Semantic Versioning], with the exception that minor rel
1313

1414
- ✨ Add a `merge-single-qubit-rotation-gates` pass for merging consecutive rotation gates using quaternions ([#1407], [#1674]) ([**@J4MMlE**], [**@MatthiasReumann**])
1515
- ✨ Add conversions between `jeff` and QCO ([#1479], [#1548], [#1565], [#1637]) ([**@denialhaag**])
16-
- ✨ Add a `place-and-route` pass for mapping circuits to architectures with restricted topologies ([#1537], [#1547], [#1568], [#1581], [#1583], [#1588], [#1664]) ([**@MatthiasReumann**], [**@burgholzer**])
16+
- ✨ Add a `place-and-route` pass for mapping circuits to architectures with restricted topologies ([#1537], [#1547], [#1568], [#1581], [#1583], [#1588], [#1600], [#1664]) ([**@MatthiasReumann**], [**@burgholzer**])
1717
- ✨ Add initial infrastructure for new QC and QCO MLIR dialects
1818
([#1264], [#1330], [#1402], [#1428], [#1430], [#1436], [#1443], [#1446], [#1464], [#1465], [#1470], [#1471], [#1472], [#1474], [#1475], [#1506], [#1510], [#1513], [#1521], [#1542], [#1548], [#1550], [#1554], [#1567], [#1569], [#1570], [#1572], [#1573], [#1580], [#1602], [#1620], [#1623], [#1624], [#1626], [#1627], [#1635], [#1673], [#1675])
1919
([**@burgholzer**], [**@denialhaag**], [**@taminob**], [**@DRovara**], [**@li-mingbao**], [**@Ectras**], [**@MatthiasReumann**], [**@simon1hofmann**])
@@ -375,6 +375,7 @@ _📚 Refer to the [GitHub Release Notes](https://github.com/munich-quantum-tool
375375
[#1623]: https://github.com/munich-quantum-toolkit/core/pull/1623
376376
[#1620]: https://github.com/munich-quantum-toolkit/core/pull/1620
377377
[#1602]: https://github.com/munich-quantum-toolkit/core/pull/1602
378+
[#1600]: https://github.com/munich-quantum-toolkit/core/pull/1600
378379
[#1596]: https://github.com/munich-quantum-toolkit/core/pull/1596
379380
[#1593]: https://github.com/munich-quantum-toolkit/core/pull/1593
380381
[#1588]: https://github.com/munich-quantum-toolkit/core/pull/1588

mlir/include/mlir/Dialect/QCO/Transforms/Mapping/Architecture.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#pragma once
1212

13+
#include <llvm/ADT/ArrayRef.h>
1314
#include <llvm/ADT/DenseSet.h>
1415
#include <llvm/ADT/SmallVector.h>
1516
#include <mlir/Support/LLVM.h>
@@ -28,6 +29,14 @@ class [[nodiscard]] Architecture {
2829
using CouplingSet = DenseSet<std::pair<std::size_t, std::size_t>>;
2930
using NeighbourVector = SmallVector<SmallVector<std::size_t, 4>>;
3031

32+
/**
33+
* @brief Constructs an empty architecture.
34+
*/
35+
Architecture() : nqubits_(0) {}
36+
37+
/**
38+
* @brief Constructs a well-defined architecture.
39+
*/
3140
explicit Architecture(std::string name, std::size_t nqubits,
3241
CouplingSet couplingSet)
3342
: name_(std::move(name)), nqubits_(nqubits),
@@ -61,7 +70,7 @@ class [[nodiscard]] Architecture {
6170
/**
6271
* @brief Collect all neighbours of @p u.
6372
*/
64-
[[nodiscard]] SmallVector<std::size_t, 4> neighboursOf(std::size_t u) const;
73+
[[nodiscard]] ArrayRef<std::size_t> neighboursOf(std::size_t u) const;
6574

6675
/**
6776
* @brief Return the maximum degree (connectivity) of any qubit in the
@@ -94,5 +103,4 @@ class [[nodiscard]] Architecture {
94103
Matrix dist_;
95104
Matrix prev_;
96105
};
97-
98106
} // namespace mlir::qco
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright (c) 2023 - 2026 Chair for Design Automation, TUM
3+
* Copyright (c) 2025 - 2026 Munich Quantum Software Company GmbH
4+
* All rights reserved.
5+
*
6+
* SPDX-License-Identifier: MIT
7+
*
8+
* Licensed under the MIT License
9+
*/
10+
11+
#pragma once
12+
13+
#include "mlir/Dialect/QCO/Transforms/Passes.h"
14+
15+
#include <llvm/Support/LogicalResult.h>
16+
#include <mlir/IR/Region.h>
17+
#include <mlir/Pass/Pass.h>
18+
19+
#include <memory>
20+
21+
namespace mlir::qco {
22+
23+
// Forward declaration
24+
class Architecture;
25+
26+
/**
27+
* @brief Verifies if all two-qubit gates within the region are executable on
28+
* the targeted architecture. Expects static qubits only.
29+
* @returns llvm::success() if executable, llvm::failure() otherwise.
30+
*/
31+
LogicalResult isExecutable(Region& region, const Architecture& arch);
32+
33+
/**
34+
* @brief Create a mapping pass instance with the given target architecture.
35+
* @returns a pass object.
36+
*/
37+
std::unique_ptr<Pass>
38+
createMappingPass(std::shared_ptr<Architecture> arch,
39+
MappingPassOptions options = MappingPassOptions{});
40+
} // namespace mlir::qco

mlir/include/mlir/Dialect/QCO/Transforms/Passes.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ def MappingPass : Pass<"place-and-route", "mlir::ModuleOp"> {
8989
"The alpha factor in the cost function. Must be > 0.">,
9090
Option<"lambda", "lambda", "float", "0.5F",
9191
"The lambda factor in the cost function.">,
92-
Option<"niterations", "niterations", "std::size_t", "2",
92+
Option<"niterations", "niterations", "std::size_t", "1",
9393
"The number of forwards and backwards traversal to "
94-
"improve the initial layout.">,
94+
"improve the initial layout. Must be > 0.">,
9595
Option<"ntrials", "ntrials", "std::size_t", "4",
9696
"The number of (possibly parallel) random trials of "
9797
"the forwards and backwards mechanism. Must be > 0.">,

mlir/include/mlir/Dialect/QCO/Utils/Qubits.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ class Qubits {
5757
*/
5858
[[nodiscard]] TypedValue<QubitType> getHardwareQubit(std::size_t index) const;
5959

60+
/**
61+
* @returns the index assigned to the qubit value.
62+
*/
63+
[[nodiscard]] std::size_t getIndex(TypedValue<QubitType> q) const;
64+
6065
private:
6166
DenseMap<std::size_t, TypedValue<QubitType>> programToValue_;
6267
DenseMap<std::size_t, TypedValue<QubitType>> hardwareToValue_;

mlir/lib/Dialect/QCO/Transforms/Mapping/Architecture.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
#include "mlir/Dialect/QCO/Transforms/Mapping/Architecture.h"
1212

13-
#include <llvm/ADT/SmallVector.h>
1413
#include <llvm/ADT/Twine.h>
1514
#include <llvm/Support/ErrorHandling.h>
1615
#include <mlir/Support/LLVM.h>
@@ -41,8 +40,7 @@ std::size_t Architecture::distanceBetween(std::size_t u, std::size_t v) const {
4140
return dist_[u][v];
4241
}
4342

44-
SmallVector<std::size_t, 4>
45-
Architecture::neighboursOf(const std::size_t u) const {
43+
ArrayRef<std::size_t> Architecture::neighboursOf(std::size_t u) const {
4644
return neighbours_[u];
4745
}
4846

0 commit comments

Comments
 (0)