- Compilation/
Diagonal unitary decomposition
Diagonal unitary decomposition
Here, we show how the decomposition of a diagonal unitary operator comes about. We will first look at the single-qubit case and then generalize. We will also outline the recursion that leads to the complete decomposition.
Single-qubit diagonal unitary
A single-qubit unitary operator is described by a 2×2 matrix U with the property UU†=I2. As a result, a diagonal unitary operator Δ on one qubit has a diagonal with two entries, a and b, that satisfy
We will decompose this diagonal operator into a product of global phase and an RZ rotation.
As both are also diagonal unitary operators, they take the same form as Δ, but with
φ0=φ1 and φ0=−φ1 for qml.GlobalPhase
and qml.RZ
,
respectively. Denoting the global phase angle as ϕ and the RZ rotation angle as θ,
we find for their product:
If we want to find those angles ϕ and θ that reproduce the diagonal unitary operator Δ, we just need to equate the matrices and solve for the angles:
To conclude this section, we draw the single-qubit decomposition:

Generalizing to multiple qubits
To generalize the decomposition from one to multiple qubits, we take two steps: first, we establish the general form this decomposition should assume, and second, we calculate the corresponding angles.
The first step results from the so-called Multiplexer Extension Property (MEP) [1], which states that attaching multiplexer nodes to a circuit identity yields a valid circuit identity again. That is, given a circuit identity
0: ─A─┤ = ─B─┤,
for parametrized circuits A and B, we may conclude that
0: ─╭◻─┤ = ─╭○───╭●──┤ = ─╭○───╭●──┤ = ─╭◻─┤
1: ─╰A─┤ ─╰A0──╰A1─┤ ─╰B0──╰B1─┤ ─╰B─┤,
where A0 and A1 are two instances of the parametrized circuit A, and B0 and B1 are the equivalent instances of B. Applying multiple multiplexing nodes follows the same logic and results in valid circuit identities again.
Note that a multi-qubit diagonal operator can be interpreted as a multiplexed single-qubit diagonal operator, which generally takes the form of a block diagonal matrix. This is because a diagonal matrix is a special case of a block-diagonal matrix. Therefore, we can directly apply the MEP to the single-qubit decomposition from above and add n−1 multiplexing nodes to obtain the following decomposition of a multi-qubit diagonal unitary:

Where we used the fact that a multiplexed global phase is the same as a diagonal operator on the controlling qubits.
For the second step, i.e., the calculation of the parameters in the decomposition, we may again generalize the single-qubit scenario. For each basis state on the control qubits, the multiplexed phase, which then becomes a smaller diagonal operator, applies the same phase to two basis states of the target qubit. Similarly, the multiplexed RZ rotation applies phases with opposite sign to the target, with individual phases chosen for each control state. The matrix equation for the decomposition above then reads
Now, we can apply the same strategy as in the single-qubit case to each pair of matrix entries. That is, we can compute the parameters θp and ϕp from the pth pair of phases {exp(−iφ2p),exp(−iφ2p+1)} from the original diagonal that we aim to implement:
For this, we extract the phase angles φ (e.g., using np.angle
),
and compute
to find the required parameters.
This means that we just need to chain together np.angle
, some indexing, np.mean
and
subtraction in order to compute the parameters. This does not require much computational
effort, which is fortunate because a diagonal operator on n qubits has 2n entries and quickly
becomes expensive to handle. An implementation of this can be found in
PennyLane's qml.DiagonalQubitUnitary
.
Recursive decomposition
To conclude, we can apply the decomposition from above recursively to break down a multi-qubit diagonal unitary operator into multiplexed RZ rotations (and a global phase):

The multiplexed RZ rotations, qml.SelectPauliRot
in PennyLane, can then be decomposed individually. For more, see the
Select-U(2) compilation page.