Algorithms

trueq.algorithms.subroutines.qft

Returns a circuit which implements the quantum Fourier transform on \(n\)-qubits, \(\mathcal{F}_{2^n}\).

Subroutines

trueq.algorithms.subroutines.qft(labels, truncate_at=None, swap=True)

Returns a circuit which implements the quantum Fourier transform on \(n\)-qubits, \(\mathcal{F}_{2^n}\).

By default, the returned circuit contains no approximations. However, by calling this method with an integer value for truncate_at, the returned circuit will be approximated by truncating certain controlled-\(Z\) rotations. Given an integer \(b\), the approximated Fourier transform will not contain controlled-\(Z\) rotations with angles smaller than \(2 \pi / 2^{b+1}\), or in other words, all cascades of controlled rotations will have depth no longer than \(b\).

Setting swap to False omits the final subcircuit which reverses the order of the qubits. This step requires \(O(n)\) swap gates, and can be safely omitted and replaced by classical post-processing if the QFT is immediately followed by measurement.

import numpy as np
import trueq as tq

circuit = tq.algorithms.qft(range(4), truncate_at=2)
circuit.measure_all()
circuit.draw()
0 1 2 3 Key: Labels: (0,) Name: Gate.h Aliases: Gate.h Gate.cliff12 Generators: Z: 127.28 X: 127.28 0.71 0.71 0.71 -0.71 H Labels: (0, 1) Name: Gate Locally Equivalent: Non-Clifford Generators: IZ: 45.00 ZI: 45.00 ZZ: -45.00 1.00 1.00 1.00 1.00j Labels: (0, 2) Name: Gate Locally Equivalent: Non-Clifford Generators: IZ: 22.50 ZI: 22.50 ZZ: -22.50 1.00 1.00 1.00 0.71 0.71j Labels: (1,) Name: Gate.h Aliases: Gate.h Gate.cliff12 Generators: Z: 127.28 X: 127.28 0.71 0.71 0.71 -0.71 H Labels: (1, 2) Name: Gate Locally Equivalent: Non-Clifford Generators: IZ: 45.00 ZI: 45.00 ZZ: -45.00 1.00 1.00 1.00 1.00j Labels: (1, 3) Name: Gate Locally Equivalent: Non-Clifford Generators: IZ: 22.50 ZI: 22.50 ZZ: -22.50 1.00 1.00 1.00 0.71 0.71j Labels: (2,) Name: Gate.h Aliases: Gate.h Gate.cliff12 Generators: Z: 127.28 X: 127.28 0.71 0.71 0.71 -0.71 H Labels: (2, 3) Name: Gate Locally Equivalent: Non-Clifford Generators: IZ: 45.00 ZI: 45.00 ZZ: -45.00 1.00 1.00 1.00 1.00j Labels: (3,) Name: Gate.h Aliases: Gate.h Gate.cliff12 Generators: Z: 127.28 X: 127.28 0.71 0.71 0.71 -0.71 H Labels: (0, 3) Name: Gate.swap Aliases: Gate.swap Locally Equivalent: SWAP Generators: YY: 90.00 XX: 90.00 ZZ: 90.00 1.00 1.00 1.00 1.00 SW SW Labels: (1, 2) Name: Gate.swap Aliases: Gate.swap Locally Equivalent: SWAP Generators: YY: 90.00 XX: 90.00 ZZ: 90.00 1.00 1.00 1.00 1.00 SW SW 1 Labels: (0,) Name: Meas M Labels: (1,) Name: Meas M Labels: (2,) Name: Meas M Labels: (3,) Name: Meas M
Parameters
  • labels (Iterable) – The qubit labels on which the Fourier transform acts.

  • truncate_at (NoneType | int) – An integer \(b\), which specifies the removal of all controlled-\(Z\) gates with an angle smaller than \(2 \pi / 2^b\), or None by default to remove no gates in the generated circuit.

  • swap (bool) – Whether to include the subcircuit which reverses the order of the qubits at the end of the QFT circuit. Default is True.

Return type

Circuit