from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister
from qiskit import Aer, execute, BasicAer
from qiskit.visualization import plot_bloch_multivector, plot_histogram

import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline

qc = QuantumCircuit(3)

# apply Hadamard
for q in range(3):
    qc.h(q)
qc.draw(output='mpl')

backend = Aer.get_backend('statevector_simulator')
res  = execute(qc, backend=backend).result()
final_state = res.get_statevector()

print (final_state)
print (1./np.sqrt(8))



𝑋=[[0, 1] ,[1, 0]]
qc = QuantumCircuit(2)
qc.h(0)
qc.x(1)
qc.draw('mpl')

backend = Aer.get_backend('unitary_simulator')
res  = execute(qc, backend=backend).result()
unitary = res.get_unitary()

print (unitary.round(2).real)


qc = QuantumCircuit(3)
qc.z(0)
qc.h(1)
qc.x(2)
qc.draw('mpl')

backend = Aer.get_backend('unitary_simulator')
res  = execute(qc, backend=backend).result()
unitary = res.get_unitary()

print (unitary.round(2).real)

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

backend = Aer.get_backend('statevector_simulator')
final_state = execute(qc,backend).result().get_statevector()
print (final_state.round(2))

results = execute(qc,backend).result().get_counts()
plot_histogram(results)

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

backend_sv =Aer.get_backend('statevector_simulator')
final_state = execute(qc,backend_sv).result().get_statevector()
print (final_state.round(2))

plot_bloch_multivector(final_state)

import qiskit
qiskit.__version__

qc = QuantumCircuit(2)
qc.h(0)
qc.h(1)
qc.z(1)
qc.draw()

final_state = execute(qc,backend_sv).result().get_statevector()


plot_bloch_multivector(final_state)

qc.cx(0,1)
qc.draw()

final_state = execute(qc,backend_sv).result().get_statevector()
print (final_state)
plot_bloch_multivector(final_state)


qc = QuantumCircuit(2)
qc.h(0)
qc.h(1)
qc.cx(0,1)
qc.h(0)
qc.h(1)
display(qc.draw())  
backend_uni = Aer.get_backend('unitary_simulator')
unitary = execute(qc,backend_uni).result().get_unitary()
print (unitary.round(2).real)
#array_to_latex(unitary, pretext="\\text{Circuit = }\n")

qc.cx(1,0)
display(qc.draw())  
backend_uni = Aer.get_backend('unitary_simulator')
unitary = execute(qc,backend_uni).result().get_unitary()
print (unitary.round(2).real)

