-
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
Make sure all cirq gates decompose to XPow/YPow/ZPow/CZPow + Measurement #4858
Comments
How would this work? Is it possible to decompose any arbitrary |
@vtomole Yes. We have utilities in Cirq to decompose any arbitrary 2q Matrix Gate into the CZ gateset (see See https://github.com/quantumlib/Cirq/blob/master/cirq-core/cirq/transformers/analytical_decompositions/two_qubit_to_cz.py) and there's an open issue #4022 to add compilation of any arbitrary unitary to 1/2q gates |
…inate in `CZPowGate`. (quantumlib#4862) Part of quantumlib#4858 Decompositions are tested as part of `assert_eigengate_implements_consistent_protocols`, which is already tested for both gates.
I also think we should have |
…olledOperation` to end in X/Y/Z/CZ target gateset (#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 #4858
…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
…djacent swaps (quantumlib#5093) - Adds decomposition to `cirq.QubitPermutationGate` in terms of minimum number of adjacent swap operations on qubits. - Part of quantumlib#4858 Closes quantumlib#5090
…inate in `CZPowGate`. (quantumlib#4862) Part of quantumlib#4858 Decompositions are tested as part of `assert_eigengate_implements_consistent_protocols`, which is already tested for both gates.
…uantumlib#5083) - Adds support for decomposing parameterized `cirq.PhasedXPowGate`s. - Also modifies the decomposition to respect global phase, so that the decomposition is valid for controlled variants as well. - Part of quantumlib#4858
…uantumlib#5085) - Adds support for decomposing parameterized `cirq.DiagonalGate`. - Global phase is ignored for parameterized version because `cirq.GlobalPhaseGate` doesn't yet support symbols. - Part of quantumlib#4858
…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
…djacent swaps (quantumlib#5093) - Adds decomposition to `cirq.QubitPermutationGate` in terms of minimum number of adjacent swap operations on qubits. - Part of quantumlib#4858 Closes quantumlib#5090
…inate in `CZPowGate`. (quantumlib#4862) Part of quantumlib#4858 Decompositions are tested as part of `assert_eigengate_implements_consistent_protocols`, which is already tested for both gates.
…uantumlib#5083) - Adds support for decomposing parameterized `cirq.PhasedXPowGate`s. - Also modifies the decomposition to respect global phase, so that the decomposition is valid for controlled variants as well. - Part of quantumlib#4858
…uantumlib#5085) - Adds support for decomposing parameterized `cirq.DiagonalGate`. - Global phase is ignored for parameterized version because `cirq.GlobalPhaseGate` doesn't yet support symbols. - Part of quantumlib#4858
…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
…djacent swaps (quantumlib#5093) - Adds decomposition to `cirq.QubitPermutationGate` in terms of minimum number of adjacent swap operations on qubits. - Part of quantumlib#4858 Closes quantumlib#5090
As part of https://tinyurl.com/cirq-organize-decompose-rfc, we want to make sure that all cirq gates decompose to the XPow/YPow/ZPow/CZPow + Measuremet gateset.
This issue is to track all the gates where we need to explicitly add a
_decompose_
method to make sure all decompositions end on the above target gateset.We should also discuss what happens for gates where trivial decomposition is not present?
MatrixGates
: Should we add an analytical decomposition to the_decompose_
method of matrix gates?ControlledGate
s.P1 - I need this no later than the next release (end of quarter)
Part of #3242
The text was updated successfully, but these errors were encountered: