# QFT¶

class QFT(num_qubits=None, approximation_degree=0, do_swaps=True, inverse=False, insert_barriers=False, name='qft')[source]

Quantum Fourier Transform Circuit.

The Quantum Fourier Transform (QFT) on $$n$$ qubits is the operation

$|j\rangle \mapsto \frac{1}{2^{n/2}} \sum_{k=0}^{2^n - 1} e^{2\pi ijk / 2^n} |k\rangle$

The circuit that implements this transformation can be implemented using Hadamard gates on each qubit, a series of controlled-U1 (or Z, depending on the phase) gates and a layer of Swap gates. The layer of Swap gates can in principle be dropped if the QFT appears at the end of the circuit, since then the re-ordering can be done classically. They can be turned off using the do_swaps attribute.

For 4 qubits, the circuit that implements this transformation is:

The inverse QFT can be obtained by calling the inverse method on this class. The respective circuit diagram is:

One method to reduce circuit depth is to implement the QFT approximately by ignoring controlled-phase rotations where the angle is beneath a threshold. This is discussed in more detail in https://arxiv.org/abs/quant-ph/9601018 or https://arxiv.org/abs/quant-ph/0403071.

Here, this can be adjusted using the approximation_degree attribute: the smallest approximation_degree rotation angles are dropped from the QFT. For instance, a QFT on 5 qubits with approximation degree 2 yields (the barriers are dropped in this example):

Construct a new QFT circuit.

Parameters
• num_qubits (Optional[int]) – The number of qubits on which the QFT acts.

• approximation_degree (int) – The degree of approximation (0 for no approximation).

• do_swaps (bool) – Whether to include the final swaps in the QFT.

• inverse (bool) – If True, the inverse Fourier transform is constructed.

• insert_barriers (bool) – If True, barriers are inserted as visualization improvement.

• name (str) – The name of the circuit.

Attributes

 QFT.ancillas Returns a list of ancilla bits in the order that the registers were added. QFT.approximation_degree The approximation degree of the QFT. QFT.calibrations Return calibration dictionary. QFT.clbits Returns a list of classical bits in the order that the registers were added. QFT.data Return the circuit data (instructions and context). QFT.do_swaps Whether the final swaps of the QFT are applied or not. QFT.extension_lib QFT.global_phase Return the global phase of the circuit in radians. QFT.header QFT.insert_barriers Whether barriers are inserted for better visualization or not. QFT.instances QFT.num_ancillas Return the number of ancilla qubits. QFT.num_clbits Return number of classical bits. QFT.num_parameters Convenience function to get the number of parameter objects in the circuit. QFT.num_qubits The number of qubits in the QFT circuit. QFT.parameters Convenience function to get the parameters defined in the parameter table. QFT.prefix QFT.qregs A list of the quantum registers associated with the circuit. QFT.qubits Returns a list of quantum bits in the order that the registers were added.

