Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
38b5498
✨ Refactor unitary matrix calculations in quantum gate operations to …
simon1hofmann Apr 22, 2026
db72760
✨ Implement quantum gate decomposition utilities, including two-qubit…
simon1hofmann Apr 22, 2026
741e4c1
✨ Introduce native gate synthesis pass.
simon1hofmann Apr 22, 2026
f55f1cd
✨ Enhance quantum gate decomposition tests with new utility functions…
simon1hofmann Apr 22, 2026
09942df
✨ Add comprehensive tests for native synthesis and gate decomposition…
simon1hofmann Apr 22, 2026
8833b72
✨ Update documentation for native gate synthesis pass with enhanced e…
simon1hofmann Apr 23, 2026
b4257de
📝 Add docstrings
simon1hofmann Apr 23, 2026
1ade32b
✅ Refactor native synthesis tests.
simon1hofmann Apr 23, 2026
4b5f1b2
✨ Enhance two-qubit gate sequence emission by adding support for resi…
simon1hofmann Apr 23, 2026
d719a64
✨ Euler sequence support for matrix synthesis in single-qubit operations
simon1hofmann Apr 24, 2026
0597cee
✨ Refactor parameter ordering for U and U2 gates in decomposition and…
simon1hofmann Apr 24, 2026
b8ff476
📝 Clean up documentation and comments.
simon1hofmann Apr 24, 2026
cc9dfc5
✨ Support arbitrary single controlled operation in native synthesis.
simon1hofmann Apr 24, 2026
12cb303
📝 Update documentation for native gate menu in QuantumCompilerConfig,…
simon1hofmann Apr 24, 2026
76dd5af
🚨 Fix linter warnings
simon1hofmann Apr 24, 2026
9a6e85e
🚨 Fix linter warnings
simon1hofmann Apr 24, 2026
dddc7d4
🚨 Fix linter warnings
simon1hofmann Apr 24, 2026
d30e3f1
🚨 Fix linter warnings
simon1hofmann Apr 24, 2026
92b3ab4
🚨 Fix linter warnings
simon1hofmann Apr 24, 2026
b9bbfea
✅ Introduce helper functions for retrieving unitary qubit operands an…
simon1hofmann Apr 24, 2026
170dee3
🔧 Update qubit comparison logic in mergeTwoTargetOneParameter to ensu…
simon1hofmann Apr 24, 2026
36cf394
🔧 Refactor single-qubit matrix extraction logic to use raw operation …
simon1hofmann Apr 24, 2026
0b102ae
🔧 Enhance qubit comparison logic in QCO operations to validate both q…
simon1hofmann Apr 24, 2026
cece82a
🐛 Fix Ubuntu Tests
simon1hofmann Apr 27, 2026
f0034c4
✅ Increase Coverage
simon1hofmann Apr 27, 2026
56e46f7
🚨 Fix linter warning
simon1hofmann Apr 27, 2026
bf0a02b
✅ Increase Coverage
simon1hofmann Apr 27, 2026
39509e3
Merge branch 'main' into native_gate_synthesis
simon1hofmann Apr 27, 2026
5f8ce03
🐛 Fix Windows Tests
simon1hofmann Apr 27, 2026
de8e474
🐇 Address Rabbit's Comments
simon1hofmann Apr 27, 2026
04a3312
🐇 Address Rabbit's Comments
simon1hofmann Apr 27, 2026
f66e820
🐛 Skip stale windows in TwoQubitWindowConsolidator to avoid erasing c…
simon1hofmann Apr 27, 2026
750ce8d
🐇 Address Rabbit's Comments
simon1hofmann Apr 27, 2026
1f20168
🐛 Fix Windows Tests
simon1hofmann Apr 27, 2026
5c0f2d1
🐛 Fix Windows Tests
simon1hofmann Apr 27, 2026
98d4bea
🐛 Fix Windows Tests
simon1hofmann Apr 27, 2026
12c3eac
🐇 Address Rabbit's Comments
simon1hofmann Apr 27, 2026
01aa915
🐛 Fix Windows Tests
simon1hofmann Apr 27, 2026
7c8aeb9
🐛 Fix Windows Tests
simon1hofmann Apr 27, 2026
db83356
🎨 Revert unitary matrix calculations in QCO standard gates to use std…
simon1hofmann Apr 29, 2026
304eb58
Merge branch 'main' into native_gate_synthesis
simon1hofmann Apr 29, 2026
1af1116
Merge branch 'main' into native_gate_synthesis
simon1hofmann Apr 30, 2026
98f1108
🐛 Try to fix Windows Tests
simon1hofmann Apr 30, 2026
0226c36
🐛 Try to fix Windows Tests
simon1hofmann Apr 30, 2026
2c1c5ad
Merge branch 'main' into native_gate_synthesis
simon1hofmann Jun 18, 2026
d2b472b
🔥 Remove `Eigen` and old single qubit synthesis
simon1hofmann Jun 18, 2026
4d19551
🔥 Remove `fuseRzAcrossCtrlControls` method
simon1hofmann Jun 18, 2026
8a2d90e
🔥 Remove `Gate.h` and `GateKind.h`
simon1hofmann Jun 18, 2026
5aa7660
🔥 Remove dead code
simon1hofmann Jun 18, 2026
bd07e69
✨ Add `fuse-two-qubit-unitary-runs` pass for fusing compile-time two-…
simon1hofmann Jun 18, 2026
fc42ea8
🔥 Remove and merge tests
simon1hofmann Jun 18, 2026
742632d
🔥 Remove and merge files
simon1hofmann Jun 19, 2026
9bb75bf
Merge branch 'main' into native_gate_synthesis
simon1hofmann Jun 19, 2026
a6b7c98
🔥 More merging and clean up
simon1hofmann Jun 19, 2026
6da8de8
🚨 Fix linter warnings
simon1hofmann Jun 19, 2026
6a3b138
✨ Refactor unit tests for two-qubit unitary fusion
simon1hofmann Jun 21, 2026
9c56c00
Merge branch 'main' into native_gate_synthesis
simon1hofmann Jun 21, 2026
b8cd395
🎨 Refactor and streamline native gate profile and synthesis for two-q…
simon1hofmann Jun 21, 2026
41d0077
🚨 Fix linter warnings
simon1hofmann Jun 21, 2026
7e23b01
🚨 Fix linter warnings
simon1hofmann Jun 21, 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ with the exception that minor releases may include breaking changes.

