In [1]:
import numpy as np

from qiskit import QuantumCircuit, ClassicalRegister, QuantumRegister
from qiskit import execute
from qiskit import BasicAer
from qiskit.tools.visualization import plot_histogram
In [2]:
def qdft(qc): 
    qc.h(q[0])

    qc.cu1(np.pi/2, q[1], q[0])
    qc.h(q[1])

    qc.cu1(np.pi/4, q[2], q[0])
    qc.cu1(np.pi/2, q[2], q[1])
    qc.h(q[2]);

    qc.cu1(np.pi/8, q[3], q[0])
    qc.cu1(np.pi/4, q[3], q[1])
    qc.cu1(np.pi/2, q[3], q[2])
    qc.h(q[3]);

    qc.swap(q[0], q[3])
    qc.swap(q[1], q[2])

    qc.measure(q, c)
In [3]:
q = QuantumRegister(4)
c = ClassicalRegister(4)
qc = QuantumCircuit(q, c)

qdft(qc)
qc.draw(output='mpl')
Out[3]:
In [4]:
backend = BasicAer.get_backend('qasm_simulator')
shots_sim = 100

job_sim = execute(qc, backend)
stats_sim = job_sim.result().get_counts()

plot_histogram(stats_sim)
Out[4]:
In [5]:
q = QuantumRegister(4)
c = ClassicalRegister(4)
qc = QuantumCircuit(q, c)

qc.h(q)
qdft(qc)
qc.draw(output='mpl')
Out[5]:
In [6]:
backend = BasicAer.get_backend('qasm_simulator')
shots_sim = 100

job_sim = execute(qc, backend)
stats_sim = job_sim.result().get_counts()

plot_histogram(stats_sim)
Out[6]: