PennyLane
Install
Install
  1. Compilation/
  2. Phase gradient

Phase gradient

OverviewState propertiesPhase gradient rotationsControl rotationsMultiplexed rotationsResources

Here we show how a phase gradient state can be used to implement a rotation gate within a given precision \varepsilon. We will make use of the properties of phase gradient states described in the state properties tab.

For simplicity, we will consider a single-qubit qml.RZ rotation gate, i.e., we are looking to implement

|ψ>: ─RZ(θ)─┤,

with a given precision \varepsilon for the rotation angle \theta. Here, |\psi\rangle denotes the initial state on the qubit that we target with the rotation. If we were to implement a different Pauli product rotation gate, we would conjugate it by Clifford gates to transform it into an RZ gate and then implement it with the procedure described here.

Note that any number x\in [0,1) can be represented with a precision of \varepsilon using b=\lceil\log_2(1/\varepsilon)\rceil bits.

Here, we will look at the example \theta=2.6781\pi with precision \varepsilon=0.1. Note that in practice, \varepsilon usually is chosen without knowledge about the angles that are going to be implemented.

Canonicalize and discretize angle and precision

The first step is to adjust and discretize the rotation angle, according to the desired precision \varepsilon. More precisely, we pick the angle \theta' so that \theta =\theta' \!\!\mod 2\pi and \theta'\in[0, 2\pi), by splitting off multiples of 2\pi, which corresponds to powers of the global phase (-1).

For our example, we split off 2\pi, corresponding to the phase (-1), so that \theta'= 0.6781 \pi\in [0, 2\pi) and our circuit becomes

|ψ>: ─RZ(θ')──(-1)─┤.

Then we "change units" by dividing both \theta' and \varepsilon by 2\pi, obtaining \theta'' and \varepsilon'' (we skip \varepsilon' in the variable names). As we have \theta''\in [0, 1), it can be encoded up to precision \varepsilon'' with b=\lceil\log(1/\varepsilon'')\rceil bits. (To verify this, note that the largest deviation that can occur by cutting off all subsequent bits is bounded by 2^{-b}, i.e., it is bounded by 2^{-\lceil\log_2(1/\varepsilon'')\rceil}\leq\varepsilon'', exactly the desired precision. Since we are only considering approximation by rounding down, this can still be improved.) We call the discretized angle, in form of a length-b bit string, \phi.

In our example, changing units yields \theta''\approx0.33905 and \varepsilon''=0.1/(2\pi)\approx 0.01592. We have b=\lceil \log_2(2\pi/0.1)\rceil=6 and a finite-precision approximation of \theta'' is \phi=(0.010101)_2=(0.3281)_{10} with an approximation error of |\theta''-\phi|\approx 0.01093 < \varepsilon''. Here, the subscript (\dots)_2 indicates a binary representation, i.e., (0.010101)_2=0\cdot 2^0 + 0\cdot 2^{-1}+1\cdot 2^{-2} + \dots +1\cdot 2^{-6}.

Encoding bit strings

In the next step, we require an auxiliary register of size b=\lceil\log_2(1/\varepsilon'')\rceil that is in the zeroed state |0\rangle^{\otimes b}. We can encode \phi, or more precisely B\phi where we set B=2^b, in this register with simple bit flips.

Here, we want to control this collection of bit flips on the state in the target qubit of our rotation. Such a multi-target CNOT gate also is known as fan-out, and can be implemented, for example, with sequential CNOT gates.

For our example, we have to flip every other bit to encode B\phi=(010101)_2:

|0>   : ───┤ |0> ╮
|0>   : ─X─┤ |1> │
|0>   : ───┤ |0> ├ Bϕ
|0>   : ─X─┤ |1> │
|0>   : ───┤ |0> │
|0>   : ─X─┤ |1> ╯

and the controlled version accordingly looks like this:

|ψ>: ─╭●─┤
|0>: ─│──┤
|0>: ─├X─┤
|0>: ─│──┤
|0>: ─├X─┤
|0>: ─│──┤
|0>: ─╰X─┤.

Entrance: phase gradient

For the next step, a register with b qubits in the phase gradient state

|\nabla_b\rangle = \frac{1}{\sqrt{B}} \sum_{k=0}^{B-1} e^{-2\pi i \tfrac{k}{B}} |k\rangle

