# I am a comment in python

print("Hello From Quantum World :-)")

# please run me

from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit, execute, Aer
from random import randrange

# Create my circuit and register objects
qreg = QuantumRegister(2) # my quantum register
creg = ClassicalRegister(2) # my classical register 
circuit = QuantumCircuit(qreg,creg) # my quantum circuit

# let's apply a Hadamard gate to the first qubit

circuit.h(qreg[0])

# let's set the second qubit to |1>
circuit.x(qreg[1])

# let's apply CNOT(first_qubit,second_qubit)
circuit.cx(qreg[0],qreg[1])

# let's measure the both qubits
circuit.measure(qreg,creg)

print("The execution was completed, and the circuit was created :)")

## execute the circuit 100 times
job = execute(circuit,Aer.get_backend('qasm_simulator'),shots=1024)
# get the result
counts = job.result().get_counts(circuit)
print(counts)

from qiskit.tools.visualization import matplotlib_circuit_drawer as drawer
# draw the overall circuit 
drawer(circuit)
# re-execute me if you DO NOT see the circuit diagram

from qiskit import IBMQ

IBMQ.save_account('write YOUR IBM API TOKEN here')

# Then, execute this cell

IBMQ.stored_accounts()

IBMQ.load_accounts()

IBMQ.active_accounts()

IBMQ.backends()

IBMQ.backends(operational=True, simulator=False)

from qiskit.backends.ibmq import least_busy
least_busy(IBMQ.backends(simulator=False))

backend = least_busy(IBMQ.backends(simulator=True))

backend.name()

from qiskit import compile

qobj = compile(circuit, backend=backend, shots=1024)

job = backend.run(qobj)

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

backend_real = least_busy(IBMQ.backends(simulator=False))

backend_real.name()

backend_real.status()

qobj_real = compile(circuit, backend=backend_real, shots=1024)

job_real = backend_real.run(qobj_real)

job_real.queue_position()

result_real = job_real.result()
counts_real = result_real.get_counts()
print(counts_real)

