from qiskit import *
from qiskit.visualization import plot_bloch_multivector, visualize_transition, plot_histogram

# Create a quantum circuit with 2 qubits
# The default initial state of qubits will be |0> or [1,0]
qc = QuantumCircuit(2)

#Applying the x gate to second qubit
qc.x(1)

#Draw the circuit
# qc.draw()
qc.draw('mpl')

#Get the backend for the circuit to display unitary matrix
backend = Aer.get_backend('unitary_simulator')

#Get the backend for the circuit (simulator or realtime system)
#backend = Aer.get_backend('statevector_simulator')


#execute the circuit using the backend
out = execute(qc,backend).result().get_unitary()

#execute the circuit using the backend
#out = execute(qc,backend).result().get_statevector()

#import qiskit_textbook and display the statevector
from qiskit_textbook.tools import array_to_latex
array_to_latex(out, pretext = "\\text{UnitaryMatrix} = ")

#import qiskit_textbook and display the statevector
#from qiskit_textbook.tools import array_to_latex
#array_to_latex(out, pretext = "\\text{Statevector} = ")

#plot the result as a bloch sphere visualization
plot_bloch_multivector(out)

