Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
9f12eaa
Remove beta factor and ndepth calculation
MatthiasReumann Oct 23, 2025
a64d10c
Precompute neighbours in Architecture
MatthiasReumann Oct 23, 2025
4246983
Add early exit on expansion
MatthiasReumann Oct 23, 2025
b45b2d5
Use std::minmax
MatthiasReumann Oct 23, 2025
d133c20
Add closed set
MatthiasReumann Oct 23, 2025
d47a8eb
Reorder astar router class
MatthiasReumann Oct 24, 2025
fbdb8e9
Refactor getIns and getOuts: remove interface methods
MatthiasReumann Oct 27, 2025
d03cfd4
Remove msTime
MatthiasReumann Oct 27, 2025
2ebf383
Reorder typeswitch cases to better reflect most frequent ops
MatthiasReumann Oct 27, 2025
cfd0c85
Refactor ParallelOpScheduler
MatthiasReumann Oct 28, 2025
ed83dc2
Move getUserInRegion to Common.h
MatthiasReumann Oct 28, 2025
9cf9f6f
Add two-qubit block skipping
MatthiasReumann Oct 29, 2025
2e78dd8
Remove msTime from placement pass
MatthiasReumann Oct 29, 2025
fa2fbfb
Revert early exit
MatthiasReumann Oct 29, 2025
ce7d64f
Re-add closed map
MatthiasReumann Oct 29, 2025
b5e4cbf
Final touches
MatthiasReumann Oct 29, 2025
81a5ce9
Remove IBMFalcon
MatthiasReumann Oct 29, 2025
9d751b9
Merge branch 'main' into enh/mlir-routing-a-star-improvements
MatthiasReumann Oct 29, 2025
33941aa
Fix compile error on linux and windows
MatthiasReumann Oct 29, 2025
bcacb84
Add ValuePair to Common.h
MatthiasReumann Oct 30, 2025
8dd2a86
Fix scheduler problems
MatthiasReumann Oct 30, 2025
0d5f5fd
Fix SWAP bug in handleUnitary
MatthiasReumann Oct 30, 2025
b83571c
Remove left-over debug print
MatthiasReumann Oct 30, 2025
0cfdb7e
Update tests for coverage
MatthiasReumann Oct 30, 2025
ab98a40
Add grover_5 test
MatthiasReumann Oct 30, 2025
e719864
Merge test files (Add multiple RUNs)
MatthiasReumann Oct 30, 2025
1c8fd84
Update CHANGELOG.md
MatthiasReumann Oct 31, 2025
85cc1ac
Merge branch 'main' into enh/mlir-routing-a-star-improvements
MatthiasReumann Oct 31, 2025
2db8b1d
Sort CHANGELOG.md PR links
MatthiasReumann Oct 31, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ This project adheres to [Semantic Versioning], with the exception that minor rel

### Added

