from qiskit import *
from math import pi
import numpy as np
from qiskit_aer import Aer
from qiskit.visualization import *
import matplotlib.pyplot as plt
from qutip import *


qc = QuantumCircuit(2)
qc.h(1)
qc.barrier()
qc.cu(np.pi/2, 0, 1, 0, 0 ,1)
qc.barrier()
qc.h(0)
qc.barrier()
qc.swap(0,1)
qc.draw()

backend = Aer.get_backend('statevector_simulator')
out = (backend.run(transpile(qc,backend))).result().get_statevector()
print(out)

def qft3():
    n = 3
    q = QuantumRegister(n)
    c = ClassicalRegister(n)
    qc = QuantumCircuit(q,c)

    qc.h(q[2])
    qc.barrier()
    qc.cu(np.pi/2, 0, 0, 0, q[1], q[2])
    qc.barrier()
    qc.h(q[1])
    qc.barrier()
    qc.cu(np.pi/4, 0, 0, 0, q[0], q[2])
    qc.barrier()
    qc.cu(np.pi/2, 0, 0, 0, q[0], q[1])
    qc.barrier()
    qc.h(q[0])
    qc.barrier()
    qc.swap(q[0], q[2])
    return q,c,qc

q,c,qc = qft3()
qc.barrier()
qc.draw()