from qiskit import *
from math import pi
import numpy as np
from qiskit.visualization import plot_bloch_multivector,plot_histogram
from qiskit_textbook.tools import array_to_latex

backend_s = Aer.get_backend('statevector_simulator')
backend_u = Aer.get_backend('unitary_simulator')

qc = QuantumCircuit(2)
qc.x(0) # NOT gate to convert default 0 state to 1
qc.draw('mpl')

result_statevector = execute(qc,backend_s).result().get_statevector()
array_to_latex(result_statevector,pretext = "\\text{Result = }")
plot_bloch_multivector(result_statevector)

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

result_statevector = execute(qc,backend_s).result().get_statevector()
array_to_latex(result_statevector,pretext = "\\text{Result = }")
plot_bloch_multivector(result_statevector)

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

result_statevector = execute(qc,backend_s).result().get_statevector()
array_to_latex(result_statevector,pretext = "\\text{Result = }")
plot_bloch_multivector(result_statevector)

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

result_statevector = execute(qc,backend_s).result().get_statevector()
array_to_latex(result_statevector,pretext = "\\text{Result = }")
plot_bloch_multivector(result_statevector)

qc = QuantumCircuit(1)
qc.x(0)
qc.z(0)
qc.h(0)

qc.draw('mpl')

result_unitary = execute(qc,backend_u).result().get_unitary()
array_to_latex(result_unitary,pretext = "\\text{U = XZH = }")

qc = QuantumCircuit(2)
qc.h(0)
qc.x(1)

qc.draw('mpl')

array_to_latex(execute(qc,backend_u).result().get_unitary())

qc = QuantumCircuit(2)
qc.h(0)

qc.draw('mpl')

array_to_latex(execute(qc,backend_u).result().get_unitary())

qc = QuantumCircuit(2)
qc.sdg(1)
qc.z(0)
qc.draw('mpl')

array_to_latex(execute(qc,backend_u).result().get_unitary())

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

qc.draw('mpl')

entangled = execute(qc,backend_s).result()
entangled_statevector = entangled.get_statevector()
entangled_counts = entangled.get_counts()
array_to_latex(entangled_statevector, pretext = "\\text{Statevector = }")
plot_histogram(entangled_counts)

import qiskit
qiskit.__qiskit_version__