- ✨ Add A\*-search-based routing algorithm to MLIR transpilation routines ([#1237]) ([**@MatthiasReumann**])
- ✨ Add A\*-search-based routing algorithm to MLIR transpilation routines ([#1237], [#1271]) ([**@MatthiasReumann**])

### Fixed

Expand Down Expand Up @@ -221,20 +221,21 @@ _📚 Refer to the [GitHub Release Notes](https://github.com/munich-quantum-tool
<!-- PR links -->

[#1276]: https://github.com/munich-quantum-toolkit/core/pull/1276
[#1237]: https://github.com/munich-quantum-toolkit/core/pull/1237
[#1271]: https://github.com/munich-quantum-toolkit/core/pull/1271
[#1269]: https://github.com/munich-quantum-toolkit/core/pull/1269
[#1263]: https://github.com/munich-quantum-toolkit/core/pull/1263
[#1247]: https://github.com/munich-quantum-toolkit/core/pull/1247
[#1246]: https://github.com/munich-quantum-toolkit/core/pull/1246
[#1237]: https://github.com/munich-quantum-toolkit/core/pull/1237
[#1236]: https://github.com/munich-quantum-toolkit/core/pull/1236
[#1235]: https://github.com/munich-quantum-toolkit/core/pull/1235
[#1232]: https://github.com/munich-quantum-toolkit/core/pull/1232
[#1224]: https://github.com/munich-quantum-toolkit/core/pull/1224
[#1223]: https://github.com/munich-quantum-toolkit/core/pull/1223
[#1211]: https://github.com/munich-quantum-toolkit/core/pull/1211
[#1210]: https://github.com/munich-quantum-toolkit/core/pull/1210
[#1207]: https://github.com/munich-quantum-toolkit/core/pull/1207
[#1209]: https://github.com/munich-quantum-toolkit/core/pull/1209
[#1207]: https://github.com/munich-quantum-toolkit/core/pull/1207
[#1186]: https://github.com/munich-quantum-toolkit/core/pull/1186
[#1181]: https://github.com/munich-quantum-toolkit/core/pull/1181
[#1180]: https://github.com/munich-quantum-toolkit/core/pull/1180
Expand Down
8 changes: 1 addition & 7 deletions mlir/include/mlir/Dialect/MQTOpt/Transforms/Passes.td
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,6 @@ def PlacementPassSC : Pass<"placement-sc", "mlir::ModuleOp"> {
clEnumValN(PlacementStrategy::Random, "random", "Random placement"),
clEnumValN(PlacementStrategy::Identity, "identity", "Identity placement"))}]>
];
let statistics = [
Statistic<"tms", "runtime-milliseconds", "The runtime in milliseconds">
];
}

def RoutingPassSC : Pass<"route-sc", "mlir::ModuleOp"> {
Expand All @@ -122,14 +119,11 @@ def RoutingPassSC : Pass<"route-sc", "mlir::ModuleOp"> {
"astar option: Number of lookahead steps (heuristic horizon)">,
Option<"alpha", "alpha", "float", "1.0F",
"astar option: The alpha factor in the cost function">,
Option<"beta", "beta", "float", "1.0F",
"astar option: The beta factor in the cost function">,
Option<"lambda", "lambda", "float", "0.5F",
"astar option: The lambda factor in the cost function">
];
let statistics = [
Statistic<"numSwaps", "num-additional-swaps", "The number of additional SWAPs">,
Statistic<"msTime", "runtime-milliseconds", "The runtime in milliseconds">
Statistic<"numSwaps", "num-additional-swaps", "The number of additional SWAPs">
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,17 @@ enum class ArchitectureName : std::uint8_t { MQTTest };
*/
class Architecture {
public:
using CouplingMap = llvm::DenseSet<std::pair<QubitIndex, QubitIndex>>;
using CouplingSet = mlir::DenseSet<std::pair<QubitIndex, QubitIndex>>;
using NeighbourVector = mlir::SmallVector<mlir::SmallVector<QubitIndex, 4>>;

explicit Architecture(std::string name, std::size_t nqubits,
CouplingMap couplingMap)
CouplingSet couplingSet)
: name_(std::move(name)), nqubits_(nqubits),
couplingMap_(std::move(couplingMap)),
couplingSet_(std::move(couplingSet)), neighbours_(nqubits),
dist_(nqubits, llvm::SmallVector<std::size_t>(nqubits, UINT64_MAX)),
prev_(nqubits, llvm::SmallVector<std::size_t>(nqubits, UINT64_MAX)) {
floydWarshallWithPathReconstruction();
collectNeighbours();
}

/**
Expand All @@ -58,7 +60,7 @@ class Architecture {
* @brief Return true if @p u and @p v are adjacent.
*/
[[nodiscard]] bool areAdjacent(QubitIndex u, QubitIndex v) const {
return couplingMap_.contains({u, v});
return couplingSet_.contains({u, v});
}

/**
Expand All @@ -76,7 +78,8 @@ class Architecture {
/**
* @brief Collect all neighbours of @p u.
*/
[[nodiscard]] llvm::SmallVector<QubitIndex> neighboursOf(QubitIndex u) const;
[[nodiscard]] llvm::SmallVector<QubitIndex, 4>
neighboursOf(QubitIndex u) const;

private:
using Matrix = llvm::SmallVector<llvm::SmallVector<std::size_t>>;
Expand All @@ -89,9 +92,16 @@ class Architecture {
*/
void floydWarshallWithPathReconstruction();

/**
* @brief Collect the neighbours of all qubits.
* @details Has a time complexity of O(nqubits)
*/
void collectNeighbours();

std::string name_;
std::size_t nqubits_;
CouplingMap couplingMap_;
CouplingSet couplingSet_;
NeighbourVector neighbours_;

Matrix dist_;
Matrix prev_;
Expand Down
25 changes: 20 additions & 5 deletions mlir/include/mlir/Dialect/MQTOpt/Transforms/Transpilation/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,16 @@ constexpr std::size_t IF_PARENT_DEPTH = 2UL;
*/
using QubitIndex = uint32_t;

/**
* @brief A pair of SSA Values.
*/
using ValuePair = std::pair<mlir::Value, mlir::Value>;

/**
* @brief Represents a pair of qubit indices.
*/
using QubitIndexPair = std::pair<QubitIndex, QubitIndex>;

/**
* @brief Return true if the function contains "entry_point" in the passthrough
* attribute.
Expand All @@ -50,19 +56,28 @@ using QubitIndexPair = std::pair<QubitIndex, QubitIndex>;
* @param u A unitary.
* @returns True iff the qubit gate acts on two qubits.
*/
[[nodiscard]] bool isTwoQubitGate(UnitaryInterface u);
[[nodiscard]] bool isTwoQubitGate(UnitaryInterface op);

/**
* @brief Return input qubit pair for a two-qubit unitary.
* @param u A two-qubit unitary.
* @param op A two-qubit unitary.
* @return Pair of SSA values consisting of the first and second in-qubits.
*/
[[nodiscard]] std::pair<mlir::Value, mlir::Value> getIns(UnitaryInterface op);
[[nodiscard]] ValuePair getIns(UnitaryInterface op);

/**
* @brief Return output qubit pair for a two-qubit unitary.
* @param u A two-qubit unitary.
* @param op A two-qubit unitary.
* @return Pair of SSA values consisting of the first and second out-qubits.
*/
[[nodiscard]] std::pair<mlir::Value, mlir::Value> getOuts(UnitaryInterface op);
[[nodiscard]] ValuePair getOuts(UnitaryInterface op);

/**
* @brief Return the first user of a value in a given region.
* @param v The value.
* @param region The targeted region.
* @return A pointer to the user, or nullptr if non exists.
*/
[[nodiscard]] mlir::Operation* getUserInRegion(mlir::Value v,
mlir::Region* region);
} // namespace mqt::ir::opt
31 changes: 31 additions & 0 deletions mlir/include/mlir/Dialect/MQTOpt/Transforms/Transpilation/Layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include "mlir/Dialect/MQTOpt/Transforms/Transpilation/Common.h"

#include <llvm/ADT/DenseMapInfo.h>
#include <llvm/ADT/SmallVector.h>
#include <mlir/IR/Value.h>
#include <mlir/Support/LLVM.h>
Expand Down Expand Up @@ -114,6 +115,9 @@ class [[nodiscard]] ThinLayout {
* @brief Maps a hardware qubit index to its program index.
*/
SmallVector<QubitIndex> hardwareToProgram_;

private:
friend struct llvm::DenseMapInfo<ThinLayout>;
};

/**
Expand Down Expand Up @@ -260,3 +264,30 @@ class [[nodiscard]] Layout : public ThinLayout {
SmallVector<Value> qubits_;
};
} // namespace mqt::ir::opt

namespace llvm {
template <> struct DenseMapInfo<mqt::ir::opt::ThinLayout> {
using Layout = mqt::ir::opt::ThinLayout;
using VectorInfo = DenseMapInfo<SmallVector<mqt::ir::opt::QubitIndex>>;

static Layout getEmptyKey() {
Layout layout(0);
layout.programToHardware_ = VectorInfo::getEmptyKey();
return layout;
}

static Layout getTombstoneKey() {
Layout layout(0);
layout.programToHardware_ = VectorInfo::getTombstoneKey();
return layout;
}

static unsigned getHashValue(const Layout& layout) {
return VectorInfo::getHashValue(layout.programToHardware_);
}

static bool isEqual(const Layout& lhs, const Layout& rhs) {
return VectorInfo::isEqual(lhs.programToHardware_, rhs.programToHardware_);
}
};
} // namespace llvm
Loading
Loading