from qiskit import *
import matplotlib.pyplot as plt

qreg = QuantumRegister(2)
creg = ClassicalRegister(2)

circuit = QuantumCircuit(qreg,creg)

circuit.reset(qreg[0])
circuit.reset(qreg[1])

circuit.h(qreg[0])

circuit.cx(qreg[0],qreg[1])

circuit.measure(qreg[0],creg[0])
circuit.measure(qreg[1],creg[1])

backend = Aer.get_backend('qasm_simulator')
job = execute(circuit, backend, shots=2048)
result = job.result()

circuit.draw("mpl")

visualization.plot_histogram(result.get_counts())

from qiskit.providers.ibmq import least_busy

provider = IBMQ.load_account() #If this throws an error, run IBMQ.save_account(YOUR_API_KEY). You will find your api key on https://quantum-computing.ibm.com/account

device = least_busy(provider.backends(filters=lambda x: x.configuration().n_qubits >= 3 and 
                                   not x.configuration().simulator and x.status().operational==True))

job = execute(circuit, backend=device, shots=2048) #May take some time
results = job.result()
answer = results.get_counts(circuit)

visualization.plot_histogram(answer)

