-
-
Notifications
You must be signed in to change notification settings - Fork 36
Decomposition #920
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
Open
cs-tum-st
wants to merge
91
commits into
munich-quantum-toolkit:main
Choose a base branch
from
cs-tum-st:decomposition
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.
Open
Decomposition #920
Changes from all commits
Commits
Show all changes
91 commits
Select commit
Hold shift + click to select a range
5a2d414
Combining Gates and builing combined U3 works.
cs-tum-st 8d4bb8f
Changed internal handling of U3 gates.
cs-tum-st bedfeaa
Merge branch 'munich-quantum-toolkit:main' into decomposition
cs-tum-st 75caf7b
Changed
cs-tum-st 9134d22
Added more Tests
cs-tum-st 8c75e53
Merge branch 'main' into decomposition
ystade 1344160
🎨 pre-commit fixes
pre-commit-ci[bot] 802b829
🎨 Adjust to naming convention
ystade 20c47a9
🎨 Rename to NativeGateDecomposer and include in Compiler
ystade 8fac867
🎨 Fix newly introduced bugs
ystade 59fcb5e
🎨 Add nQubits to decompose interface and fix resulting bugs
ystade 8933446
🎨 Improve docstring
ystade 2931f5d
🎨 Improve docstrings
ystade b789b03
Fixed errors translating gates into Quaternions
cs-tum-st f93ed5e
🎨 pre-commit fixes
pre-commit-ci[bot] b5c499d
Fixed errors translating gates into Quaternions
cs-tum-st d1bf227
Merge remote-tracking branch 'origin/decomposition' into decomposition
cs-tum-st 31e85de
🎨 pre-commit fixes
pre-commit-ci[bot] 371ff1f
Adressed an outdated Test and some signed/unsigned type issues
cs-tum-st a4421de
Merge remote-tracking branch 'origin/decomposition' into decomposition
cs-tum-st 3092711
🎨 pre-commit fixes
pre-commit-ci[bot] fe4e45c
switched abs with fabs
cs-tum-st 2302213
switched abs with fabs
cs-tum-st 9504e59
Merge remote-tracking branch 'origin/decomposition' into decomposition
cs-tum-st 5879e7f
made some changes to pushing decomposed operations into layers
cs-tum-st ebe3904
made some changes to pushing decomposed operations into layers
cs-tum-st 0f0d429
🎨 pre-commit fixes
pre-commit-ci[bot] 5eaaa45
Merge remote-tracking branch 'origin/decomposition' into decomposition
cs-tum-st 4873706
Merge branch 'main' into decomposition
cs-tum-st 844e78c
minor comment change
cs-tum-st 837e08f
Merge remote-tracking branch 'origin/decomposition' into decomposition
cs-tum-st 0b2de5a
added check for empty target vector in operation
cs-tum-st b9e34ca
🎨 pre-commit fixes
pre-commit-ci[bot] 48accfa
Merge branch 'main' into decomposition
cs-tum-st cdaf880
Coverage Tests added
cs-tum-st 2f96f6e
🎨 pre-commit fixes
pre-commit-ci[bot] 49386a5
Small fixes
cs-tum-st a3f5ac3
Small fixes
cs-tum-st 396036e
Merge remote-tracking branch 'origin/decomposition' into decomposition
cs-tum-st c048044
Combining Gates and builing combined U3 works.
cs-tum-st 4c2e71f
Changed internal handling of U3 gates.
cs-tum-st d45825b
Changed
cs-tum-st a5df7ff
Added more Tests
cs-tum-st 5abc59a
⬆️🪝 Update patch versions (#917)
renovate[bot] 0cf313f
♻️ Auto-generate stub files (#916)
denialhaag 64a154a
⬆️🔒️ Lock file maintenance (#919)
renovate[bot] 604bc22
🎨 pre-commit fixes
pre-commit-ci[bot] 78041d9
🎨 Adjust to naming convention
ystade f8c962b
🎨 Rename to NativeGateDecomposer and include in Compiler
ystade 12ced4c
🎨 Fix newly introduced bugs
ystade e08023b
🎨 Add nQubits to decompose interface and fix resulting bugs
ystade 21e7c6c
🎨 Improve docstring
ystade f1b778e
🎨 Improve docstrings
ystade ca6f971
Fixed errors translating gates into Quaternions
cs-tum-st f1e211c
Fixed errors translating gates into Quaternions
cs-tum-st accf727
🎨 pre-commit fixes
pre-commit-ci[bot] 917ae75
Adressed an outdated Test and some signed/unsigned type issues
cs-tum-st 49136f1
🎨 pre-commit fixes
pre-commit-ci[bot] a42674e
switched abs with fabs
cs-tum-st dfc4030
switched abs with fabs
cs-tum-st 1047c35
made some changes to pushing decomposed operations into layers
cs-tum-st 96b84f9
made some changes to pushing decomposed operations into layers
cs-tum-st 9fefb28
🎨 pre-commit fixes
pre-commit-ci[bot] abf5564
minor comment change
cs-tum-st 5710c28
⬆️ Update `prek` checks (#925)
denialhaag 6a30a7c
⬆️🔒️ Lock file maintenance (#926)
renovate[bot] 7d1d343
⬆️🪝 Update patch versions (#922)
renovate[bot] 5961eec
⬆️ Update `munich-quantum-toolkit/core` (#924)
mqt-app[bot] 7ab6b3b
⬆️🪝 Update pre-commit hook astral-sh/ruff-pre-commit to v0.15.0 (#929)
renovate[bot] 5b53957
⬆️🐍 Update dependency ty to v0.0.15 (#927)
renovate[bot] 93ec973
⬆️🪝 Update pre-commit hook astral-sh/uv-pre-commit to v0.10.0 (#930)
renovate[bot] 18b3c20
⬆️🔒️ Lock file maintenance (#931)
renovate[bot] fd46fef
added check for empty target vector in operation
cs-tum-st 0f93636
🎨 pre-commit fixes
pre-commit-ci[bot] 3100f6f
⬆️🪝 Update pre-commit hook adhtruong/mirrors-typos to v1.43.2 (#928)
renovate[bot] 4189f4b
Bump pillow from 12.1.0 to 12.1.1 in the uv group across 1 directory …
dependabot[bot] b79673b
⬆️🪝 Update pre-commit hook henryiii/validate-pyproject-schema-store t…
renovate[bot] 9e51b68
⬆️🔒️ Lock file maintenance (#935)
renovate[bot] 9a96db8
Coverage Tests added
cs-tum-st c2700b5
Small fixes
cs-tum-st b538c37
🎨 pre-commit fixes
pre-commit-ci[bot] e732563
Copy elison fix
cs-tum-st 68d3982
Merge remote-tracking branch 'origin/decomposition' into decomposition
cs-tum-st 6d8be44
Apply suggestions from code review
ystade cf8eacc
🔥 Remove artefacts
ystade 0606012
🎨 Make param const
ystade 6822ef3
Merge remote-tracking branch 'origin/main' into fork/cs-tum-st/decomp…
ystade c679c7a
✨ Add python bindings for native gate compiler
ystade d417399
🎨 Add compiler to python interface
ystade b3d4585
🎨 Replace if by switch
ystade 934862d
🎨 Some code improvements and clean-ups
ystade 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
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,133 @@ | ||
| /* | ||
| * 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 "DecomposerBase.hpp" | ||
| #include "ir/operations/StandardOperation.hpp" | ||
| #include "na/zoned/Types.hpp" | ||
|
|
||
| #include <vector> | ||
|
|
||
| namespace na::zoned { | ||
|
|
||
| class NativeGateDecomposer : public DecomposerBase { | ||
| /** | ||
| * A minimal struct to store the parameters of a U3 gate along with the qubit | ||
| * it acts on. | ||
| */ | ||
|
cs-tum-st marked this conversation as resolved.
|
||
| struct StructU3 { | ||
|
cs-tum-st marked this conversation as resolved.
|
||
| std::array<qc::fp, 3> angles; | ||
| qc::Qubit qubit; | ||
| }; | ||
| /** | ||
| * A quaternion is represented by an array of four `qc::fp` values `{q0, q1, | ||
| * q2, q3}` denoting the components of the quaternion. | ||
| */ | ||
| using Quaternion = std::array<qc::fp, 4>; | ||
|
cs-tum-st marked this conversation as resolved.
|
||
| size_t nQubits_ = 0; | ||
|
|
||
| /// Tolerance for floating-point comparisons, scaled to account for | ||
| /// accumulated rounding errors in quaternion arithmetic (~10 bits margin). | ||
| constexpr static qc::fp epsilon = | ||
| std::numeric_limits<qc::fp>::epsilon() * 1024; | ||
|
ystade marked this conversation as resolved.
|
||
|
|
||
| public: | ||
| /// The configuration of the NativeGateDecomposer | ||
| struct Config { | ||
| template <typename BasicJsonType> | ||
| friend void to_json(BasicJsonType& /* unused */, | ||
| const Config& /* unused */) {} | ||
| template <typename BasicJsonType> | ||
| friend void from_json(const BasicJsonType& /* unused */, | ||
| Config& /* unused */) {} | ||
| }; | ||
|
|
||
| private: | ||
| /** | ||
| * @brief Takes a vector of SingleQubitGateLayers and, for each layer, | ||
| * transforms all gates into U3 gates represented by `StructU3` objects. | ||
| * @details It combines all gates acting on the same qubit into a single U3 | ||
| * gate. | ||
| * @param layers is a std::vector of SingleQubitGateLayers of a scheduled | ||
| * circuit. | ||
| * @returns a vector of vectors of StructU3 objects representing the single | ||
| * qubit gate layers. | ||
| */ | ||
| [[nodiscard]] auto | ||
| transformToU3(const std::vector<SingleQubitGateRefLayer>& layers) const | ||
| -> std::vector<std::vector<StructU3>>; | ||
|
|
||
| public: | ||
| /// Create a new NativeGateDecomposer. | ||
| NativeGateDecomposer(const Architecture& /* unused */, | ||
| const Config& /* unused */) {} | ||
|
cs-tum-st marked this conversation as resolved.
|
||
|
|
||
| /** | ||
| * @brief Converts commonly used single qubit gates into their Quaternion | ||
| * representation. | ||
| * @details A single qubit gate R_v(phi) with rotation axis v=(v0,v1,v2) | ||
| * and rotation angle phi can be represented as a quaternion: | ||
| * @code quaternion(R_v(phi)) = (cos(phi/2) * I, v0 * sin(phi/2) * X, v1 * | ||
| * sin(phi/2) * Y, v2 * sin(phi/2) * Z)@endcode with X, Y, Z Pauli Matrices. | ||
| * @param op a reference_wrapper to the operation to be converted | ||
| * @returns a quaternion. | ||
| */ | ||
| static auto | ||
| convertGateToQuaternion(std::reference_wrapper<const qc::Operation> op) | ||
| -> Quaternion; | ||
| /** | ||
| * @brief Merges the quaternions representing two gates as in a matrix | ||
| * multiplication of the gates. | ||
| * @param q1 the first quaternion to be combined. | ||
| * @param q2 the second quaternion to be combined. | ||
| * @returns an quaternion. | ||
| */ | ||
| static auto combineQuaternions(const Quaternion& q1, const Quaternion& q2) | ||
| -> Quaternion; | ||
| /** | ||
| * @brief Calculates the values of the U3-gate parameters theta, phi, and | ||
| * lambda. | ||
| * @param quat is a quaternion representing a single qubit gate. | ||
| * @returns an array of three `qc::fp` values `{theta, phi, lambda}` giving | ||
| * the U3 gate angles. | ||
| */ | ||
| static auto getU3AnglesFromQuaternion(const Quaternion& quat) | ||
| -> std::array<qc::fp, 3>; | ||
|
|
||
| /** | ||
| * @brief Calculates the largest value of the U3-gate parameter theta from a | ||
| * vector of operations. | ||
| * @param layer is a vector of U3 parameters. | ||
| * @returns the maximal value of theta in the given layer. | ||
| */ | ||
| static auto calcThetaMax(const std::vector<StructU3>& layer) -> qc::fp; | ||
|
|
||
| /** | ||
| * @brief Takes a vector of `qc::fp` representing the U3-gate angles of a | ||
| * single-qubit gate and the maximal value of theta for the single qubit gate | ||
| * layer and calculates the transversal decomposition angles as in Nottingham | ||
| * et. al. 2024. | ||
| * @param angles is a `std::array` of `qc::fp` representing (theta, phi, | ||
| * lambda). | ||
| * @param theta_max the maximal theta value of the single-qubit gate layer. | ||
| * @returns an array of `qc::fp` values giving the angles (chi, gamma_minus, | ||
| * gamma_plus). | ||
| */ | ||
| auto static getDecompositionAngles(const std::array<qc::fp, 3>& angles, | ||
| qc::fp theta_max) -> std::array<qc::fp, 3>; | ||
|
|
||
| [[nodiscard]] auto | ||
| decompose(size_t nQubits, | ||
| const std::vector<SingleQubitGateRefLayer>& singleQubitGateLayers) | ||
| -> std::vector<SingleQubitGateLayer> override; | ||
| }; | ||
|
|
||
| } // namespace na::zoned | ||
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
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.