Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QISkit Time Out for ibmqx5 #354

Closed
kenorb opened this issue Mar 21, 2018 · 8 comments
Closed

QISkit Time Out for ibmqx5 #354

kenorb opened this issue Mar 21, 2018 · 8 comments

Comments

@kenorb
Copy link
Contributor

kenorb commented Mar 21, 2018

Code

File: hello_quantum.py

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

# Create a QuantumProgram object instance.
Q_program = QuantumProgram()
try:
    import Qconfig
    Q_program.set_api(Qconfig.APItoken, Qconfig.config["url"])
except:
    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'
try:
    # 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.
    qc.h(qr[0])
    # 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 in the local_qasm_simulator.
    result = Q_program.execute(["bell"], backend=backend, shots=1024, seed=1)

    # Show the results.
    print(result)
    print(result.get_data("bell"))

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))

File: Qconfig.py

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

Result

$ python hello_quantum.py 
The backends available for use are: ibmqx5,ibmqx4,ibmqx_hpc_qasm_simulator,ibmqx2,ibmqx_qasm_simulator,local_qasm_simulator,local_clifford_simulator,local_qiskit_simulator,local_unitary_simulator

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

Steps to Reproduce (for bugs)

  1. python hello_quantum.py

Context

I am trying to run hello_quantum.py which I have modified slightly and configured API in Qconfig.py, however, it is timing out. At /qx/account/advanced I can see that ibmqx5 is available.

Your Environment

  • Environment name and version: Python 3.6.4
  • Operating System and version: macOS High Sierra
@ajavadia
Copy link
Member

@kenorb Please increase the timeout in the Q_program.execute(). Pass something like: timeout=600. The default is timeout=60 (seconds) which can be too little when the queue is busy. Doing so will let QISKit know that you are willing to wait 10 mins, while that instruction is blocking the rest of the script.

Please let me know if this works.

@kenorb
Copy link
Contributor Author

kenorb commented Mar 21, 2018

Thanks for your help. Now by these timeouts runs, I got into another MAX_CREDITS_EXCEEDED error, so I can't test it. Do you know if these credits are per day or any way of topping them up?

@rraymondhp
Copy link
Contributor

When the jobs are in the queue, your credits are being used and not returned. They will be returned only when the jobs have been executed and out of the queues.

@ajavadia
Copy link
Member

@kenorb Your credits will replenish when the job is done executing.
Note that in qiskit, when a job times out, it only times out in the frontend. The actual job will remain on the queue and eventually execute. You can come back later and see the results of your executions. Do something like this:

#setup
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 (well, up to some limit; the default 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']:
        print(q['qasm'])
        print(q['result'])

@kenorb
Copy link
Contributor Author

kenorb commented Mar 21, 2018

I think increasing the timeout helped. Probably executing the script on different backends ibmqx4, ibmqx5, ibmqx2 could help to avoid the credit limit issue.

I've tested ibmqx5 now and got execution times in the average of 50-120 seconds.

Re credits, I've created this Q&A: How to add credits?

@kenorb kenorb closed this as completed Mar 21, 2018
@AveryLeider
Copy link

Thank you so much, extending the timeout time totally solved my issue.

@quantumjim
Copy link
Member

@ajavadia Hi Ali!
Is there a way to get the value of j at the time of execution? It would be good to be able to call up the results for a specific j in done_jobs, rather than checking the qasm.

@ajavadia
Copy link
Member

@decodoku Hi James, not currently. But very soon you will be able to. All the code to do that is there, but we need to clean up a bit and write a tutorial on how to use it. It is indeed useful to be able to get the id of a submitted job, see its position in the queue, cancel it to get your credits back, or just retrieve the results at a future time.

All of this feedback is very good, so we can do this properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants