!pip install qiskit qiskit-aer

!pip install qiskit
!pip install pylatexenc

from qiskit import *
from qiskit.tools.monitor import job_monitor
from qiskit.tools.visualization import plot_state_qsphere
from qiskit.visualization import plot_histogram, plot_bloch_multivector, array_to_latex


# create a circuit
circuit = QuantumCircuit (1)

# Apply hadamard gate
circuit.h(0)

circuit.h(0)

#draw circuit
circuit.draw(output = 'mpl', initial_state = True)


# select a simulator
simulator = Aer.get_backend('aer_simulator')

# save statevector
circuit.save_statevector()

# assemble our circuit
qobj = assemble(circuit)

# run on simulator
job = simulator.run(qobj)

# monitoring the process
job_monitor(job)

# get results from job
result = job.result()

# get statevector from result
final_state = result.get_statevector()

print(final_state)
array_to_latex(final_state)




# this vector is in which state of quantum?
plot_bloch_multivector(final_state)



# create a circuit
circuit = QuantumCircuit(1)

# Apply a gate
circuit.h(0)

circuit.h(0)

# draw circuit
circuit.draw(output = 'mpl', initial_state=True)

# select a simulator
simulator = Aer.get_backend('aer_simulator')

# save unitary
circuit.save_unitary()

# assemble our circuit
qobj = assemble(circuit)

# run on simulator
job = simulator.run(qobj)

# monitoring the process
job_monitor(job)

# get results from job
result = job.result()

# get the unitary
unitary = result.get_unitary()

print (unitary)
array_to_latex(unitary)