#supporting package
import matplotlib.pyplot as plt
%matplotlib inline
import numpy as np
from math import pi, sqrt
from qiskit import QuantumCircuit, ClassicalRegister, QuantumRegister, execute, Aer

qc = QuantumCircuit(2)
qc.h(0)
qc.cz(0, 1) #squareroot control Z-gate
qc.h(1)
qc.swap(0,1) # to make completeness in orthonormal basis
qc.draw('mpl')

s = np.array([[1,0,0,0],[0,0,1,0],[0,1,0,0],[0,0,0,1]])
s


h = np.array([[0.707,0.707,0,0],[0.707,-0.707,0,0],[0,0,0.707,0.707],[0,0,0.707,-0.707]])
h

z=np.array([[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,0+1.j]])
z

QFT2 = s*h*z*h #need to do

#QFT2

qc = QuantumCircuit(3)
qc.h(2)
display( qc.draw('mpl') )

# UROT_2 gate to x1 depending on x2
qc.cu1(pi/2, 1, 2) # CROT from qubit 1 to qubit 2 hence the angle: pi/2^{2-1}
display ( qc.draw('mpl') )

qc.cu1(pi/4, 0, 2) # CROT from qubit 2 to qubit 0 hence the angle: pi/2^{2-0}
display( qc.draw('mpl') )

# Repeat the process for 1 and 0 
qc.h(1)  # Hadamard on 1
qc.cu1(pi/2, 0, 1) # CROT from qubit 0 to qubit 1 hence the angle: pi/2^{1-0}
qc.h(0)  # Hadamard on 0
display( qc.draw('mpl') )

# Now swap the qubit 0 and 2 to complete QFT. [NOT CLEAR TO ME]
qc.swap(0,2)
display ( qc.draw('mpl') )

qc = QuantumCircuit(2)
qc.h(1)
display( qc.draw('mpl') )

# UROT_1 gate to x0 depending on x1
qc.cu1(pi/2, 0, 1) # CROT from qubit 0 to qubit 1 hence the angle: pi/2^{1-0}
display ( qc.draw('mpl') )

qc.h(0)  # Hadamard on 1
# Now swap the qubit 0 and 2 to complete QFT. [To make orthonormal bais set completeness]
qc.swap(0,1)
display ( qc.draw('mpl') )

