uniqc.algorithmics.circuits.qft module#

Quantum Fourier Transform (QFT) circuit.

uniqc.algorithmics.circuits.qft.qft_circuit(circuit, qubits=None, swaps=True)[source]#

Apply the Quantum Fourier Transform (QFT) to the given qubits.

The QFT maps the computational basis state \(|j\rangle\) to:

\[\frac{1}{\sqrt{N}} \sum_{k=0}^{N-1} e^{2\pi i\, jk/N} |k\rangle\]

where \(N = 2^n\) and n is the number of qubits.

The circuit applies, for each qubit j (from most-significant to least-significant):

  1. A Hadamard gate on qubit j.

  2. Controlled phase rotations \(R_k\) from every later qubit k > j with angle \(\pi / 2^{k-j}\).

If swaps is True (the default), a layer of SWAP gates is appended to reverse the qubit order so that the output follows the standard big-endian convention.

To obtain the inverse QFT, use circuit.dagger() on a copy of the QFT sub-circuit, or apply qft_circuit and then call circuit.dagger() on the relevant gates.

Parameters:
  • circuit (Circuit) – Quantum circuit to operate on (mutated in-place).

  • qubits (List[int] | None) – Qubit indices to apply QFT on. None means all qubits of circuit (list(range(circuit.qubit_num))).

  • swaps (bool) – Whether to append SWAP gates to reverse qubit order. Defaults to True.

Raises:

ValueError – Fewer than 1 qubit is specified.

Return type:

None

Example

>>> from uniqc.circuit_builder import Circuit
>>> from uniqc.algorithmics.circuits import qft_circuit
>>> c = Circuit(3)
>>> qft_circuit(c, qubits=[0, 1, 2])