Methods

 Return indexed operation. Return number of operations in circuit. QFT.add_calibration(gate, qubits, schedule) Register a low-level, custom pulse definition for the given gate. QFT.add_register(*regs) Add registers. QFT.append(instruction[, qargs, cargs]) Append one or more instructions to the end of the circuit, modifying the circuit in place. QFT.assign_parameters(param_dict[, inplace]) Assign parameters to new parameters or values. QFT.barrier(*qargs) Apply Barrier. QFT.bind_parameters(value_dict) Assign numeric parameters to values yielding a new circuit. QFT.cast(value, _type) Best effort to cast value to type. Converts several classical bit representations (such as indexes, range, etc.) into a list of classical bits. QFT.ccx(control_qubit1, control_qubit2, …) Apply CCXGate. QFT.ch(control_qubit, target_qubit[, label, …]) Apply CHGate. Return the current number of instances of this class, useful for auto naming. Return the prefix to use for auto naming. QFT.cnot(control_qubit, target_qubit[, …]) Apply CXGate. Append rhs to self if self contains compatible registers. QFT.compose(other[, qubits, clbits, front, …]) Compose circuit with other circuit or instruction, optionally permuting wires. QFT.control([num_ctrl_qubits, label, ctrl_state]) Control this circuit on num_ctrl_qubits qubits. QFT.copy([name]) Copy the circuit. Count each operation kind in the circuit. QFT.cp(theta, control_qubit, target_qubit[, …]) Apply CPhaseGate. QFT.crx(theta, control_qubit, target_qubit) Apply CRXGate. QFT.cry(theta, control_qubit, target_qubit) Apply CRYGate. QFT.crz(theta, control_qubit, target_qubit) Apply CRZGate. QFT.cswap(control_qubit, target_qubit1, …) Apply CSwapGate. QFT.csx(control_qubit, target_qubit[, …]) Apply CSXGate. QFT.cu(theta, phi, lam, gamma, …[, label, …]) Apply CUGate. QFT.cu1(theta, control_qubit, target_qubit) Apply CU1Gate. QFT.cu3(theta, phi, lam, control_qubit, …) Apply CU3Gate. QFT.cx(control_qubit, target_qubit[, label, …]) Apply CXGate. QFT.cy(control_qubit, target_qubit[, label, …]) Apply CYGate. QFT.cz(control_qubit, target_qubit[, label, …]) Apply CZGate. QFT.dcx(qubit1, qubit2) Apply DCXGate. Call a decomposition pass on this circuit, to decompose one level (shallow decompose). QFT.delay(duration[, qarg, unit]) Apply Delay. Return circuit depth (i.e., length of critical path). QFT.diag_gate(diag, qubit) Deprecated version of QuantumCircuit.diagonal. QFT.diagonal(diag, qubit) Attach a diagonal gate to a circuit. QFT.draw([output, scale, filename, style, …]) Draw the quantum circuit. QFT.extend(rhs) Append QuantumCircuit to the right hand side if it contains compatible registers. QFT.fredkin(control_qubit, target_qubit1, …) Apply CSwapGate. Take in a QASM file and generate a QuantumCircuit object. QFT.from_qasm_str(qasm_str) Take in a QASM string and generate a QuantumCircuit object. QFT.h(qubit) Apply HGate. QFT.hamiltonian(operator, time, qubits[, label]) Apply hamiltonian evolution to to qubits. QFT.has_register(register) Test if this circuit has the register r. QFT.i(qubit) Apply IGate. QFT.id(qubit) Apply IGate. QFT.initialize(params, qubits) Apply initialize to circuit. Invert this circuit. Whether the inverse Fourier transform is implemented. QFT.iso(isometry, q_input, q_ancillas_for_output) Attach an arbitrary isometry from m to n qubits to a circuit. QFT.isometry(isometry, q_input, …[, …]) Attach an arbitrary isometry from m to n qubits to a circuit. QFT.iswap(qubit1, qubit2) Apply iSwapGate. QFT.mcmt(gate, control_qubits, target_qubits) Apply a multi-control, multi-target using a generic gate. QFT.mcp(lam, control_qubits, target_qubit) Apply MCPhaseGate. QFT.mcrx(theta, q_controls, q_target[, …]) Apply Multiple-Controlled X rotation gate QFT.mcry(theta, q_controls, q_target, q_ancillae) Apply Multiple-Controlled Y rotation gate QFT.mcrz(lam, q_controls, q_target[, …]) Apply Multiple-Controlled Z rotation gate QFT.mct(control_qubits, target_qubit[, …]) Apply MCXGate. QFT.mcu1(lam, control_qubits, target_qubit) Apply MCU1Gate. QFT.mcx(control_qubits, target_qubit[, …]) Apply MCXGate. QFT.measure(qubit, cbit) Measure quantum bit into classical bit (tuples). QFT.measure_active([inplace]) Adds measurement to all non-idle qubits. QFT.measure_all([inplace]) Adds measurement to all qubits. DEPRECATED: use circuit.reverse_ops(). QFT.ms(theta, qubits) Apply MSGate. QFT.num_connected_components([unitary_only]) How many non-entangled subcircuits can the circuit be factored to. Return number of non-local gates (i.e. Computes the number of tensor factors in the unitary (quantum) part of the circuit only. Computes the number of tensor factors in the unitary (quantum) part of the circuit only. QFT.p(theta, qubit) Apply PhaseGate. QFT.power(power[, matrix_power]) Raise this circuit to the power of power. QFT.qasm([formatted, filename]) Return OpenQASM string. Converts several qubit representations (such as indexes, range, etc.) into a list of qubits. QFT.qubit_duration(*qubits) Return the duration between the start and stop time of the first and last instructions, excluding delays, over the supplied qubits. QFT.qubit_start_time(*qubits) Return the start time of the first instruction, excluding delays, over the supplied qubits. QFT.qubit_stop_time(*qubits) Return the stop time of the last instruction, excluding delays, over the supplied qubits. QFT.r(theta, phi, qubit) Apply RGate. QFT.rcccx(control_qubit1, control_qubit2, …) Apply RC3XGate. QFT.rccx(control_qubit1, control_qubit2, …) Apply RCCXGate. QFT.remove_final_measurements([inplace]) Removes final measurement on all qubits if they are present. QFT.repeat(reps) Repeat this circuit reps times. QFT.reset(qubit) Reset q. Return a circuit with the opposite order of wires. Reverse the circuit by reversing the order of instructions. QFT.rx(theta, qubit[, label]) Apply RXGate. QFT.rxx(theta, qubit1, qubit2) Apply RXXGate. QFT.ry(theta, qubit[, label]) Apply RYGate. QFT.ryy(theta, qubit1, qubit2) Apply RYYGate. QFT.rz(phi, qubit) Apply RZGate. QFT.rzx(theta, qubit1, qubit2) Apply RZXGate. QFT.rzz(theta, qubit1, qubit2) Apply RZZGate. QFT.s(qubit) Apply SGate. QFT.sdg(qubit) Apply SdgGate. Returns total number of gate operations in circuit. QFT.snapshot(label[, snapshot_type, qubits, …]) Take a statevector snapshot of the internal simulator representation. QFT.snapshot_density_matrix(label[, qubits]) Take a density matrix snapshot of simulator state. QFT.snapshot_expectation_value(label, op, qubits) Take a snapshot of expectation value of an Operator. QFT.snapshot_probabilities(label, qubits[, …]) Take a probability snapshot of the simulator state. Take a stabilizer snapshot of the simulator state. Take a statevector snapshot of the simulator state. QFT.squ(unitary_matrix, qubit[, mode, …]) Decompose an arbitrary 2*2 unitary into three rotation gates. QFT.swap(qubit1, qubit2) Apply SwapGate. QFT.sx(qubit) Apply SXGate. QFT.sxdg(qubit) Apply SXdgGate. QFT.t(qubit) Apply TGate. QFT.tdg(qubit) Apply TdgGate. QFT.to_gate([parameter_map, label]) Create a Gate out of this circuit. QFT.to_instruction([parameter_map]) Create an Instruction out of this circuit. QFT.toffoli(control_qubit1, control_qubit2, …) Apply CCXGate. QFT.u(theta, phi, lam, qubit) Apply UGate. QFT.u1(theta, qubit) Apply U1Gate. QFT.u2(phi, lam, qubit) Apply U2Gate. QFT.u3(theta, phi, lam, qubit) Apply U3Gate. QFT.uc(gate_list, q_controls, q_target[, …]) Attach a uniformly controlled gates (also called multiplexed gates) to a circuit. QFT.ucrx(angle_list, q_controls, q_target) Attach a uniformly controlled (also called multiplexed) Rx rotation gate to a circuit. QFT.ucry(angle_list, q_controls, q_target) Attach a uniformly controlled (also called multiplexed) Ry rotation gate to a circuit. QFT.ucrz(angle_list, q_controls, q_target) Attach a uniformly controlled (also called multiplexed gates) Rz rotation gate to a circuit. QFT.unitary(obj, qubits[, label]) Apply unitary gate to q. Return number of qubits plus clbits in circuit. QFT.x(qubit[, label]) Apply XGate. QFT.y(qubit) Apply YGate. QFT.z(qubit) Apply ZGate. Return indexed operation. Return number of operations in circuit.