is needed. Note that if we are given a register with c>b qubits in the state |\nabla_c\rangle, we can just use the first b qubits of that register.

Adding a b-qubit integer M to the state |\nabla_b\rangle results in a global phase,

|\nabla_b+M \rangle = e^{2\pi i \tfrac{M}{B}}|\nabla_b\rangle,

see phase gradient state properties for details. We may perform this addition with a semi-in-place adder, which performs the computation |x\rangle |y\rangle \mapsto |x\rangle |(x+y)\!\!\mod B\rangle.

Let us trace the effect of our circuit on the overall quantum state. Suppose the qubit to be phase-rotated was originally in the state |\psi\rangle= \alpha|0\rangle+\beta|1\rangle. From this, we created the entangled state \alpha |0\rangle^{b+1}+\beta|1\rangle\otimes|B\phi\rangle by control-loading the angle. Applying the adder to this state, we then obtained

\alpha |0\rangle^{b+1} \otimes |\nabla_b\rangle + \beta |1\rangle\otimes |B\phi\rangle\otimes |\nabla_b+B\phi\rangle = (\alpha |0\rangle^{b+1}+ e^{2\pi i \frac{B\phi}{B}}\beta |1\rangle\otimes |B\phi\rangle) \otimes |\nabla_b\rangle.

Causing a relative phase between states by control-applying a circuit that otherwise leads to a global phase is known as phase kickback. See, e.g., our demo for how to build a quantum lock with phase kickback.

For our example, we built the following circuit:

|ψ>    : ─╭●────────────┤
|0>    : ─│──╭SemiAdder─┤
|0>    : ─├X─├SemiAdder─┤
|0>    : ─│──├SemiAdder─┤
|0>    : ─├X─├SemiAdder─┤
|0>    : ─│──├SemiAdder─┤
|0>    : ─╰X─├SemiAdder─┤
      ╭: ────├SemiAdder─┤
      │: ────├SemiAdder─┤
|∇_6> ┤: ────├SemiAdder─┤
      │: ────├SemiAdder─┤
      │: ────├SemiAdder─┤
      ╰: ────╰SemiAdder─┤

Cleaning up: Uncomputation and global phase

We are almost done at this point; we successfully applied a phase to the |1\rangle component of the target qubit state. However, we also entangled the target qubit with the encoding register, which is something we still need to rectify. For this, we apply the inverse of the controlled angle encoding, which is just the encoding itself due to X^2=1. This produces the product state |\psi'\rangle \otimes |0\rangle^{b}\otimes |\nabla_b \rangle between the target qubit, the encoding register, and the phase gradient register. Here we denoted

|\psi'\rangle = \alpha |0\rangle + \beta e^{2\pi i \phi}|1\rangle.

The circuit for our example now reads

|ψ>    : ─╭●────────────╭●──┤   |ψ'>
|0>    : ─│──╭SemiAdder─│───┤   |0>
|0>    : ─├X─├SemiAdder─├X──┤   |0>
|0>    : ─│──├SemiAdder─│───┤   |0>
|0>    : ─├X─├SemiAdder─├X──┤   |0>
|0>    : ─│──├SemiAdder─│───┤   |0>
|0>    : ─╰X─├SemiAdder─╰X──┤   |0>
      ╭: ────├SemiAdder─────┤ ╮
      │: ────├SemiAdder─────┤ │
|∇_6> ┤: ────├SemiAdder─────┤ ├ |∇_6>
      │: ────├SemiAdder─────┤ │
      │: ────├SemiAdder─────┤ │
      ╰: ────╰SemiAdder─────┤ ╯

In a last step, we adjust the overall phase of |\psi'\rangle via

\begin{align} |\psi''\rangle &= e^{-\pi i \phi} |\psi'\rangle \\ &= e^{-\pi i \phi} \alpha |0\rangle + e^{\pi i \phi}\beta |1\rangle \\ &= R_Z(\phi\pi) |\psi\rangle \\ &\approx R_Z(\theta')|\psi\rangle. \end{align}

Including the split-off phase (-1), we thus approximately applied the desired R_Z rotation to the input state |\psi\rangle, leaving the encoding and phase gradient registers behind in their original state.

