You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Extend default decomposition of cirq.ControlledGate and cirq.ControlledOperation 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
0 commit comments