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):
A Hadamard gate on qubit j.
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 applyqft_circuitand then callcircuit.dagger()on the relevant gates.- Parameters:
- 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])