1. Compilation/
  2. 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 1|1\rangle) and "flipped" phase shifts (acting on the state 0|0\rangle). It is also useful to know their relationship to Pauli ZZ 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

Rϕ(ϕ)=(100eiϕ)R_\phi(\phi) = \begin{pmatrix} 1 & 0 \\ 0 & e^{i\phi} \end{pmatrix}

in the computational basis as a "generic" phase shift, or just phase shift.

Relationship to Pauli ZZ rotation

As the Pauli ZZ 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 \cong to express equality up to a global phase. Note that qml.GlobalPhase comes with a negative sign convention and RZ(ϕ)=exp(i12ϕZ)R_Z(\phi) = \exp(-i\tfrac{1}{2} \phi Z).

Controlled phase shift

If phase shifts need to be applied controlled by the state of some control qubits and we want to compile into RZR_Z 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) RZR_Z 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) RZR_Z 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 0|0\rangle, rather than the 1|1\rangle state, which we call a "flipped" phase shift, Rϕ0R^0_\phi. Its matrix representation in the computational basis is

Rϕ0(ϕ)=(eiϕ001).R^{0}_\phi(\phi) = \begin{pmatrix} e^{i\phi} & 0 \\ 0 & 1 \end{pmatrix}.

If we only have "generic" phase shifts available, we may decompose Rϕ0R^0_\phi 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

Rϕ0(a)=(eia001)=(0110)(100eia)(0110)=XRϕ(a)X.R^{0}_\phi(a) = \begin{pmatrix} e^{ia} & 0 \\ 0 & 1 \end{pmatrix} = \begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix} \begin{pmatrix} 1 & 0 \\ 0 & e^{ia} \end{pmatrix} \begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix} = X R_\phi(a) X.

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

Rϕ0(a)=(eia001)=(eia00eia)(100eia)Rϕ(a).R^{0}_\phi(a) = \begin{pmatrix} e^{ia} & 0 \\ 0 & 1 \end{pmatrix} = \begin{pmatrix} e^{ia} & 0 \\ 0 & e^{ia} \end{pmatrix} \begin{pmatrix} 1 & 0 \\ 0 & e^{-ia} \end{pmatrix} \cong R_{\phi}(-a).

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 1|1\rangle 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 RZR_Z 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 RZR_Z gate will simply flip the sign of its angle when pulling a Pauli XX gate through its target.