-
-
Notifications
You must be signed in to change notification settings - Fork 54
✨ Implement single- and two-qubit gate decomposition pass #1206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
taminob
wants to merge
247
commits into
main
Choose a base branch
from
taminob/mlir-two-qubit-gate-decomposition-pass
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 229 commits
Commits
Show all changes
247 commits
Select commit
Hold shift + click to select a range
20404bc
snapshot
taminob 8fd23f6
copied rust code
taminob 5e806f6
🎨 pre-commit fixes
pre-commit-ci[bot] 70082d8
snapshot
taminob debe427
snapshot
taminob b86844b
snapshot
taminob e4dec47
minor additions
taminob 9ce8ac3
add pass to Passes.td
taminob f45107b
snapshot
taminob 81e6230
compiling snapshot
taminob 588db20
tmp
taminob 84fa825
switch to long double
taminob 3dd1266
testing a.cpp
taminob 3c214ad
add zgemm for testing, start euler decomposition implementation
taminob 62aa918
non-working but finished snapshot
taminob eec099c
fix out-of-bounds issues
taminob b1a4286
test using Armadillo
taminob cee23a7
minor fix
taminob 5550adc
tmp
taminob b541500
work on gate application
taminob 0b80624
use laughing-umbrella implementation for decompose_two_qubit_product_…
taminob 299d6f1
add more eigen decomposition implementations
taminob 96b39ad
work on applySeries()
taminob 3947566
Revert "use laughing-umbrella implementation for decompose_two_qubit_…
taminob ab188ae
fix transpose_conjugate
taminob 410fadd
add test
taminob 05885a1
actually kind of working snapshot?
taminob c87b02a
fix test case
taminob 619d0d6
minor fix
taminob a998ef7
fix test case
taminob 71420a2
add new test, fix tests
taminob bd8cdbd
iniital complexSeries test
taminob 85b03c2
use Eigen for multiply() and determinant()
taminob 0de0b43
fix gate matrix multiplication
taminob cc9f1be
add simple (too simple) series complexity
taminob 13721df
fix insertion when operations which are not part of the series are in…
taminob 6305604
add gate matrices
taminob dd130b9
sequence complexity()
taminob fb742d8
print debugging :)
taminob e6840d4
longer complex test to pass sequence complexity check
taminob 08e1991
use CXGate() definition for decomposer
taminob 0e6ff8e
add cnot test other direction
taminob 5814ade
tmp (to be deleted)
taminob 70d604e
re-write using Eigen
taminob a5dead7
delete pulse-optimizer code (KEEP for future; should be re-added at s…
taminob 5aeb866
use designated initializer lists
taminob 0714745
fix warnings, rename all variables
taminob 579b6e8
test normalized magic basis, allow complex eigenvector decomposition
taminob 7ca5341
finally figured some stuff out
taminob e1548d2
try out lauging-umbrella weyl-chamber
taminob 9dfd453
try to implement weylchamber.c1c2c3 algorithm
taminob e78b4f3
on_gates two-qubit product decompose
taminob cf9d649
minor additions
taminob c02bfa6
try ordering all four eigenvectors
taminob 3a800c6
undo ordering of all columns
taminob c155100
implement algorithm based on quantumflow.canonical_decomposition
taminob b6ff17f
sanity checks and stuff
taminob 83c089e
add original implementation again which seems to kind of work?
taminob a94195f
generate openqasm code of generated sequence
taminob ab57b7d
some more small fixes, maybe breakthrough?
taminob af6f411
rework getTwoQubitSeries logic
taminob 8a9447b
generate openqasm code of found series
taminob e4b68d1
fix new getTwoQubitSeries logic
taminob 1eea4af
working except global phase?
taminob bb4b796
fix global phase issues
taminob 837363f
first working snapshot
taminob 2582c66
very minor cleanup
taminob 8ec690b
add more sanity checks for unitary
taminob e26a374
find and fix minor formula mistake
taminob bc1475e
test update
taminob 4048bf6
make calculations exact without approximation
taminob cff036c
respect gphase of circuit and fix series collection bug
taminob 21701e8
change global phase to local phase
taminob 85c1f86
revert to global phase, fix controlled gate qubit order
taminob 9c0ecb4
fix first couple of tests
taminob 00986dd
start working on basis set and remove dead code
taminob bcaf798
decompose for all bases, choose best
taminob 83868c0
add checks for most tests
taminob b16bc9a
TMP, needs to be removed; allow OpenQASM export with round-trip pass
taminob 8cdce44
add single-qubit backtracking
taminob e919bcd
fix atol issues
taminob 1f91271
add more euler bases to pattern
taminob d4f1b49
minor cleanup (renaming, comments, disable printing)
taminob 5620b9e
Revert "TMP, needs to be removed; allow OpenQASM export with round-tr…
taminob 82ba25d
remove armadillo in cmake
taminob 3d1dc8a
more cleanup
taminob 1eeedba
fix (?) tests
taminob 3afb374
fix final test
taminob 17b02c5
another minor cleanup
taminob ca9c9f1
clean sanity check prints up
taminob 0174a3d
properly add Eigen lib to cmake
taminob 3c70713
remove unnecessary correction
taminob 9f645a0
🎨 pre-commit fixes
pre-commit-ci[bot] b8f6b0b
fix eigen compilation issues
taminob 5cd8ca4
more cleanup
taminob 412a829
clean up weyl decomposition creation
taminob 6f04dbb
remove openqasm code generation
taminob eac38de
fix includes and use SmallVector instead of std::vector
taminob 4ea3120
fix or silence linter
taminob 0cf2292
incorporate coderabbitai feedback
taminob b4d419c
remove global phase accumulation
taminob 75672af
fix :math: latex formatting
taminob fe08c78
minor comment fixes
taminob 5128d83
replace CHECK-DAG by CHECK again
taminob 9194ae9
add comments to weyl decomposition
taminob ac4fb41
extract TwoQubitWeylDecomposition::getTrace()
taminob 56a2990
transform basis decomposer into actual class with private members
taminob 76ca4d0
attempt to fix CI test
taminob ec7f8c3
add supercontrolled check
taminob 49a769a
extract decomposition into headers
taminob 910384e
slight improvement to weyl decomposition for testing purposes
taminob 4c42850
add unittest for weyl decomposition
taminob 3453d2c
fix linter issues
taminob 7f0d1f6
add tests for basis decomposer
taminob e904dc1
fix linter issues
taminob c586338
clang-tidy: Add IgnoreHeader for include cleaner for Eigen
taminob f2efbcb
remove exact values from MLIR test
taminob 78daaba
fix mlir test/linter issues
taminob 741660e
remove std::numbers because not supported by all compilers in CI
taminob 9a6c691
remove unused Helpers.h from src dir
taminob ad8da23
remove auto* because of windows build
taminob 1e89778
try to fix windows ARM ci
taminob 854d9a0
pass matrices by reference
taminob 25b377d
allow non-optimal vectorization
taminob cd8ae96
🎨 pre-commit fixes
pre-commit-ci[bot] 2f634f5
try to fix
taminob f9b033d
integrate single-qubit decomposition
taminob aaab4b8
add tests for single-qubit decomposition
taminob fa78cbb
add unittests for euler decomposition
taminob d103e7a
fix linter issues
taminob 7fc31ae
fix include cleaner issues
taminob 43e9d31
add test parametrizations for other specializations
taminob 95424ee
add more matrix definitions
taminob a5c54e6
handle barrier gates in series collection
taminob aa3212d
🎨 pre-commit fixes
pre-commit-ci[bot] 474a5d9
fix include cleaner issues
taminob 21e9b7b
remove unused globalPhase from TwoQubitSeries
taminob 6815b26
fix barrier handling at start of series
taminob 202fa7f
simplify weyl specialization test parameters
taminob 49a60a7
remove dynamic_casts due to RTTI issue
taminob 8fc3b53
Revert "remove dynamic_casts due to RTTI issue"
taminob 68890af
move GateDecompositionPass to new QCO dialect
taminob 9a7006b
add GateDecompositionPass to compiler pipeline
taminob 935ad7d
🎨 pre-commit fixes
pre-commit-ci[bot] d296638
add UnitaryMatrixType to operation and add Eigen dependency to dialect
taminob a8dbfcb
first non-working attempt
taminob e9da9b0
second non-working attempt
taminob 5b325a5
compiling approach
taminob b3161cc
formatting
taminob 01886fb
avoid use of implementation-dependent argument names
taminob 30198a9
finally got template function working
taminob 1c7dd1d
add to compiler pipeline and add (failing) test case
taminob a8fbec2
make unitary function const, remove HasMatrixDefinition bool template…
taminob f9f7f04
start working on ctrl matrix
taminob d8d7b19
use new unitary matrix functions in GateDecompositionPattern
taminob ce79ed2
add debug prints
taminob 6c965ed
🎨 pre-commit fixes
pre-commit-ci[bot] 1588388
add helpers for CtrlOp matrix
taminob 00491d7
add matrix definition to all operations
taminob 69ebd05
fixes for unitary matrix definition
taminob df22236
fixes for gate decomposition pattern
taminob 31f4a02
fix formatting in MatrixUtils.h
taminob 9e2e0e6
(dirty) fix for CtrlOp in gate decomposition pattern; runs, but SSA e…
taminob f9e4ed4
Merge remote-tracking branch 'origin/main' into taminob/mlir-two-qubi…
taminob 0bb5a86
:memo: Add PR of unitary matrices to CHANGELOG
taminob a0051a9
remove matrix draft remains
taminob 1a8fa76
fix compilation issues with new matrix implementation
taminob 0514c54
🎨 pre-commit fixes
pre-commit-ci[bot] 1bb1f63
fix issue with CtrlOp
taminob 0334614
fixes and improvements (forceApplication+singleQubitOnly) for QCO dia…
taminob 98a703e
Merge remote-tracking branch 'origin/main' into taminob/mlir-two-qubi…
taminob 9fde078
🎨 pre-commit fixes
pre-commit-ci[bot] 7b93aec
fix nested ops issue and others in pass/pattern
taminob 7348caf
set GPhase complexity to 0 and fix complexity calculation for backtra…
taminob c46f159
thesis evaluation: add statistics and disable canonicalizations
taminob a79324c
evaluation scripts
taminob 90c46f4
evaluation results
taminob 3a8b02a
evaluation script fixes and improvements
taminob b4af378
update evaluation results
taminob 5e676bf
evaluate circuit collection for qiskit, total_evaluate fixes
taminob 2ddfc6c
update evaluation results
taminob 007b575
evaluation script improvements
taminob c66c4ec
update evaluation figures
taminob 8b7f0bc
Revert thesis evaluation changes
taminob 84a367a
Merge remote-tracking branch 'origin/main' into taminob/mlir-two-qubi…
taminob 595edb9
:memo: Add PR to CHANGELOG
taminob b506244
fix typo in comment
taminob a418cc1
improve naming in getDefaultNbasis
taminob 4b1a607
coderabbit feedback and cleanup
taminob f5b2ff1
remove broken unittest; need to think of ways to verify optimizations
taminob fd4f99b
remove helpers::kroneckerProduct, IDENTITY_GATE and fix unitary matrices
taminob ad50bef
more fixes
taminob 0b09375
relax isUnitaryMatrix() default tolerance to Eigen's default value
taminob bc905ed
fix mysterious segfault in Eigen::kroneckerProduct (still no idea why…
taminob ac7fb91
reduce random test time limit to 3s
taminob 80fa001
add C_ prefix to complex IM, M_IM
taminob f28b77e
remove custom types
taminob 69e989f
remove constants and other stuff
taminob 618f2dc
fix typo in comment
taminob b8cacc5
replace exceptions by llvm error reporting
taminob f50760d
some coderabbitai comments and complexity caching
taminob 4d1f561
remove crash test
taminob 9e1cab9
make Weyl decomposition non-trivial class; some other fixes
taminob f1b33bb
better random basis tests and other fixes
taminob fa2e420
more coderabbitai fixes
taminob aa3e9fa
add utils for tests
taminob b8ec913
coderabbit feedback
taminob b8e868c
fix includes
taminob a5af558
separate definitions into source files
taminob bb27f47
🎨 pre-commit fixes
pre-commit-ci[bot] be46de4
incorporate coderabbitai feedback and fix linter issues
taminob 4f608e5
remove constexpr from gate constants
taminob e2cbf76
🎨 pre-commit fixes
pre-commit-ci[bot] 61140da
improve comments, other minor fixes
taminob 799ed77
add some caching for available gates and improve comments
taminob 831628a
Merge remote-tracking branch 'origin/main' into taminob/mlir-two-qubi…
taminob 1a1a8fc
minor comment and one const fix
taminob 91c1f2a
fix annoying static initialization issue in gtest with Eigen
taminob a908ba5
switch to fully deterministic random matrix generation
taminob c8110be
fix potential alignment issues in SmallVector inline storage
taminob fae71dd
fix alignment issue for static-sized matrices on stack
taminob 926ab1b
🎨 pre-commit fixes
pre-commit-ci[bot] 9f264cf
Merge remote-tracking branch 'origin/main' into taminob/mlir-two-qubi…
taminob 38e2293
Merge remote-tracking branch 'origin/main' into taminob/mlir-two-qubi…
taminob 0c3a4cd
linter/coderabbit fixes
taminob e728711
remove static random generator for better reproducibility
taminob 7d9aa33
minor fixes
taminob b3b4a86
🎨 pre-commit fixes
pre-commit-ci[bot] 4ea6694
minor fixes
taminob 310d35a
reapply thesis-evaluation (revert 8b7f0bc5640cd93093db534bf608652c02a…
taminob 8f58cb4
evaluation script update: automated Qiskit Rust eval
taminob 97755cf
evaluation results
taminob e61854f
update qiskit python results without Rust timing code
taminob a3c68bf
add Qiskit copyright notice to decomposition classes
taminob 97c1187
add XZX euler basis to mqt decomposition
taminob 0b9a10d
update evaluation results for mqt and figures
taminob f4b6d7f
fix evaluation graph y axis + add improved circuit calculation
taminob b21868f
update figures for corrected y axis
taminob c3d412b
Revert thesis-evaluation changes
taminob 279a5b5
Merge remote-tracking branch 'origin/main' into taminob/mlir-two-qubi…
taminob 8a54aa1
fix compilation issues after merge
taminob 6c78c31
Merge remote-tracking branch 'origin/main' into taminob/mlir-two-qubi…
taminob d058d03
fix linter issue
taminob 7bc9a35
remove eigen alignment limit from cmake
taminob 044b3ff
Merge branch 'main' into HEAD
MatthiasReumann b88cc89
cleanup [skip ci]
taminob 9e84295
Merge branch 'main' into taminob/mlir-two-qubit-gate-decomposition-pass
burgholzer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| # 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 | ||
|
|
||
| set(LLVM_TARGET_DEFINITIONS Passes.td) | ||
| mlir_tablegen(Passes.h.inc -gen-pass-decls -name QCO) | ||
| add_public_tablegen_target(QcoPassesIncGen) | ||
| add_mlir_doc(Passes QcoPasses Passes/ -gen-pass-doc) |
235 changes: 235 additions & 0 deletions
235
mlir/include/mlir/Passes/Decomposition/BasisDecomposer.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,235 @@ | ||
| /* | ||
| * 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 "EulerBasis.h" | ||
| #include "GateSequence.h" | ||
| #include "WeylDecomposition.h" | ||
|
|
||
| #include <Eigen/Core> | ||
| #include <array> | ||
| #include <cassert> | ||
| #include <complex> | ||
| #include <cstdint> | ||
| #include <llvm/ADT/SmallVector.h> | ||
| #include <optional> | ||
| #include <utility> | ||
|
|
||
| namespace mlir::qco::decomposition { | ||
|
|
||
| /** | ||
| * Decomposer that must be initialized with a two-qubit basis gate that will | ||
| * be used to generate a circuit equivalent to a canonical gate (RXX+RYY+RZZ). | ||
| */ | ||
| class TwoQubitBasisDecomposer { | ||
| public: | ||
| /** | ||
| * Create decomposer that allows two-qubit decompositions based on the | ||
| * specified basis gate. | ||
| * This basis gate will appear between 0 and 3 times in each decompositions. | ||
| * The order of qubits is relevant and will change the results accordingly. | ||
| * The decomposer cannot handle different basis gates in the same | ||
| * decomposition (different order of the qubits also counts as a different | ||
| * basis gate). | ||
| */ | ||
| [[nodiscard]] static TwoQubitBasisDecomposer create(const Gate& basisGate, | ||
| double basisFidelity); | ||
|
|
||
| /** | ||
| * Perform decomposition using the basis gate of this decomposer. | ||
| * | ||
| * @param targetDecomposition Prepared Weyl decomposition of unitary matrix | ||
| * to be decomposed. | ||
| * @param target1qEulerBases List of euler bases that should be tried out to | ||
| * find the best one for each euler decomposition. | ||
| * All bases will be mixed to get the best overall | ||
| * result. | ||
| * @param basisFidelity Fidelity for lowering the number of basis gates | ||
| * required | ||
| * @param approximate If true, use basisFidelity or, if std::nullopt, use | ||
| * basisFidelity of this decomposer. If false, fidelity | ||
| * of 1.0 will be assumed. | ||
| * @param numBasisGateUses Force use of given number of basis gates. | ||
| */ | ||
| [[nodiscard]] std::optional<TwoQubitGateSequence> twoQubitDecompose( | ||
| const decomposition::TwoQubitWeylDecomposition& targetDecomposition, | ||
| const llvm::SmallVector<EulerBasis>& target1qEulerBases, | ||
| std::optional<double> basisFidelity, bool approximate, | ||
| std::optional<std::uint8_t> numBasisGateUses) const; | ||
|
|
||
| protected: | ||
| // NOLINTBEGIN(modernize-pass-by-value) | ||
| /** | ||
| * Constructs decomposer instance. | ||
| */ | ||
| TwoQubitBasisDecomposer( | ||
| Gate basisGate, double basisFidelity, | ||
| const decomposition::TwoQubitWeylDecomposition& basisDecomposer, | ||
| bool isSuperControlled, const Eigen::Matrix2cd& u0l, | ||
| const Eigen::Matrix2cd& u0r, const Eigen::Matrix2cd& u1l, | ||
| const Eigen::Matrix2cd& u1ra, const Eigen::Matrix2cd& u1rb, | ||
| const Eigen::Matrix2cd& u2la, const Eigen::Matrix2cd& u2lb, | ||
| const Eigen::Matrix2cd& u2ra, const Eigen::Matrix2cd& u2rb, | ||
| const Eigen::Matrix2cd& u3l, const Eigen::Matrix2cd& u3r, | ||
| const Eigen::Matrix2cd& q0l, const Eigen::Matrix2cd& q0r, | ||
| const Eigen::Matrix2cd& q1la, const Eigen::Matrix2cd& q1lb, | ||
| const Eigen::Matrix2cd& q1ra, const Eigen::Matrix2cd& q1rb, | ||
| const Eigen::Matrix2cd& q2l, const Eigen::Matrix2cd& q2r) | ||
| : basisGate{std::move(basisGate)}, basisFidelity{basisFidelity}, | ||
| basisDecomposer{basisDecomposer}, isSuperControlled{isSuperControlled}, | ||
| u0l{u0l}, u0r{u0r}, u1l{u1l}, u1ra{u1ra}, u1rb{u1rb}, u2la{u2la}, | ||
| u2lb{u2lb}, u2ra{u2ra}, u2rb{u2rb}, u3l{u3l}, u3r{u3r}, q0l{q0l}, | ||
| q0r{q0r}, q1la{q1la}, q1lb{q1lb}, q1ra{q1ra}, q1rb{q1rb}, q2l{q2l}, | ||
| q2r{q2r} {} | ||
| // NOLINTEND(modernize-pass-by-value) | ||
|
|
||
| /** | ||
| * Calculate decompositions when no basis gate is required. | ||
| * | ||
| * Decompose target :math:`\sim U_d(x, y, z)` with 0 uses of the | ||
| * basis gate. Result :math:`U_r` has trace: | ||
| * | ||
| * .. math:: | ||
| * | ||
| * \Big\vert\text{Tr}(U_r\cdot U_\text{target}^{\dag})\Big\vert = | ||
| * 4\Big\vert (\cos(x)\cos(y)\cos(z)+ j \sin(x)\sin(y)\sin(z)\Big\vert | ||
| * | ||
| * which is optimal for all targets and bases | ||
| * | ||
| * @note The inline storage of llvm::SmallVector must be set to 0 to ensure | ||
| * correct Eigen alignment via heap allocation | ||
| */ | ||
| [[nodiscard]] static llvm::SmallVector<Eigen::Matrix2cd, 0> | ||
| decomp0(const decomposition::TwoQubitWeylDecomposition& target); | ||
|
|
||
| /** | ||
| * Calculate decompositions when one basis gate is required. | ||
| * | ||
| * Decompose target :math:`\sim U_d(x, y, z)` with 1 use of the | ||
| * basis gate math:`\sim U_d(a, b, c)`. Result :math:`U_r` has trace: | ||
| * | ||
| * .. math:: | ||
| * | ||
| * \Big\vert\text{Tr}(U_r \cdot U_\text{target}^{\dag})\Big\vert = | ||
| * 4\Big\vert \cos(x-a)\cos(y-b)\cos(z-c) + j | ||
| * \sin(x-a)\sin(y-b)\sin(z-c)\Big\vert | ||
| * | ||
| * which is optimal for all targets and bases with ``z==0`` or ``c==0``. | ||
| * | ||
| * @note The inline storage of llvm::SmallVector must be set to 0 to ensure | ||
| * correct Eigen alignment via heap allocation | ||
| */ | ||
| [[nodiscard]] llvm::SmallVector<Eigen::Matrix2cd, 0> | ||
| decomp1(const decomposition::TwoQubitWeylDecomposition& target) const; | ||
|
|
||
| /** | ||
| * Calculate decompositions when two basis gates are required. | ||
| * | ||
| * Decompose target :math:`\sim U_d(x, y, z)` with 2 uses of the | ||
| * basis gate. | ||
| * | ||
| * For supercontrolled basis :math:`\sim U_d(\pi/4, b, 0)`, all b, result | ||
| * :math:`U_r` has trace | ||
| * | ||
| * .. math:: | ||
| * | ||
| * \Big\vert\text{Tr}(U_r \cdot U_\text{target}^\dag) \Big\vert = | ||
| * 4\cos(z) | ||
| * | ||
| * which is the optimal approximation for basis of CNOT-class | ||
| * :math:`\sim U_d(\pi/4, 0, 0)` or DCNOT-class | ||
| * :math:`\sim U_d(\pi/4, \pi/4, 0)` and any target. It may be sub-optimal | ||
| * for :math:`b \neq 0` (i.e. there exists an exact decomposition for any | ||
| * target using :math:`B \sim U_d(\pi/4, \pi/8, 0)`, but it may not be this | ||
| * decomposition). This is an exact decomposition for supercontrolled basis | ||
| * and target :math:`\sim U_d(x, y, 0)`. No guarantees for | ||
| * non-supercontrolled basis. | ||
| * | ||
| * @note The inline storage of llvm::SmallVector must be set to 0 to ensure | ||
| * correct Eigen alignment via heap allocation | ||
| */ | ||
| [[nodiscard]] llvm::SmallVector<Eigen::Matrix2cd, 0> decomp2Supercontrolled( | ||
| const decomposition::TwoQubitWeylDecomposition& target) const; | ||
|
|
||
| /** | ||
| * Calculate decompositions when three basis gates are required. | ||
| * | ||
| * Decompose target with 3 uses of the basis. | ||
| * | ||
| * This is an exact decomposition for supercontrolled basis | ||
| * :math:`\sim U_d(\pi/4, b, 0)`, all b, and any target. No guarantees for | ||
| * non-supercontrolled basis. | ||
| * | ||
| * @note The inline storage of llvm::SmallVector must be set to 0 to ensure | ||
| * correct Eigen alignment via heap allocation | ||
| */ | ||
| [[nodiscard]] llvm::SmallVector<Eigen::Matrix2cd, 0> decomp3Supercontrolled( | ||
| const decomposition::TwoQubitWeylDecomposition& target) const; | ||
|
|
||
| /** | ||
| * Calculate traces for a combination of the parameters of the canonical | ||
| * gates of the target and basis decompositions. | ||
| * This can be used to determine the smallest number of basis gates that are | ||
| * necessary to construct an equivalent to the canonical gate. | ||
| */ | ||
| [[nodiscard]] std::array<std::complex<double>, 4> | ||
| traces(const decomposition::TwoQubitWeylDecomposition& target) const; | ||
| /** | ||
| * Decompose a single-qubit unitary matrix into a single-qubit gate | ||
| * sequence. Multiple euler bases may be specified and the one with the | ||
| * least complexity will be chosen. | ||
| */ | ||
| [[nodiscard]] static OneQubitGateSequence | ||
| unitaryToGateSequence(const Eigen::Matrix2cd& unitaryMat, | ||
| const llvm::SmallVector<EulerBasis>& targetBasisList, | ||
| QubitId /*qubit*/, | ||
| // TODO: add error map here: per qubit a mapping of | ||
| // operation to error value for better calculateError() | ||
| bool simplify, std::optional<double> atol); | ||
|
|
||
| [[nodiscard]] static bool relativeEq(double lhs, double rhs, double epsilon, | ||
| double maxRelative); | ||
|
|
||
| private: | ||
| // basis gate of this decomposer instance | ||
| Gate basisGate{}; | ||
| // fidelity with which the basis gate decomposition has been calculated | ||
| double basisFidelity; | ||
| // cached decomposition for basis gate | ||
| decomposition::TwoQubitWeylDecomposition basisDecomposer; | ||
| // true if basis gate is super-controlled | ||
| bool isSuperControlled; | ||
|
|
||
| // pre-built components for decomposition with 3 basis gates | ||
| Eigen::Matrix2cd u0l; | ||
| Eigen::Matrix2cd u0r; | ||
| Eigen::Matrix2cd u1l; | ||
| Eigen::Matrix2cd u1ra; | ||
| Eigen::Matrix2cd u1rb; | ||
| Eigen::Matrix2cd u2la; | ||
| Eigen::Matrix2cd u2lb; | ||
| Eigen::Matrix2cd u2ra; | ||
| Eigen::Matrix2cd u2rb; | ||
| Eigen::Matrix2cd u3l; | ||
| Eigen::Matrix2cd u3r; | ||
|
|
||
| // pre-built components for decomposition with 2 basis gates | ||
| Eigen::Matrix2cd q0l; | ||
| Eigen::Matrix2cd q0r; | ||
| Eigen::Matrix2cd q1la; | ||
| Eigen::Matrix2cd q1lb; | ||
| Eigen::Matrix2cd q1ra; | ||
| Eigen::Matrix2cd q1rb; | ||
| Eigen::Matrix2cd q2l; | ||
| Eigen::Matrix2cd q2r; | ||
| }; | ||
|
|
||
| } // namespace mlir::qco::decomposition |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| /* | ||
| * 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 "ir/operations/OpType.hpp" | ||
|
|
||
| #include <cstdint> | ||
| #include <llvm/ADT/SmallVector.h> | ||
|
|
||
| namespace mlir::qco::decomposition { | ||
| /** | ||
| * Largest number that will be assumed as zero for the euler decompositions. | ||
| */ | ||
| inline constexpr auto DEFAULT_ATOL = 1e-12; | ||
|
|
||
| /** | ||
| * EulerBasis for a euler decomposition. | ||
| */ | ||
| enum class EulerBasis : std::uint8_t { | ||
| U3 = 0, | ||
| U321 = 1, | ||
| U = 2, | ||
| PSX = 3, | ||
| U1X = 4, | ||
| RR = 5, | ||
| ZYZ = 6, | ||
| ZXZ = 7, | ||
| XZX = 8, | ||
| XYX = 9, | ||
| ZSXX = 10, | ||
| ZSX = 11, | ||
| }; | ||
|
|
||
| /** | ||
| * Get list of gates potentially involved in euler basis after euler | ||
| * decomposition. | ||
| */ | ||
| [[nodiscard]] llvm::SmallVector<qc::OpType, 3> | ||
| getGateTypesForEulerBasis(EulerBasis eulerBasis); | ||
|
|
||
| } // namespace mlir::qco::decomposition | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.