3
$\begingroup$

I am attempting to run the following on a remote backend through QISkit:

try:
    import math
    from qiskit import QuantumCircuit, ClassicalRegister, QuantumRegister
    from qiskit import execute, IBMQ, Aer
    from qiskit.backends.ibmq import least_busy

    q = QuantumRegister(1, 'q')
    c1 = ClassicalRegister(1, 'c1')
    c2 = ClassicalRegister(1, 'c2')
    qc1 = QuantumCircuit(q, c1)
    qc2 = QuantumCircuit(q, c2)
    qc1.ry(math.pi*0.25, q[0])
    qc2.ry(math.pi*0.25, q[0])

    qc1.measure(q, c1)
    qc2.measure(q, c2)

    backend_sim = Aer.get_backend('qasm_simulator')

    job_sim1 = execute(qc1, backend_sim)
    result_sim1 = job_sim1.result()

    job_sim2 = execute(qc2, backend_sim)
    result_sim2 = job_sim2.result()

    print("simulation one: ", result_sim1)
    print(result_sim1.get_counts(qc1))
    print("simulation two: ", result_sim2)
    print(result_sim2.get_counts(qc2))

    ibmq_backends = IBMQ.backends()

    print("Remote backends: ", ibmq_backends)
    try:
        least_busy_device = least_busy(IBMQ.backends(simulator=False))
        print("Running on current least busy device: ", least_busy_device)

        job_exp = execute(qc, least_busy_device, shots=1024, max_credits=10)
        result_exp = job_exp.result()

        print("experiment: ", result_exp)
        print(result_exp.get_counts(qc))
    except:
        print("all devices are unavailable.")
except QiskitError as ex:
    print('an error occurred. Error = {}'.format(ex))

After the local qasm simulator runs, I receive:

Remote backends: []
All devices are currently unavailable

However, if I run the "hello_quantum.py" example given through IBMQ, I am able to access multiple backends and use the ibm_16_melbourne computer. Interestingly, there seems to be an error in this program specifically.

Any ideas on what could be going wrong here?

$\endgroup$

1 Answer 1

3
$\begingroup$

To use the remote backends, you need to sign into the IBM Q Experience. This is done with

IBMQ.load_accounts()

(after IBMQ has been imported, of course). Since IBMQ.backends() returns the list of backends that your account allows you to use, it will return an empty list when you are not signed in.

An additional note: If you update to the most recent Qiskit version (as of 2019-02-20) you'll need to use from qiskit.providers.ibmq import least_busy to import least_busy.

$\endgroup$
3
  • $\begingroup$ I realize I had forgotten to load my account, thank you very much! I am able to now print a list of remote backends and select the least busy device. However, I am still unable to run the simulation through this device for some reason. I receive the same error: "All devices are currently unavailable". I have even tried to enable my account again through "qiskit.IBMQ.enable_account()" but I receive a warning that my credentials are already in use. Any more suggestions? $\endgroup$ Feb 28, 2019 at 17:11
  • $\begingroup$ There's a full list of things you can try here quantumcomputing.stackexchange.com/questions/5532/… Other than that, I'm not sure. Is your account able to run jobs on the Q Experience web interface? $\endgroup$ Mar 1, 2019 at 21:45
  • $\begingroup$ I was able to get it running now, thank you very much! $\endgroup$ Mar 3, 2019 at 5:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.