from qiskit import QuantumCircuit, ClassicalRegister, QuantumRegister, execute, Aer
from qiskit.tools.visualization import circuit_drawer, plot_histogram
import numpy as np
from numpy import pi

num_measurements = 5

q = QuantumRegister(1)
c = ClassicalRegister(num_measurements)

circ = QuantumCircuit(q,c)

for m in range(num_measurements):
    circ.measure(q[0],c[m]) 

circuit_drawer(circ, output='mpl')

backend_sim = Aer.get_backend('qasm_simulator')

job_sim = execute(circ, backend_sim, shots=1)

result_sim = job_sim.result()

counts = result_sim.get_counts(circ)
print(counts)

num_measurements = 5

q = QuantumRegister(1)
c = ClassicalRegister(num_measurements)

circ = QuantumCircuit(q,c)

for m in range(num_measurements):
    circ.measure(q[0],c[m])
    circ.rx(pi, q[0])

circuit_drawer(circ, output='mpl')

job_sim = execute(circ, backend_sim, shots=1)

result_sim = job_sim.result()

counts = result_sim.get_counts(circ)
print(counts)

num_measurements = 1

q = QuantumRegister(1)
c = ClassicalRegister(num_measurements)

circ = QuantumCircuit(q,c)

circ.rx(pi/2, q)
circ.measure(q, c)

circuit_drawer(circ, output='mpl')

job_sim = execute(circ, backend_sim, shots=1)

result_sim = job_sim.result()

counts = result_sim.get_counts(circ)
print(counts)

repetitions = 1024

job_sim = execute(circ, backend_sim, shots=repetitions)

result_sim = job_sim.result()

counts = result_sim.get_counts(circ)
print(counts)

plot_histogram(counts)

