Skip to content
Draft
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
789654d
:test_tube: Added tests for Hadamard lifting
LiRem101 Mar 26, 2026
e05e2fe
:test_tube: Added test cases for controlled Pauli Z lifting
LiRem101 Mar 27, 2026
fc10555
:twisted_rightwards_arrows: Merge branch 'main' into mlir/hadamard-li…
LiRem101 Mar 27, 2026
fa877c6
:construction: Added framework for hadamard lifting pass
LiRem101 Mar 27, 2026
d784d01
:construction: Started exchange of Hadamard and Pauli
LiRem101 Mar 30, 2026
e1b6b37
:construction: Lifting uncontrolled Hadamard gates above Pauli
LiRem101 Mar 31, 2026
59739f1
:twisted_rightwards_arrows: Merge branch 'main' into mlir/hadamard-li…
LiRem101 Mar 31, 2026
9dc386e
:white_check_mark: Added canonicalization to references
LiRem101 Mar 31, 2026
5653b9a
:white_check_mark: Corrected gates
LiRem101 Mar 31, 2026
67d3c7c
:construction: Added handling of controlled gates
LiRem101 Apr 1, 2026
95e3604
:recycle: Refactored handling of controlled gates
LiRem101 Apr 1, 2026
e01a8b9
:construction: Added handling of controlled Pauli Z gates
LiRem101 Apr 1, 2026
798c514
:recycle: Refactored handling of controlled Pauli Z gates
LiRem101 Apr 1, 2026
baf731c
:construction: Added CNOT Hadamard handling
LiRem101 Apr 1, 2026
a43b158
✅ Corrected test
LiRem101 Apr 2, 2026
7fd4f75
:rotating_light: Fixed linter warnings
LiRem101 Apr 2, 2026
9c43526
:twisted_rightwards_arrows: Merge branch 'main' into mlir/hadamard-li…
LiRem101 Apr 2, 2026
18382b3
:rotating_light: Fixed linter warnings
LiRem101 Apr 2, 2026
7a89811
:fire: Removed statistics
LiRem101 Apr 2, 2026
cc5f15c
:construction: Added infrastructure to use hadamard lifting
LiRem101 Apr 2, 2026
a682420
:construction: Added infrastructure to use hadamard lifting
LiRem101 Apr 2, 2026
2c298bf
🎨 pre-commit fixes
pre-commit-ci[bot] Apr 2, 2026
e3da07f
:memo: Added information to CHANGELOG.md
LiRem101 Apr 2, 2026
b3bf966
:pencil2: Changed Preceeding to preceding
LiRem101 Apr 2, 2026
b2862e8
:twisted_rightwards_arrows: Merge branch 'mlir/hadamard-lifting' of g…
LiRem101 Apr 2, 2026
e9c66b3
:rotating_light: Fixed linter warnings
LiRem101 Apr 7, 2026
13c046d
:rotating_light: Optimized imports
LiRem101 Apr 7, 2026
db8491e
:rotating_light: Changed dyn_cast to llvm
LiRem101 Apr 7, 2026
f95eeb0
🔀 Merge branch 'main' into mlir/hadamard-lifting
LiRem101 Apr 7, 2026
18cb1b0
:twisted_rightwards_arrows: Merged 'main' and resolved merge conflicts
LiRem101 Apr 8, 2026
fb70183
🎨 pre-commit fixes
pre-commit-ci[bot] Apr 8, 2026
d785bdb
:construction: Fixed branching for optimization passes
LiRem101 Apr 8, 2026
74edb2e
:twisted_rightwards_arrows: Merge branch 'mlir/hadamard-lifting' of g…
LiRem101 Apr 8, 2026
cc97cfd
:memo: Updated Hadamard lifting documentation and fixed typos
LiRem101 Apr 8, 2026
26ca2ed
:construction: Removed double MLIRParser in CMakeLists
LiRem101 Apr 8, 2026
a15d2c1
:white_check_mark: Apply only canonicalizer to reference code
LiRem101 Apr 8, 2026
233da3f
:recycle: use is_permutation
LiRem101 Apr 8, 2026
6af2a96
:bug: Controlled Pauli Y cannot be lifted
LiRem101 Apr 8, 2026
664abad
🎨 pre-commit fixes
pre-commit-ci[bot] Apr 8, 2026
cf245b1
:recycle: Refactored runCanonicalizerPass method
LiRem101 Apr 8, 2026
4ab38c1
:twisted_rightwards_arrows: Merge branch 'mlir/hadamard-lifting' of g…
LiRem101 Apr 8, 2026
57159ae
:rotating_light: Optimized imports and test naming
LiRem101 Apr 8, 2026
c966623
:construction: Apply suggestions from code review
LiRem101 Apr 15, 2026
8d32188
:construction: Adapated code to suggestions from code review
LiRem101 Apr 15, 2026
edc59a2
:memo: Adapted documentation according to review
LiRem101 Apr 15, 2026
cdfc8ed
:construction: Implemented changes suggested by review, removed handl…
LiRem101 Apr 15, 2026
de726cb
:construction: Added global phase for Y-H commutation
LiRem101 Apr 16, 2026
500b0d1
:construction: Added TypeSwitch
LiRem101 Apr 16, 2026
b67a26f
:memo: Improved documentation
LiRem101 Apr 16, 2026
928f6c5
:recycle: Removed temporary value and branchings, assisted-by: GPT 5 …
LiRem101 Apr 16, 2026
9b2397e
:construction: Implemented changes requested in review
LiRem101 Apr 16, 2026
20b6580
:white_check_mark: Added test for measurement after target of CNOT
LiRem101 Apr 16, 2026
3b430d4
:construction: Implemented changes requested in review
LiRem101 Apr 17, 2026
ee2f941
:twisted_rightwards_arrows: Merge with main
LiRem101 Apr 17, 2026
f3cb1d7
🎨 pre-commit fixes
pre-commit-ci[bot] Apr 17, 2026
e5ba050
:pencil2: Fixed typos
LiRem101 Apr 17, 2026
afdb6b0
:twisted_rightwards_arrows: Merge with origin
LiRem101 Apr 17, 2026
44d8c98
🎨 pre-commit fixes
pre-commit-ci[bot] Apr 17, 2026
1ca77fa
:rotating_light: Fix linter errors
LiRem101 Apr 17, 2026
10b21ed
:rotating_light: Fix linter errors
LiRem101 Apr 17, 2026
f183f63
:rotating_light: Fix linter errors
LiRem101 Apr 17, 2026
89da08c
:rotating_light: Fix linter errors
LiRem101 Apr 17, 2026
2f0dbe6
:rotating_light: Fix linter errors
LiRem101 Apr 17, 2026
31995a8
:bug: Fix dangling range, assisted-by: GPT 5 via KI:connect
LiRem101 Apr 20, 2026
3750513
:white_check_mark: Adapated tests to removal of controlled cases
LiRem101 Apr 20, 2026
0da58cf
:bug: Fixed dangling hadamard gate object
LiRem101 Apr 20, 2026
1c2a5a8
:twisted_rightwards_arrows: Merge with main
LiRem101 Apr 22, 2026
fce739b
🎨 pre-commit fixes
pre-commit-ci[bot] Apr 22, 2026
3331f0c
Merge branch 'main' into mlir/hadamard-lifting
denialhaag Apr 29, 2026
7f1256b
Simplify diff
denialhaag Apr 29, 2026
3084ec4
Adapt to new include style
denialhaag Apr 29, 2026
615bbd4
Merge branch 'main' into fork/LiRem101/mlir/hadamard-lifting
burgholzer May 6, 2026
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ This project adheres to [Semantic Versioning], with the exception that minor rel
- ✨ Add Sampler and Estimator Primitives to the QDMI-Qiskit Interface ([#1507]) ([**@marcelwa**])
- ✨ Add conversions between Jeff and QCO ([#1479], [#1548], [#1565]) ([**@denialhaag**])
- ✨ Add a `place-and-route` pass for mapping circuits to architectures with restricted topologies ([#1537], [#1547], [#1568], [#1581], [#1583], [#1588]) ([**@MatthiasReumann**])
- ✨ Add a `hadamard-lifting` pass for lifting Hadamard gates above Pauli gates ([#1605]) ([**@lirem101**])
- ✨ Add initial infrastructure for new QC and QCO MLIR dialects
([#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], [#1623])
([**@burgholzer**], [**@denialhaag**], [**@taminob**], [**@DRovara**], [**@li-mingbao**], [**@Ectras**], [**@MatthiasReumann**], [**@simon1hofmann**])
Expand Down Expand Up @@ -336,6 +337,7 @@ _📚 Refer to the [GitHub Release Notes](https://github.com/munich-quantum-tool
<!-- PR links -->

[#1623]: https://github.com/munich-quantum-toolkit/core/pull/1623
[#1605]: https://github.com/munich-quantum-toolkit/core/pull/1605
[#1602]: https://github.com/munich-quantum-toolkit/core/pull/1602
[#1596]: https://github.com/munich-quantum-toolkit/core/pull/1596
[#1593]: https://github.com/munich-quantum-toolkit/core/pull/1593
Expand Down
3 changes: 3 additions & 0 deletions mlir/include/mlir/Compiler/CompilerPipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ struct QuantumCompilerConfig {

/// Print IR after each stage
bool printIRAfterAllStages = false;

/// Enable Hadamard lifting
bool hadamardLifting = false;
Comment thread
LiRem101 marked this conversation as resolved.
Outdated
};

/**
Expand Down
60 changes: 60 additions & 0 deletions mlir/include/mlir/Dialect/QCO/Transforms/Passes.td
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,64 @@ def MappingPass : Pass<"place-and-route", "mlir::ModuleOp"> {
"The number of inserted SWAPs">];
}

//===----------------------------------------------------------------------===//
// Optimization Passes
//===----------------------------------------------------------------------===//

def HadamardLifting : Pass<"hadamard-lifting", "mlir::ModuleOp"> {
let dependentDialects = ["mlir::qco::QCODialect"];
let summary = "This pass attempts to move Hadamard gates as far away from "
"measurements as possible by flipping them "
Comment thread
LiRem101 marked this conversation as resolved.
Outdated
"with Pauli gates. Additionally, it can change target and "
"control qubits from Pauli-Z gates to make "
"Hadamard lifting applicable. It also lifts Hadamard gates "
"over CNOT gates if that moves a measurement "
"directly after a control.";
Comment thread
burgholzer marked this conversation as resolved.
Outdated
let description = [{
This pass lifts Hadamard gates away from the measurements in order to apply measurement lifting more effectively. It
Comment thread
burgholzer marked this conversation as resolved.
Outdated
uses the following commutation rules:
┌───┐ ┌───┐ ┌───┐ ┌───┐
─┤ X ├─┤ H ├─ => ─┤ H ├─┤ Z ├─
└───┘ └───┘ └───┘ └───┘
┌───┐ ┌───┐ ┌───┐ ┌───┐
─┤ Z ├─┤ H ├─ => ─┤ H ├─┤ X ├─
└───┘ └───┘ └───┘ └───┘
┌───┐ ┌───┐ ┌───┐ ┌───┐
─┤ Y ├─┤ H ├─ => ─┤ H ├─┤ Y ├─
└───┘ └───┘ └───┘ └───┘
Hadamard lifting is only applied to lift Hadamard gates further in front in the circuit, not the other way around.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am tripping over the wording here. "lifting in front" does not really sound like proper English. It is rather "lift up", in general.
Generally, I am under the impression that "Hadamard commutation" would be a more fitting description overall. Would you agree?
If so, I'd propose a bit of a more thorough rewrite of the wording throughout this PR.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will adapt the wording. The naming I'd like to discuss again after I worked through the review, as we discussed.


If the Hadamard and Pauli gates are controlled, they are only lifted if both gates are controlled by exactly the
same qubits and the Pauli gate is not a Pauli Y gate. In that case, the swap of the Pauli Y gate and the Hadamard
gate introduces a phase (YH = -HY) which leads to a non-global phase for controlled gates.
Comment thread
burgholzer marked this conversation as resolved.
Outdated

In the case of the controlled Pauli Z gate, controls and targets are interchangeable. Therefore, transformation
routines as follows are possible and applied:
┌───┐
┤ Z ├──■── ──■────■── ──■────■──
└─┬─┘┌─┴─┐ => ┌─┴─┐┌─┴─┐ => ┌─┴─┐┌─┴─┐
──■──┤ H ├ ┤ Z ├┤ H ├ ┤ H ├┤ X ├
└───┘ └───┘└───┘ └───┘└───┘
The commutation of controlled gates is only done if there are no gates applied between the two controlled gates to
any of the qubits used on the controlled gates.
Comment thread
burgholzer marked this conversation as resolved.
Outdated

In order to reduce multi-qubit gates, a third transformation routine is applied. Using the commutation rule
┌───┐┌───┐┌───┐
──■── ┤ H ├┤ X ├┤ H ├
┌─┴─┐ => │───│└─┬─┘│───│
┤ X ├ ┤ H ├──■──┤ H ├
└───┘ └───┘ └───┘
the following transformation is applied to circuits where a Hadamard gate follows a target gate of a controlled
Pauli X gate, which is followed by a measurement:
┌───┐┌───┐┌───┐
──■───────────── ┤ H ├┤ X ├┤ H ├──
┌─┴─┐┌───┐┌──────┐ => │───│└─┬─┘│───┘──┐
┤ X ├┤ H ├┤ Meas │ ┤ H ├──■──┤ Meas │
└───┘└───┘└──────┘ └───┘ └──────┘

Afterward the measurement lifting routine could transform the CNOT into a classically controlled Pauli X.
Comment thread
burgholzer marked this conversation as resolved.
Outdated
Comment thread
burgholzer marked this conversation as resolved.
Outdated

}];
}

#endif // MLIR_DIALECT_QCO_TRANSFORMS_PASSES_TD
1 change: 1 addition & 0 deletions mlir/lib/Compiler/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ add_mlir_library(
MLIRQCToQCO
MLIRQCOToQC
MLIRQCToQIR
MLIRQCOTransforms
MQT::MLIRSupport)

mqt_mlir_target_use_project_options(MQTCompilerPipeline)
Expand Down
10 changes: 7 additions & 3 deletions mlir/lib/Compiler/CompilerPipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "mlir/Conversion/QCOToQC/QCOToQC.h"
#include "mlir/Conversion/QCToQCO/QCToQCO.h"
#include "mlir/Conversion/QCToQIR/QCToQIR.h"
#include "mlir/Dialect/QCO/Transforms/Passes.h"
#include "mlir/Support/Passes.h"
#include "mlir/Support/PrettyPrinting.h"

Expand Down Expand Up @@ -136,9 +137,12 @@ QuantumCompilerPipeline::runPipeline(ModuleOp module,
}
}
// Stage 5: Optimization passes
// TODO: Add optimization passes
if (failed(
runStage([&](PassManager& pm) { populateQCOCleanupPipeline(pm); }))) {
if (failed(runStage([&](PassManager& pm) {
if (config_.hadamardLifting) {
pm.addPass(qco::createHadamardLifting());
}
populateQCOCleanupPipeline(pm);
Comment thread
LiRem101 marked this conversation as resolved.
Outdated
}))) {
return failure();
}
if (record != nullptr && config_.recordIntermediates) {
Expand Down
Loading
Loading