- 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\times 2 matrix U with the property UU^\dagger=\mathbb{I}_2. As a result, a diagonal unitary operator \Delta 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 R_Z rotation.
As both are also diagonal unitary operators, they take the same form as \Delta, but with
\varphi_0=\varphi_1 and \varphi_0=-\varphi_1 for qml.GlobalPhase
and qml.RZ
,
respectively. Denoting the global phase angle as \phi and the R_Z rotation angle as \theta,
we find for their product:
If we want to find those angles \phi and \theta that reproduce the diagonal unitary operator \Delta, 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 A_0 and A_1 are two instances of the parametrized circuit A, and B_0 and B_1 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 R_Z 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 \theta_p and \phi_p from the pth pair of phases \{\exp(-i\varphi_{2p}), \exp(-i\varphi_{2p+1})\} from the original diagonal that we aim to implement:
For this, we extract the phase angles \vec{\varphi} (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 2^n 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 R_Z rotations (and a global phase):
The multiplexed R_Z rotations, qml.SelectPauliRot
in PennyLane, can then be decomposed individually. For more, see the
Select-U(2) compilation page.