I've got the following quantum code using QISKit (based on hello_quantum.py):

import sys, os
from qiskit import QuantumProgram, QISKitError, RegisterSizeError

# Create a QuantumProgram object instance.
Q_program = QuantumProgram()
    import Qconfig
    Q_program.set_api(Qconfig.APItoken, Qconfig.config["url"])
    offline = True
    print("WARNING: There's no connection with IBMQuantumExperience servers.");
print("The backends available for use are: {}\n".format(",".join(Q_program.available_backends())))
backend = 'ibmqx5'
    # Create a Quantum Register called "qr" with 2 qubits.
    qr = Q_program.create_quantum_register("qr", 2)
    # Create a Classical Register called "cr" with 2 bits.
    cr = Q_program.create_classical_register("cr", 2)
    # Create a Quantum Circuit called "qc". involving the Quantum Register "qr"
    # and the Classical Register "cr".
    qc = Q_program.create_circuit("bell", [qr], [cr])

    # Add the H gate in the Qubit 0, putting this qubit in superposition.
    # Add the CX gate on control qubit 0 and target qubit 1, putting 
    # the qubits in a Bell state
    qc.cx(qr[0], qr[1])

    # Add a Measure gate to see the state.
    qc.measure(qr, cr)

    # Compile and execute the Quantum Program.
    result = Q_program.execute(["bell"], backend=backend, shots=1024, seed=1)

    # Show the results.

except QISKitError as ex:
    print('There was an error in the circuit!. Error = {}'.format(ex))
except RegisterSizeError as ex:
    print('Error in the number of registers!. Error = {}'.format(ex))

I set my APItoken in Qconfig.py as:

APItoken = 'XXX'
config = {
    'url': 'https://quantumexperience.ng.bluemix.net/api',

However, the code fails with the following error:

The backends available for use are: ibmqx2,ibmqx5,ibmqx4,ibmqx_hpc_qasm_simulator,ibmqx_qasm_simulator,local_qasm_simulator,local_clifford_simulator,local_qiskit_simulator,local_unitary_simulator

There was an error in the circuit!. Error = 'QISkit Time Out'

I've tested both ibmqx4 and ibmqx5, the same issue. I can see that they're active at /qx/devices.

What does it mean? Does it mean the IBM Q server is down, or the program is too big to execute? Or there is something else going on? In other words, what should I do to run a simple Hello Quantum program on IBM quantum server?


Your job timed out, probably because of the queue being too long for the job to complete in the time allowed by default for .execute().

But you already know that, of course, because you have already written an excellent answer of your own. Nevertheless, I have some insights to add from battle hardened experience.

I usually use this notebook to check on how busy a device is, and if it is active. Then I typically run jobs in the following way.

    noResults = True
    while noResults:
        try: # try to run, and wait if it fails
            executedJob = engine.execute(["script"], backend=backend, shots=shots, max_credits = 5, wait=30, timeout=600)
            resultsVeryRaw = executedJob.get_counts("script")
            if ('status' not in resultsVeryRaw.keys()):
                noResults = False
                print("This is not data, so we'll wait and try again")
            print("Job failed. We'll wait and try again")

This uses try to manage any exceptions that might result. The program will just wait and try again rather than crash.

If we get to the point of successfully using .get_counts, the program then checks to see if it actually contains results. Or rather, it checks that the 'status' key is not present, for it is the harbinger of doom. If there is not proper results, the program again waits and tries again.


As per GitHub post, I had to increase the timeout for Q_program.execute(), for example:

result = Q_program.execute(["bell"], backend=backend, shots=1024, seed=1, timeout=600)

The reason is probably, that the queues are busy, so we need to tell QISKit to wait up to 10 minutes. This instruction is basically blocking the rest of the script and wait till the job is executed on the actual backend server and the results are returned.

To list details of the jobs which has been submitted, the following code can be used as proposed by @ajavadia:

from qiskit import QuantumProgram
import Qconfig

qp = QuantumProgram()
qp.set_api(Qconfig.APItoken, Qconfig.config['url'])

# Download details of all the jobs you've ever submitted (the default limit is 50).
my_jobs = qp.get_api().get_jobs(limit=999)

# Filter down to get a list of completed jobs.
done_jobs = [j for j in my_jobs if j['status']=='COMPLETED']

# Print the results for all of your completed jobs.
for j in done_jobs:
    for q in j['qasms']:
  • $\begingroup$ Dealing with timeouts is somewhat inevitable, unfortunately. As well as increasing how long it will wait, you could use exception handling to get it to try again. $\endgroup$ – James Wootton Mar 21 '18 at 14:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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