PennyLane
  • Why PennyLane
  • Getting Started
  • Documentation
  • Ecosystem
Install
Install
  1. Compilation/
  2. Diagonal unitary decomposition

Diagonal unitary decomposition

OverviewDetailsResources

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

\Delta\Delta^\dagger = \begin{pmatrix} a & 0 \\ 0 & b \end{pmatrix} \begin{pmatrix} a^\ast & 0 \\ 0 & b^\ast \end{pmatrix} = \begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix} \ \ \Rightarrow\ \ a = e^{-i\varphi_0}, b=e^{-i\varphi_1}.

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:

\begin{pmatrix} e^{-\frac{i}{2}\theta} & 0 \\ 0 & e^{\frac{i}{2}\theta} \end{pmatrix} \begin{pmatrix} e^{-i\phi} & 0 \\ 0 & e^{-i\phi} \end{pmatrix} = \begin{pmatrix} e^{-i(\phi + \tfrac{1}{2}\theta)} & 0 \\ 0 & e^{-i(\phi - \tfrac{1}{2}\theta)} \end{pmatrix}

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:

\theta = \varphi_0 - \varphi_1,
\phi = \frac{1}{2}(\varphi_0 + \varphi_1).

To conclude this section, we draw the single-qubit decomposition:

Decomposition of a single-qubit diagonal unitary operator

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:

Decomposition of a multi-qubit diagonal unitary operator

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

\operatorname{diag}\begin{pmatrix} e^{-i\varphi_0} \\ e^{-i\varphi_1} \\ e^{-i\varphi_2} \\ e^{-i\varphi_3} \\ \vdots \\ e^{-i\varphi_{2^{n}-1}} \end{pmatrix} = \operatorname{diag}\begin{pmatrix} e^{-\tfrac{i}{2}\theta_0} \\ e^{\tfrac{i}{2}\theta_0} \\ e^{-\tfrac{i}{2}\theta_1} \\ e^{\tfrac{i}{2}\theta_1} \\ \vdots \\ e^{\tfrac{i}{2}\theta_{2^{n-1}-1}} \end{pmatrix} \operatorname{diag}\begin{pmatrix} e^{-i\phi_0} \\ e^{-i\phi_0} \\ e^{-i\phi_1} \\ e^{-i\phi_1} \\ \vdots \\ e^{-i\phi_{2^{n-1}-1}} \end{pmatrix}.

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:

e^{-i(\phi_p+\tfrac{1}{2}\theta_p)} = e^{-i\varphi_{2p\phantom{+1}}}
e^{-i(\phi_p-\tfrac{1}{2}\theta_p)} = e^{-i\varphi_{2p+1}}.

For this, we extract the phase angles \vec{\varphi} (e.g., using np.angle), and compute

\phi_p = \tfrac{1}{2}(\varphi_{2p} + \varphi_{2p+1}),\quad \theta_p = \varphi_{2p} - \varphi_{2p+1},

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):

Recursive decomposition of a multi-qubit diagonal into multiplexed rotations

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

PennyLane

PennyLane is an open-source software framework for quantum machine learning, quantum chemistry, and quantum computing, with the ability to run on all hardware. Built with ❤️ by Xanadu.

Stay updated with our newsletter

For researchers

  • Research
  • Features
  • Demos
  • Compilation
  • Datasets
  • Performance
  • Learn
  • Videos
  • Documentation
  • Teach

For learners

  • Learn
  • Codebook
  • Teach
  • Videos
  • Challenges
  • Demos
  • Compilation
  • Glossary

For developers

  • Features
  • Documentation
  • API
  • GitHub
  • Datasets
  • Demos
  • Compilation
  • Performance
  • Devices
  • Catalyst

© Copyright 2025 | Xanadu | All rights reserved

TensorFlow, the TensorFlow logo and any related marks are trademarks of Google Inc.

Privacy Policy|Terms of Service|Cookie Policy|Code of Conduct