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)

# Apply h gate to the control and target qubits
qc.x(0)
qc.h(0)
qc.h(1)

#Applying the CNOT gate
#qc.cx(0,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')

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

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

#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_statevector()

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

#execute the circuit and get the plain result
out = execute(qc,backend).result()
#getting the count of the result
counts = out.get_counts()
#plotting the histogram
plot_histogram(counts)

