I'm pretty new in Qiskit and quantum circuits. I'm using Qiskit to implement a quantum circuit and I followed this tutorial to implement a QFT. The way this QFT was built, it applies QFT in the first $n$ qubits, but what I need is to apply the QFT in the last $n$ qubits. Is there any way to do this?
1 Answer
$\begingroup$
$\endgroup$
2
In general, to build a Quantum Fourier Transform on an arbitrary number of qubits, you can use the QFT class already implemented in Qiskit. In particular, to apply it to the last two qubits of your circuit, you can convert the QFT object to a gate and then append it passing the qubits indices.
from qiskit import QuantumCircuit
from qiskit.circuit.library import QFT
qc = QuantumCircuit(3)
qft = QFT(num_qubits=2).to_gate()
qc.append(qft, qargs=[1, 2])
qc.decompose(reps=2).draw('mpl')
-
$\begingroup$ Thanks for this pretty straightforward answer! Could you please edit your question and add some comments about how to do the same to an inverse QFT? $\endgroup$ Commented Mar 14, 2023 at 20:03
-
1$\begingroup$ To get the inverse QFT, you just need
qft_inv = qft.inverse()
; more in general, given an arbitrary quantum gate defined in Qiskit, you can compute its inverse operation by calling the methodGate.inverse
. $\endgroup$ Commented Mar 14, 2023 at 22:26