-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Extend default decomposition of cirq.ControlledGate
and cirq.ControlledOperation
to end in X/Y/Z/CZ target gateset
#5091
Merged
CirqBot
merged 4 commits into
quantumlib:master
from
tanujkhattar:controlled_gates_decomposition
Mar 17, 2022
Merged
Extend default decomposition of cirq.ControlledGate
and cirq.ControlledOperation
to end in X/Y/Z/CZ target gateset
#5091
CirqBot
merged 4 commits into
quantumlib:master
from
tanujkhattar:controlled_gates_decomposition
Mar 17, 2022
Conversation
This file contains 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
…edOperation to end in X/Y/Z/CZ target gateset
tanujkhattar
changed the title
Extend default decomposition of cirq.ControlledGate and cirq.ControlledOperation to end in X/Y/Z/CZ target gateset
Extend default decomposition of Mar 17, 2022
cirq.ControlledGate
and cirq.ControlledOperation
to end in X/Y/Z/CZ target gateset
95-martin-orion
requested changes
Mar 17, 2022
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First pass - I feel like I may need to stare at this some more to be confident that I understand the changes being made.
95-martin-orion
approved these changes
Mar 17, 2022
tanujkhattar
added
the
automerge
Tells CirqBot to sync and merge this PR. (If it's running.)
label
Mar 17, 2022
CirqBot
added
the
front_of_queue_automerge
CirqBot uses this label to indicate (and remember) what's being merged next.
label
Mar 17, 2022
CirqBot
removed
automerge
Tells CirqBot to sync and merge this PR. (If it's running.)
front_of_queue_automerge
CirqBot uses this label to indicate (and remember) what's being merged next.
labels
Mar 17, 2022
tonybruguier
pushed a commit
to tonybruguier/Cirq
that referenced
this pull request
Apr 14, 2022
…olledOperation` to end in X/Y/Z/CZ target gateset (quantumlib#5091) When decomposed, controlled gates and operations simply fall back on the decomposition of underlying sub_gate / sub_operation and return apply appropriate controls to each decomposed operation. If we can ensure that all underlying gates / operations decompose to X/Y/Z/CZ target gateset, then their controlled versions will decompose to: - Multi controlled single qubit rotations (corresponding to (X/Y/Z).controlled_by(...)) OR - Multi controlled CZs, which is also equivalent to a multi controlled single qubit rotation (Z.controlled_by(...)) In Cirq, we have an analytical method to decompose a multi controlled rotation into X/Y/Z/CZ - `cirq.decompose_multi_controlled_rotation`, which is now used in the `_decompose_` method of controlled gates. However, there are many corner cases and limitations of the current approach, which are dealt appropriately in this PR to enable a "best-effort" decomposition of controlled gates to the cirq target gateset. Some of the limitations are: - If decomposition of sub_gate / sub_operation ignores global phase, then the controlled operation cannot directly rely on decomposing the sub operation. An explicit check is added to not fallback on sub_gate if sub_gate is a MatrixGate. - `decompose_multi_controlled_rotation` works only for qubits (doesn't work for qudits) and when all control_values are 1. Appropriate logic is added to extend its functionality to handle control_values which are 0 or (0, 1). - We have explicit types for a few important controlled gates, like `CCZ`, `CZ`, `CCX`, `CX` etc. in cirq. Appropriate type conversion logic is added to smartly infer the types of equivalent gates (eg: Controlled(sub_gate=CZ) should be inferred as CCZ) such that their decompositions can be used for decomposing the controlled gates. This is definitely the most tricky one to get right and I've added appropriate tests to cover the different cases. Part of quantumlib#4858
rht
pushed a commit
to rht/Cirq
that referenced
this pull request
May 1, 2023
…olledOperation` to end in X/Y/Z/CZ target gateset (quantumlib#5091) When decomposed, controlled gates and operations simply fall back on the decomposition of underlying sub_gate / sub_operation and return apply appropriate controls to each decomposed operation. If we can ensure that all underlying gates / operations decompose to X/Y/Z/CZ target gateset, then their controlled versions will decompose to: - Multi controlled single qubit rotations (corresponding to (X/Y/Z).controlled_by(...)) OR - Multi controlled CZs, which is also equivalent to a multi controlled single qubit rotation (Z.controlled_by(...)) In Cirq, we have an analytical method to decompose a multi controlled rotation into X/Y/Z/CZ - `cirq.decompose_multi_controlled_rotation`, which is now used in the `_decompose_` method of controlled gates. However, there are many corner cases and limitations of the current approach, which are dealt appropriately in this PR to enable a "best-effort" decomposition of controlled gates to the cirq target gateset. Some of the limitations are: - If decomposition of sub_gate / sub_operation ignores global phase, then the controlled operation cannot directly rely on decomposing the sub operation. An explicit check is added to not fallback on sub_gate if sub_gate is a MatrixGate. - `decompose_multi_controlled_rotation` works only for qubits (doesn't work for qudits) and when all control_values are 1. Appropriate logic is added to extend its functionality to handle control_values which are 0 or (0, 1). - We have explicit types for a few important controlled gates, like `CCZ`, `CZ`, `CCX`, `CX` etc. in cirq. Appropriate type conversion logic is added to smartly infer the types of equivalent gates (eg: Controlled(sub_gate=CZ) should be inferred as CCZ) such that their decompositions can be used for decomposing the controlled gates. This is definitely the most tricky one to get right and I've added appropriate tests to cover the different cases. Part of quantumlib#4858
harry-phasecraft
pushed a commit
to PhaseCraft/Cirq
that referenced
this pull request
Oct 31, 2024
…olledOperation` to end in X/Y/Z/CZ target gateset (quantumlib#5091) When decomposed, controlled gates and operations simply fall back on the decomposition of underlying sub_gate / sub_operation and return apply appropriate controls to each decomposed operation. If we can ensure that all underlying gates / operations decompose to X/Y/Z/CZ target gateset, then their controlled versions will decompose to: - Multi controlled single qubit rotations (corresponding to (X/Y/Z).controlled_by(...)) OR - Multi controlled CZs, which is also equivalent to a multi controlled single qubit rotation (Z.controlled_by(...)) In Cirq, we have an analytical method to decompose a multi controlled rotation into X/Y/Z/CZ - `cirq.decompose_multi_controlled_rotation`, which is now used in the `_decompose_` method of controlled gates. However, there are many corner cases and limitations of the current approach, which are dealt appropriately in this PR to enable a "best-effort" decomposition of controlled gates to the cirq target gateset. Some of the limitations are: - If decomposition of sub_gate / sub_operation ignores global phase, then the controlled operation cannot directly rely on decomposing the sub operation. An explicit check is added to not fallback on sub_gate if sub_gate is a MatrixGate. - `decompose_multi_controlled_rotation` works only for qubits (doesn't work for qudits) and when all control_values are 1. Appropriate logic is added to extend its functionality to handle control_values which are 0 or (0, 1). - We have explicit types for a few important controlled gates, like `CCZ`, `CZ`, `CCX`, `CX` etc. in cirq. Appropriate type conversion logic is added to smartly infer the types of equivalent gates (eg: Controlled(sub_gate=CZ) should be inferred as CCZ) such that their decompositions can be used for decomposing the controlled gates. This is definitely the most tricky one to get right and I've added appropriate tests to cover the different cases. Part of quantumlib#4858
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
When decomposed, controlled gates and operations simply fall back on the decomposition of underlying sub_gate / sub_operation and return apply appropriate controls to each decomposed operation.
If we can ensure that all underlying gates / operations decompose to X/Y/Z/CZ target gateset, then their controlled versions will decompose to:
In Cirq, we have an analytical method to decompose a multi controlled rotation into X/Y/Z/CZ -
cirq.decompose_multi_controlled_rotation
, which is now used in the_decompose_
method of controlled gates.However, there are many corner cases and limitations of the current approach, which are dealt appropriately in this PR to enable a "best-effort" decomposition of controlled gates to the cirq target gateset. Some of the limitations are:
decompose_multi_controlled_rotation
works only for qubits (doesn't work for qudits) and when all control_values are 1. Appropriate logic is added to extend its functionality to handle control_values which are 0 or (0, 1).CCZ
,CZ
,CCX
,CX
etc. in cirq. Appropriate type conversion logic is added to smartly infer the types of equivalent gates (eg: Controlled(sub_gate=CZ) should be inferred as CCZ) such that their decompositions can be used for decomposing the controlled gates.This is definitely the most tricky one to get right and I've added appropriate tests to cover the different cases.
Part of #4858