### Added

- ✨ Add a `fuse-two-qubit-unitary-runs` pass
for fusing compile-time two-qubit unitary windows via Weyl/KAK resynthesis
([#1655]) ([**@simon1hofmann**])
- ✨ Add a `fuse-single-qubit-unitary-runs` pass
for fusing compile-time single-qubit unitary runs via Euler resynthesis
([#1672]) ([**@simon1hofmann**], [**@burgholzer**])
Expand Down Expand Up @@ -632,6 +635,7 @@ changelogs._
[#1664]: https://github.com/munich-quantum-toolkit/core/pull/1664
[#1662]: https://github.com/munich-quantum-toolkit/core/pull/1662
[#1660]: https://github.com/munich-quantum-toolkit/core/pull/1660
[#1655]: https://github.com/munich-quantum-toolkit/core/pull/1655
[#1652]: https://github.com/munich-quantum-toolkit/core/pull/1652
[#1638]: https://github.com/munich-quantum-toolkit/core/pull/1638
[#1637]: https://github.com/munich-quantum-toolkit/core/pull/1637
Expand Down
14 changes: 13 additions & 1 deletion mlir/include/mlir/Compiler/CompilerPipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@ struct QuantumCompilerConfig {

/// Enable Hadamard lifting
bool enableHadamardLifting = false;

/// Comma-separated native gate menu. Recognised tokens: `u`, `x`, `sx`,
/// `rz` (or `p`), `rx`, `ry`, `r`, `cx`, `cz`, `rzz`.
/// Illustrative menus (use `cx` or `cz` as the entangler, or
/// both):
/// - `"x,sx,rz,cx"` / `"x,sx,rz,cz"` — IBM basic (no fractional 2q)
/// - `"x,sx,rz,rx,rzz,cx"` / `"...,cz"` — IBM fractional
/// - `"u,cx"` / `"u,cz"` — generic single-qubit U3 + CX/CZ
/// - `"r,cz"` — IQM-style default
/// - `"rx,rz,cx"`, `"rx,ry,cz"`, `"ry,rz,cx"` — supported RX/RY/RZ pairs plus
/// entangler
std::string nativeGates;
};

/**
Expand Down Expand Up @@ -84,7 +96,7 @@ struct CompilationRecord {
* 2. QC cleanup pipeline
* 3. QCO dialect (value semantics) - enables SSA-based optimizations
* 4. QCO cleanup pipeline
* 5. Quantum optimization passes
* 5. Optimization and native gate synthesis
* 6. QCO cleanup pipeline
* 7. QC dialect - converted back for backend lowering
* 8. QC cleanup pipeline
Expand Down
26 changes: 26 additions & 0 deletions mlir/include/mlir/Dialect/QCO/Transforms/Decomposition/Euler.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ enum class EulerBasis : std::uint8_t {
XYX = 3, ///< `RX(phi) * RY(theta) * RX(lambda)`.
U = 4, ///< `U(theta, phi, lambda)`.
ZSXX = 5, ///< `RZ` / `SX` / `X` synthesis via ZYZ decomposition.
R = 6, ///< `R(.,0) * R(.,pi/2) * R(.,0)` (XYX with `Rx`/`Ry` as `R`).
};

/**
Expand All @@ -42,6 +43,31 @@ enum class EulerBasis : std::uint8_t {
*/
[[nodiscard]] std::optional<EulerBasis> parseEulerBasis(StringRef basis);

/**
* @brief Euler angles `(theta, phi, lambda)` and global phase for a 2x2
* unitary.
*
* The decomposition obeys `matrix == e^{i*phase} * K(phi) * A(theta) *
* K(lambda)` where `(K, A)` are the rotation axes of the chosen @ref
* EulerBasis.
*/
struct EulerAngles {
double theta = 0.0; ///< Middle rotation angle.
double phi = 0.0; ///< First outer rotation angle.
double lambda = 0.0; ///< Second outer rotation angle.
double phase = 0.0; ///< Global phase in radians.
};

/**
* @brief Extracts `(theta, phi, lambda, phase)` of @p matrix in @p basis.
*
* @param matrix The single-qubit unitary to decompose.
* @param basis The target Euler basis.
* @return The extracted Euler angles and global phase.
*/
[[nodiscard]] EulerAngles anglesFromUnitary(const Matrix2x2& matrix,
EulerBasis basis);

/**
* @brief Synthesizes a composed single-qubit unitary as gates in @p basis.
*
Expand Down
173 changes: 173 additions & 0 deletions mlir/include/mlir/Dialect/QCO/Transforms/Decomposition/NativeProfile.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
/*
* Copyright (c) 2023 - 2026 Chair for Design Automation, TUM
* Copyright (c) 2025 - 2026 Munich Quantum Software Company GmbH
* All rights reserved.
*
* SPDX-License-Identifier: MIT
*
* Licensed under the MIT License
*/

#pragma once

#include "mlir/Dialect/QCO/IR/QCOInterfaces.h"
#include "mlir/Dialect/QCO/IR/QCOOps.h"
#include "mlir/Dialect/QCO/Transforms/Decomposition/Euler.h"
#include "mlir/Dialect/QCO/Utils/Matrix.h"

#include <llvm/ADT/DenseSet.h>
#include <llvm/ADT/SmallVector.h>
#include <mlir/IR/Builders.h>
#include <mlir/IR/Location.h>
#include <mlir/IR/Operation.h>
#include <mlir/IR/Value.h>
#include <mlir/Support/LLVM.h>
#include <mlir/Support/LogicalResult.h>

#include <cstdint>
#include <optional>

namespace mlir::qco::decomposition {

/**
* @brief Native gate kinds that may appear in a two-qubit synthesis menu.
*/
enum class NativeGateKind : std::uint8_t {
U,
X,
Sx,
Rz,
Rx,
Ry,
R,
Cx,
Cz,
Rzz,
};

/**
* @brief Single-qubit emission strategy resolved from a native-gate menu.
*/
enum class SingleQubitMode : std::uint8_t {
ZSXX, ///< `RZ` / `SX` / `X` via ZYZ decomposition.
U3, ///< Generic `U(theta, phi, lambda)`.
R, ///< `R(theta, phi)` chain (`Rx`/`Ry` as `R`).
AxisPair, ///< Two fixed rotation axes (see @ref AxisPair).
};

/**
* @brief Rotation-axis pair for @ref SingleQubitMode::AxisPair emitters.
*/
enum class AxisPair : std::uint8_t {
RxRz,
RxRy,
RyRz,
};

/**
* @brief Entangling basis gate for two-qubit Weyl synthesis.
*/
enum class EntanglerBasis : std::uint8_t {
None,
Cx,
Cz,
};

struct SingleQubitEmitterSpec {
SingleQubitMode mode = SingleQubitMode::U3;
AxisPair axisPair = AxisPair::RxRz;
bool supportsDirectRx = false;
};

/**
* @brief Resolved native-gate menu for two-qubit Weyl synthesis.
*/
struct NativeProfileSpec {
bool allowRzz = false;
llvm::DenseSet<NativeGateKind> allowedGates;
llvm::SmallVector<SingleQubitEmitterSpec> singleQubitEmitters;
llvm::SmallVector<EntanglerBasis> entanglerBases;
};

/**
* @brief Euler basis used to emit single-qubit factors for @p emitter.
*/
[[nodiscard]] EulerBasis
emitterEulerBasis(const SingleQubitEmitterSpec& emitter);

/**
* @brief Parses a comma-separated native-gate menu (e.g. `"u,cx,rzz"`).
*/
[[nodiscard]] std::optional<NativeProfileSpec>
parseNativeSpec(StringRef nativeGates);

/**
* @brief Synthesizes a composed two-qubit unitary as gates in @p spec.
*/
[[nodiscard]] LogicalResult
synthesizeUnitary2QWeyl(OpBuilder& builder, Location loc, Value qubit0,
Value qubit1, const Matrix4x4& target,
const NativeProfileSpec& spec, Value& outQubit0,
Value& outQubit1);

/**
* @brief Number of entangling basis gates required to synthesize @p target.
*
* @return Entangler count for @p spec, or `std::nullopt` if synthesis fails.
*/
[[nodiscard]] std::optional<std::uint8_t>
twoQubitEntanglerCount(const Matrix4x4& target, const NativeProfileSpec& spec);

/**
* @brief Maps a compile-time single-qubit op to its native-menu gate kind.
*
* Returns `std::nullopt` for non-primitive or unsupported ops.
*/
[[nodiscard]] std::optional<NativeGateKind>
nativeGateKindFor(UnitaryOpInterface op);

/**
* @brief Returns true when @p op is already on the resolved single-qubit menu.
*
* `BarrierOp` and `GPhaseOp` are always allowed.
*/
[[nodiscard]] bool allowsSingleQubitOp(UnitaryOpInterface op,
const NativeProfileSpec& spec);

/**
* @brief Entangler basis for a 1-control, 1-target `CtrlOp` with `X`/`Z` body.
*/
[[nodiscard]] std::optional<EntanglerBasis>
entanglerBasisForSingleTargetCtrl(CtrlOp ctrl);

/** @brief Returns true when @p spec lists @p basis as an entangler. */
[[nodiscard]] bool profileAllowsEntangler(const NativeProfileSpec& spec,
EntanglerBasis basis);

/**
* @brief Returns true when a 1-control, 1-target `CtrlOp` is on @p spec.
*/
[[nodiscard]] bool allowsSingleTargetCtrl(CtrlOp ctrl,
const NativeProfileSpec& spec);

/**
* @brief Returns true when a bare two-qubit op (currently `RZZ`) is on @p spec.
*/
[[nodiscard]] bool allowsBareTwoQubitOp(Operation* op,
const NativeProfileSpec& spec);

/**
* @brief Returns true when @p op is a native two-qubit gate under @p spec.
*/
[[nodiscard]] bool allowsTwoQubitOp(Operation* op,
const NativeProfileSpec& spec);

/**
* @brief Fills @p matrix with the 4x4 unitary for a two-qubit block op.
*
* Handles single-target `CtrlOp` shells and generic two-qubit unitaries.
* Returns false for barriers, global phase, and unsupported shapes.
*/
[[nodiscard]] bool assignTwoQubitOpMatrix(Operation* op, Matrix4x4& matrix);

} // namespace mlir::qco::decomposition
Loading
Loading