%pip install qiskit

from qiskit import ClassicalRegister, QuantumRegister, QuantumCircuit


from qiskit_aer import AerSimulator
from qiskit.primitives import BackendEstimator, BackendSampler

import numpy as np
np.set_printoptions(precision=3, suppress=True)

backend = AerSimulator(method='automatic')

q = QuantumRegister(1)
c = ClassicalRegister(1)
circuit = QuantumCircuit(q, c)
circuit.measure(q[0], c[0])

circuit.draw(output='mpl')


sampler = BackendSampler(backend)
job = sampler.run(circuit, options={'shots': 1})
result = job.result()
print("Counts",result.quasi_dists[0])

backend = AerSimulator(method='statevector')

from qiskit.quantum_info import Statevector
circuit = QuantumCircuit(q, c)
circuit.id(q[0])


# get the statevcector
state = Statevector.from_instruction(circuit)
print(state)



circuit.draw(output='mpl')

from qiskit.visualization import plot_bloch_multivector

print("Initial state")
plot_bloch_multivector(state)

circuit.h(q[0])
circuit.draw(output='mpl')


state = Statevector.from_instruction(circuit)
print("After a Hadamard gate")
plot_bloch_multivector(state)

from qiskit.visualization import plot_histogram


circuit.measure(q[0], c[0])
job = sampler.run(circuit, options={'shots': 1024})
result = job.result()

print("Initial state statistics")
plot_histogram(result.quasi_dists[0])