Skip to content

Commit e80ead8

Browse files
✨ Implement Trials For Mapping Pass (#1568)
1 parent a5cf121 commit e80ead8

6 files changed

Lines changed: 203 additions & 56 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 Sampler and Estimator Primitives to the QDMI-Qiskit Interface ([#1507]) ([**@marcelwa**])
1515
- ✨ Add conversions between Jeff and QCO ([#1479], [#1548]) ([**@denialhaag**])
16-
- ✨ Add a `place-and-route` pass for mapping circuits to architectures with restricted topologies ([#1537], [#1547]) ([**@MatthiasReumann**])
16+
- ✨ Add a `place-and-route` pass for mapping circuits to architectures with restricted topologies ([#1537], [#1547], [#1568]) ([**@MatthiasReumann**])
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], [#1548], [#1550], [#1554])
1919
([**@burgholzer**], [**@denialhaag**], [**@taminob**], [**@DRovara**], [**@li-mingbao**], [**@Ectras**], [**@MatthiasReumann**], [**@simon1hofmann**])
@@ -331,6 +331,7 @@ _📚 Refer to the [GitHub Release Notes](https://github.com/munich-quantum-tool
331331

332332
<!-- PR links -->
333333

334+
[#1568]: https://github.com/munich-quantum-toolkit/core/pull/1568
334335
[#1554]: https://github.com/munich-quantum-toolkit/core/pull/1554
335336
[#1550]: https://github.com/munich-quantum-toolkit/core/pull/1550
336337
[#1549]: https://github.com/munich-quantum-toolkit/core/pull/1549

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ class [[nodiscard]] Architecture {
6464
[[nodiscard]] mlir::SmallVector<std::size_t, 4>
6565
neighboursOf(std::size_t u) const;
6666

67+
/**
68+
* @brief Return the maximum degree (connectivity) of any qubit in the
69+
* architecture.
70+
*/
71+
[[nodiscard]] std::size_t maxDegree() const;
72+
6773
private:
6874
using Matrix = mlir::SmallVector<mlir::SmallVector<std::size_t, 0>, 0>;
6975

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ def MappingPass : Pass<"place-and-route", "mlir::ModuleOp"> {
4949
each traversal, the pass routes the circuit and updates the dynamic-to-static mapping based on the routing decisions
5050
made during that traversal. By performing multiple traversals, the pass can iteratively refine the mapping and
5151
potentially find a more optimal solution. This is behavior is controlled by the `niterations` parameter.
52+
53+
The pass option `ntrials` determines how many random initial layouts the pass explores. Per default, the pass always
54+
explores the identity layout. If compiled with multi-threading on, these trials will be executed in parallel.
5255
}];
5356
let options = [
5457
Option<"nlookahead", "nlookahead", "std::size_t", "1",
@@ -58,7 +61,11 @@ def MappingPass : Pass<"place-and-route", "mlir::ModuleOp"> {
5861
Option<"lambda", "lambda", "float", "0.5F",
5962
"The lambda factor in the cost function.">,
6063
Option<"niterations", "niterations", "std::size_t", "2",
61-
"The number of forwards and backwards traversal to improve the initial layout.">
64+
"The number of forwards and backwards traversal to improve the initial layout.">,
65+
Option<"ntrials", "ntrials", "std::size_t", "4",
66+
"The number of (possibly parallel) random trials of the forwards and backwards mechanism.">,
67+
Option<"seed", "seed", "std::size_t", "42",
68+
"A seed used for randomization.">
6269
];
6370
}
6471

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <llvm/Support/ErrorHandling.h>
1414
#include <mlir/Support/LLVM.h>
1515

16+
#include <algorithm>
1617
#include <cstddef>
1718
#include <cstdint>
1819
#include <string_view>
@@ -72,3 +73,11 @@ void Architecture::collectNeighbours() {
7273
neighbours_[u].push_back(v);
7374
}
7475
}
76+
77+
std::size_t Architecture::maxDegree() const {
78+
std::size_t deg = 0;
79+
for (const auto& nbrs : neighbours_) {
80+
deg = std::max(deg, nbrs.size());
81+
}
82+
return deg;
83+
}

0 commit comments

Comments
 (0)