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.h(0)
qc.draw(output='mpl')

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

H = np.array([[ 0.707+0.j,  0.707-0.j],[ 0.707+0.j, -0.707+0.j]])
I = np.eye(2)
np.kron(I,H)

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

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

H = np.array([[ 0.707+0.j,  0.707-0.j],[ 0.707+0.j, -0.707+0.j]])
I = np.eye(2)
np.kron(H,I)

q = QuantumRegister(2)
qc = QuantumCircuit(q)
qc.h(0)
qc.h(1)
qc.draw(output='mpl')

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

H = np.array([[ 0.707+0.j,  0.707-0.j],[ 0.707+0.j, -0.707+0.j]])
np.kron(H,H)

qc = QuantumCircuit(2)
qc.barrier()
qc0 = qc.copy()
qc.h(0)
qc.x(1)
qc.barrier()
qc1 = qc.copy()
qc.y(0)
qc.h(1)
qc.barrier()
qc2 = qc.copy()
qc.draw(output='mpl')

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

H = np.array([[ 0.707+0.j,  0.707-0.j],[ 0.707+0.j, -0.707+0.j]])
X = sigmax()
Y = sigmay()
XKH = np.kron(X,H)
HKY = np.kron(H,Y)
np.dot(HKY,XKH)

backend = Aer.get_backend('statevector_simulator')
qc_vec = []
for qc in [qc0,qc1,qc2]:
    out = execute(qc,backend).result().get_statevector()
    qc_vec.append(out)
    print(out)

qca = QuantumCircuit(1)

qca.barrier()
qca0 = qca.copy()
qca.h(0)

qca.barrier()
qca1 = qca.copy()
qca.y(0)

qca.barrier()
qca2 = qca.copy()
qca.draw(output='mpl')

backend = Aer.get_backend('statevector_simulator')
qca_vec = []
for qc in [qca0,qca1,qca2]:
    out = execute(qc,backend).result().get_statevector()
    qca_vec.append(out)
    print(out)

qcb = QuantumCircuit(1)

qcb.barrier()
qcb0 = qcb.copy()
qcb.x(0)

qcb.barrier()
qcb1 = qcb.copy()
qcb.h(0)

qcb.barrier()
qcb2 = qcb.copy()
qcb.draw(output='mpl')

backend = Aer.get_backend('statevector_simulator')
qcb_vec = []
for qc in [qcb0,qcb1,qcb2]:
    out = execute(qc,backend).result().get_statevector()
    qcb_vec.append(out)
    print(out)

for qcv,qcav,qcbv in zip(qc_vec,qca_vec,qcb_vec):
    print(qcv,"|", np.kron(qcbv,qcav))