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

qc = QuantumCircuit(2)
qc.barrier()
qc.h(0)
qc.cx(0, 1)
qc.barrier()
qc.draw('mpl')

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

I = np.eye(2,2)
H = 1/np.sqrt(2)*np.array([[1,1],[1,-1]])
CNOT = np.array([[1,0,0,0],[0,0,0,1],[0,0,1,0],[0,1,0,0]])
IKH = np.kron(I,H)
U = np.dot(CNOT,IKH)
print(U)

backend = Aer.get_backend('unitary_simulator')
job = execute(qc, backend)
result = job.result()
print(result.get_unitary(qc, decimals=3))

ket_00 = np.array([1,0,0,0])
np.dot(U,ket_00)

qc = QuantumCircuit(2)
qc.x(1)
qc.barrier()
qc.h(0)
qc.cx(0, 1)
qc.barrier()
qc.draw('mpl')

# Let's see the result
backend = Aer.get_backend('statevector_simulator')
out = execute(qc,backend).result().get_statevector()
print(out)

qc = QuantumCircuit(2)
qc.x(0)
qc.barrier()
qc.h(0)
qc.cx(0, 1)
qc.barrier()
qc.draw('mpl')

# Let's see the result
backend = Aer.get_backend('statevector_simulator')
out = execute(qc,backend).result().get_statevector()
print(out)

qc = QuantumCircuit(2)
qc.x(0)
qc.x(1)
qc.barrier()
qc.h(0)
qc.cx(0, 1)
qc.barrier()
qc.draw('mpl')

# Let's see the result
backend = Aer.get_backend('statevector_simulator')
out = execute(qc,backend).result().get_statevector()
print(out)









