3
$\begingroup$

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?

$\endgroup$

1 Answer 1

4
$\begingroup$

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')

enter image description here

$\endgroup$
2
  • $\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$ Mar 14 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 method Gate.inverse. $\endgroup$ Mar 14 at 22:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.