from qiskit import QuantumCircuit, BasicAer, execute, IBMQ
from qiskit.visualization import plot_histogram

ghz = QuantumCircuit(3,3)
ghz.h(0)
ghz.cx(0,1)
ghz.cx(1,2)
#ghz.barrier(0,2) 
ghz.measure([0,1,2],[0,1,2])
# also possible to measure only one qubit with the desired classical bit.
#For example, qubit 2 with classical bit 1: qc.measure(1,0) 

ghz.draw('mpl')

backend = BasicAer.get_backend('qasm_simulator')

result = execute(ghz, backend).result() #shots=1024 is by default defined
counts = result.get_counts()

plot_histogram(counts)

leg = ['counts']
plot_histogram(counts, legend=leg, sort='asc',color='green') 

# for more counts, we have

job2 = execute(ghz, backend, shots=1024)
result2 = job2.result()
counts2 = result2.get_counts()

job3 = execute(ghz, backend, shots=1024)
result3 = job3.result()
counts3 = result3.get_counts()

#brazilian flag :D 
leg = ['counts-1','counts-2', 'counts-3']
plot_histogram([counts,counts2,counts3], legend=leg, sort='asc', figsize = (8,7), 
               color=['gold','green','blue']) 

plot_histogram([counts,counts2,counts3], legend=leg, sort='asc') 

qc_spec = QuantumCircuit(3)
qc_spec.measure_all()

backend = BasicAer.get_backend('qasm_simulator')
#specify some linear connection
couple_map = [[0,1],[1,2]]

qc_spec.draw('mpl')

job = execute(qc_spec,backend, shots= 1024, coupling_map = couple_map)
results = job.result()
counts = result.get_counts()

print(counts)

import qiskit.tools.jupyter
from qiskit.tools import job_monitor

provider = IBMQ.load_account()

%qiskit_backend_overview

backend_real = provider.get_backend('ibmq_belem') 
job = execute(ghz, backend_real)

job_monitor(job)

result = job.result()
counts = result.get_counts()
plot_histogram(counts)

