Hellow!
i’m using IBMQ real device to run my circuit and obtain results. But I am facing connection error frequently. (see attached screen shot)
Since I have dozens of data to run and the circuit need to be executed multiple times, I design a while loop in python to do the job.
I use pennylane package to build circuits and send jobs to ibmq server, if I run the circuit wth simulater backend (‘ibmq_qasm_simulator’), it works decently without any errors. However, running on real machine keeps show connection errors.
I think my code is correct, since they work fine with simulator backend.
A reproducible example code is shown as below.
Usually IBMQ returns first request of the while loop, and i can see the result with command: print( ‘result:’ , rst ). But later, no matter how many cycle is done, the code shows the same connection error.
'Error submitting job: "(\'Connection aborted.\', RemoteDisconnected(\'Remote end closed connection without response\'))"'
I also checked the jobs on IBMQ website, they are all canceled without any reason.
I wonder if i visit the server too frequently, so that the server blocks my usage. If so, what should i do?
Also, it seems that qiskit have switched to a new provider (not
IBMQ
) now, is that related to this issue?
Any suggestion is appreciated, thanks!
import pennylane as qml
from qiskit import IBMQ
sleep_time = 60
num_retries = 5
str_error = None
dev = qml.device('qiskit.ibmq', wires=2, backend='ibmq_qasm_simulator') ## 'ibmq_belem')'ibmq_quito')# ##simulator or real device
@qml.qnode(dev)
def circuit(x, y):
qml.RY(y, wires=[0])
qml.RX(x, wires=[0])
qml.CNOT(wires=[0, 1])
return qml.expval(qml.PauliZ(wires=1))
data = iter([[0.1,0.2],[0.2,0.3],[0.4,0.5]])
while True:
try:
if not str_error: #calculate next data if no error happen
databatch=next(data)
for x in range(0, num_retries): #reconnect num_retries times if error happen
try:
rst0 = circuit(*databatch)
rst = [rst0,rst0]
print('result:',rst)
str_error = None
except Exception as e: # if error happen, print error. (usually see: 'Error submitting job: "(\'Connection aborted.\', RemoteDisconnected(\'Remote end closed connection without response\'))"' )
str_error = str(e)
print(e)
if str_error: # if 'some_string'(error happens) -> sleep for a while and submit job again
time.sleep(sleep_time) # wait before trying to fetch the data again
sleep_time *= 3
print(f'retry {x} times')
else: # if None (no error) -> break for loop and calculate next data
break
except StopIteration: # if no data remain, break while loop
break