- Compilation/
Control logic decompositions
Control logic decompositions
Phase shift operators are omnipresent in quantum computing. Depending on the abstraction of the quantum programming language used and the preferred representation, it is convenient to be able to translate between "generic" phase shifts ( which are defined to act on the state ) and "flipped" phase shifts (acting on the state ). It is also useful to know their relationship to Pauli rotations and how all these relationships translate to controlled versions.
The most significant equivalence from this page might be
0: ──╭Rϕ(a)─┤ ≅ 0: ──╭RZ(a)──────────────────────────────────────┤ 1: ──├●─────┤ 1: ──├●─────╭RZ(a/2)─────────────────────────────┤ 2: ──╰●─────┤ 2: ──╰●─────╰●────────RZ(a/4)──GlobalPhase(-a/8)─┤.
We will refer to the operator with matrix representation
in the computational basis as a "generic" phase shift, or just phase shift.
Relationship to Pauli rotation
As the Pauli rotation gate and the phase shift gate both just cause a relative phase change, they are equivalent to each other up to a global phase:
──Rϕ(a)─┤ = ──RZ(a)──GlobalPhase(-a/2)─┤ ≅ ──RZ(a)──┤,
where we used to express equality up to a global phase. Note that qml.GlobalPhase comes with a negative sign convention and .
Controlled phase shift
If phase shifts need to be applied controlled by the state of some control qubits and we want to compile into gates, we need to pay attention to the global phases mentioned in the previous section. In turn, decomposing a (multi-) controlled global phase yields (smaller) controlled phase shifts. See the tab on controlled global phases for more details.
This leads to the following cascading decomposition into (controlled) gates, exemplified for two controls:
0: ──╭Rϕ(a)─┤ 1: ──├●─────┤ 2: ──╰●─────┤ = 0: ──╭RZ(a)─╭GlobalPhase(-a/2)─┤ 1: ──├●─────├●─────────────────┤ 2: ──╰●─────╰●─────────────────┤ = 0: ──╭RZ(a)───────────┤ 1: ──├●─────╭Rϕ(a/2)──┤ 2: ──╰●─────╰●────────┤ = 0: ──╭RZ(a)─────────────────────────────┤ 1: ──├●─────╭RZ(a/2)─╭GlobalPhase(-a/4)─┤ 2: ──╰●─────╰●───────╰●─────────────────┤ = 0: ──╭RZ(a)───────────────────┤ 1: ──├●─────╭RZ(a/2)──────────┤ 2: ──╰●─────╰●────────Rϕ(a/4)─┤ ≅ 0: ──╭RZ(a)───────────────────┤ 1: ──├●─────╭RZ(a/2)──────────┤ 2: ──╰●─────╰●────────RZ(a/4)─┤
As we can see, the seemingly harmless equivalence up to a global phase has a significant impact on the controlled decomposition if we represent it as (controlled) rotations. The actual impact on the gate count of course will depend on further decompositions of the controlled rotations.
"Flipped" phase shift
In many scenarios, we would like to apply a phase shift to the , rather than the state, which we call a "flipped" phase shift, . Its matrix representation in the computational basis is
If we only have "generic" phase shifts available, we may decompose by flipping the qubit before and after a "generic" shift with the same angle:
──Rϕ^0(a)─┤ = ──X──Rϕ(a)──X─┤.
In matrix representation, this equality reads
Alternatively, we may recognize that a phase shift really just affects the phases relative to each other, and write
──Rϕ^0(a)─┤ = ──Rϕ(-a)──GlobalPhase(-a)─┤ ≅ ──Rϕ(-a)──┤ ≅ ──RZ(-a)──┤.
In matrix representation, this equality reads
Controlled "flipped" phase shifts
Finally, we combine the controlled phase shift logic from the beginning with the "flipped" phase shifts discussed just above.
For simplicity, we start with a single control qubit controlling a "flipped" phase shift on its state:
0: ──╭●───────┤ 1: ──╰Rϕ^0(a)─┤.
The explicit bit flip decomposition from above naively would lead to the circuit
0: ──╭●───────┤ = 0: ──╭●──╭●─────╭●─┤ 1: ──╰Rϕ^0(a)─┤ 1: ──╰X──╰Rϕ(a)─╰X─┤.
However, we may apply the controlled compute/uncompute simplification to reduce the circuit to
0: ──╭●───────┤ = 0: ─────╭●────────┤ 1: ──╰Rϕ^0(a)─┤ 1: ──X──╰Rϕ(a)──X─┤.
If we use the second decomposition from above, we arrive at
0: ──╭●───────┤ = 0: ──╭●───────╭●───────────────┤ = 0: ──╭●───────Rϕ(a)─┤ 1: ──╰Rϕ^0(a)─┤ 1: ──╰Rϕ(-a)──╰GlobalPhase(-a)─┤ 1: ──╰Rϕ(-a)────────┤,
which requires a second parametrized gate. Note that if we decompose to gates as we did above, we find for the two decompositions
0: ──╭●───────┤ ≅ 0: ─────╭●──────RZ(a/2)─┤ 1: ──╰Rϕ^0(a)─┤ 1: ──X──╰RZ(a)──X───────┤,
and
0: ──╭●───────┤ ≅ 0: ──╭●───────RZ(a/2)─┤ 1: ──╰Rϕ^0(a)─┤ 1: ──╰RZ(-a)──────────┤,
respectively. Those are equivalent because the controlled gate will simply flip the sign of its angle when pulling a Pauli gate through its target.