The fact that the resource phase gradient state is left untouched after the rotation has been performed makes it a catalytic state, as it facilitates a process without being consumed.

The complete circuit for our example is

|ψ>    : ─╭●────────────╭●─(-exp(-πϕi))─┤  ≈R_Z(θ)|ψ>
|0>    : ─│──╭SemiAdder─│───────────────┤   |0>
|0>    : ─├X─├SemiAdder─├X──────────────┤   |0>
|0>    : ─│──├SemiAdder─│───────────────┤   |0>
|0>    : ─├X─├SemiAdder─├X──────────────┤   |0>
|0>    : ─│──├SemiAdder─│───────────────┤   |0>
|0>    : ─╰X─├SemiAdder─╰X──────────────┤   |0>
      ╭: ────├SemiAdder─────────────────┤ ╮
      │: ────├SemiAdder─────────────────┤ │
|∇_6> ┤: ────├SemiAdder─────────────────┤ ├ |∇_6>
      │: ────├SemiAdder─────────────────┤ │
      │: ────├SemiAdder─────────────────┤ │
      ╰: ────╰SemiAdder─────────────────┤ ╯

Complexity

As we derived above, implementing an R_Z(\theta) rotation to precision \varepsilon in the angle requires the following gates and auxiliary qubits:

Operations

The angle encoding fan-out can be implemented, for example, with |\phi| CNOT gates, where |\phi| denotes the Hamming weight, or bit count, of \phi. The cost of SemiAdder depends on the availability of additional auxiliary wires. If b-1 zeroed wires are available, we may use the adder by Gidney [2] that uses 4b-4 T gates, 10b-11 CNOT gates, b-1 conditionally applied CZ gates, and 4b-4 single-qubit Cliffords. Overall, we have up to 4b-4 T gates, 13b-12 CNOT and CZ gates, and up to 4b-3 single-qubit Cliffords, where we used that |\phi|\leq b. To relate this to the input data, recall that b=\lceil \log_2(\pi/\varepsilon)\rceil.

Space

We require b auxiliary qubits in the state |0\rangle for the encoding register and b-1 additional auxiliary zeroed qubits for the SemiAdder, as well as a register of at least b qubits in a phase gradient state.

Alternative to global phase

As a last remark, we provide an alternative formulation of the circuit above, using a modification of the adder instead of a global phase. While this may seem like a strange trade-off to make, it will come in handy for variants that implement controlled rotations or multiplexed rotations.

Instead of applying the phase 2\pi i\phi to the |1\rangle state and then shifting the global phase by -\pi i\phi, we immediately apply the correct phases to the two states by loading \phi/2 and making the adder a subtraction circuit, controlled on the state |0\rangle of the rotation target.

This can be achieved with a simple fan-out operation onto the phase gradient state [3]:

|ψ>    : ───────╭○────────────╭○────────┤  ≈R_Z(θ)|ψ>
|0>    : ─╭load─│──╭SemiAdder─│──╭load†─┤   |0>
|0>    : ─├load─│──├SemiAdder─│──├load†─┤   |0>
|0>    : ─╰load─├──├SemiAdder─├──╰load†─┤   |0>
      ╭: ───────├X─├SemiAdder─├X────────┤ ╮
|∇_b> ┤: ───────├X─├SemiAdder─├X────────┤ ├ |∇_b>
      ╰: ───────╰X─╰SemiAdder─╰X────────┤ ╯

Note that this fan-out does not come at any non-Clifford cost if we use a standard implementation via CNOT gates. While this is also true for the circuit above using a global phase, this crucially will not change for the adder-subtractor variant shown here once we attach more control structure to the circuit.

PennyLane

PennyLane is a cross-platform Python library for quantum computing, quantum machine learning, and quantum chemistry. Built by researchers, for research. Created with ❤️ by Xanadu.

Research

  • Research
  • Performance
  • Hardware & Simulators
  • Demos
  • Quantum Compilation
  • Quantum Datasets

Education

  • Teach
  • Learn
  • Codebook
  • Coding Challenges
  • Videos
  • Glossary

Software

  • Install PennyLane
  • Features
  • Documentation
  • Catalyst Compilation Docs
  • Development Guide
  • API
  • GitHub
Stay updated with our newsletter

© 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