|
| 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/Utils/Matrix.h" |
| 14 | + |
| 15 | +#include <mlir/IR/Builders.h> |
| 16 | +#include <mlir/IR/Location.h> |
| 17 | +#include <mlir/Support/LLVM.h> |
| 18 | + |
| 19 | +#include <cstddef> |
| 20 | +#include <cstdint> |
| 21 | +#include <optional> |
| 22 | + |
| 23 | +namespace mlir::qco::decomposition { |
| 24 | + |
| 25 | +/** |
| 26 | + * @brief Native gate sets for single-qubit Euler synthesis. |
| 27 | + */ |
| 28 | +enum class EulerBasis : std::uint8_t { |
| 29 | + ZYZ = 0, ///< `RZ(phi) * RY(theta) * RZ(lambda)`. |
| 30 | + ZXZ = 1, ///< `RZ(phi) * RX(theta) * RZ(lambda)`. |
| 31 | + XZX = 2, ///< `RX(phi) * RZ(theta) * RX(lambda)`. |
| 32 | + XYX = 3, ///< `RX(phi) * RY(theta) * RX(lambda)`. |
| 33 | + U = 4, ///< `U(theta, phi, lambda)`. |
| 34 | + ZSXX = 5, ///< `RZ` / `SX` / `X` synthesis via ZYZ decomposition. |
| 35 | +}; |
| 36 | + |
| 37 | +/** |
| 38 | + * @brief Parses a basis name (e.g. `zyz`, `zsxx`; case-insensitive). |
| 39 | + * |
| 40 | + * @param basis The basis name. |
| 41 | + * @return The parsed basis, or `std::nullopt` if unrecognized. |
| 42 | + */ |
| 43 | +[[nodiscard]] std::optional<EulerBasis> parseEulerBasis(StringRef basis); |
| 44 | + |
| 45 | +/** |
| 46 | + * @brief Synthesizes a composed single-qubit unitary as gates in @p basis. |
| 47 | + * |
| 48 | + * Returns `std::nullopt` when @p hasNonBasisGate is false and resynthesis |
| 49 | + * would not shorten a run of @p runSize gates; otherwise emits gates |
| 50 | + * (including `qco.gphase` when needed). |
| 51 | + * |
| 52 | + * @param builder Builder for the emitted operations. |
| 53 | + * @param loc Location for the emitted operations. |
| 54 | + * @param qubit Input qubit value. |
| 55 | + * @param composed Composed unitary to synthesize. |
| 56 | + * @param runSize Number of gates in the run. |
| 57 | + * @param hasNonBasisGate Whether the run contains a gate outside @p basis. |
| 58 | + * @param basis The target Euler basis. |
| 59 | + * @return The synthesized qubit, or `std::nullopt` if synthesis is skipped. |
| 60 | + */ |
| 61 | +[[nodiscard]] std::optional<Value> |
| 62 | +synthesizeUnitary1QEuler(OpBuilder& builder, Location loc, Value qubit, |
| 63 | + const Matrix2x2& composed, std::size_t runSize, |
| 64 | + bool hasNonBasisGate, EulerBasis basis); |
| 65 | + |
| 66 | +} // namespace mlir::qco::decomposition |
0 commit comments