# 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()

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