Disconnect issues with qiskit hardware

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

I found that the disconnection problem might be highly related to provider issue.
I have tried to run qiskit version of my code.
If I use old IBMQ provider, the connection error happens.
If I use new IBMProvider instead, it works without any error.
A reproducible code is as follows:

from qiskit import *
from qiskit.compiler import transpile, assemble

sleep_time = 5
num_retries = 5
str_error = None
#provider = IBMProvider()        #This has no error
provider = IBMQ.load_account()   #This has error
backend = provider.get_backend('ibm_oslo')

def qcircuit(x,y):
    qr = QuantumRegister(2)
    cr = ClassicalRegister(2)
    circuit = QuantumCircuit(qr, cr)
    circuit.rx(x,qr[0])
    circuit.ry(y,qr[1])
    circuit.cx(qr[0], qr[1])
    circuit.measure(qr, cr)
    mapped_circuit = transpile(circuit, backend=backend)
    job = backend.run(mapped_circuit, shots=1024)
    return job.result()

data = iter([[0.1,0.2],[0.2,0.3],[0.4,0.5]])

while True:
    try:
        if not str_error:
            databatch=next(data)
        for x in range(0, num_retries):  
            try:
                result = qcircuit(*databatch)                
                counts = result.get_counts()
                print('result:',counts)
                str_error = None
            except  Exception as e:
                str_error = str(e)
                print(e)
            if str_error:               # if None->break; if 'some_string'(error happens)->sleep
                time.sleep(sleep_time)  # wait before trying to fetch the data again
                sleep_time *= 3
                print(f'retry {x} times')
            else:
                break
    except StopIteration:
        break

Furthermore, i also tried to change pennylane’s code into new IBMProvider directly.

provider = IBMProvider()
backend = 'ibm_oslo'
dev = qml.device('qiskit.ibmq', wires=2, backend=backend, provider=provider)

But this does not work.
Is there other way to access new IBMProvider with pennylane package?

Any suggestion is appreciated, thanks!

Hey @PoJung-Lu! Sorry to hear that you’re having this issue. Unfortunately, this seems like an issue outside of the scope of us at Xanadu :frowning:. I would try contacting IBM. You can try leaving a GitHub issue here: GitHub - Qiskit/qiskit-terra: Qiskit is an open-source SDK for working with quantum computers at the level of extended quantum circuits, operators, and algorithms.

Hi @isaacdevlugt. Thank you for your reply.
I have ask this question on qiskit slack channel, and they reply that the old IBMQ provider is deprecated.
(see their github page)
As far as I know, I didn’t see any document discussing about this issue.
If pennylane plugin does not support the new IBMProvider, I’m affraid that we will no longer be able to use IBM hardware.
Hope that pennylane would support the new IBMProvider soon, that would be very helpful.

Hey @PoJung-Lu, can you show me the output of qml.about()? I’d make sure that you’re using the most up-to-date version of pennylane (currently v0.29.1).

If that checks out, I’ll chat with some folks to see if we can figure out what’s going on :slight_smile:.

Hi @isaacdevlugt, thanks for replying.
The output of qml.about() is as follows:

> Name: PennyLane
> Version: 0.29.1
> Summary: PennyLane is a Python quantum machine learning library by Xanadu Inc.
> Home-page: https://github.com/XanaduAI/pennylane
> Author: 
> Author-email: 
> License: Apache License 2.0
> Location: /home/ubuntu2022/anaconda3/envs/research/lib/python3.10/site-packages
> Requires: appdirs, autograd, autoray, cachetools, networkx, numpy, pennylane-lightning, requests, retworkx, scipy, semantic-version, toml
> Required-by: PennyLane-Lightning, PennyLane-qiskit
> 
> Platform info:           Linux-5.15.90.1-microsoft-standard-WSL2-x86_64-with-glibc2.35
> Python version:          3.10.9
> Numpy version:           1.23.5
> Scipy version:           1.10.1
> Installed devices:
> - default.gaussian (PennyLane-0.29.1)
> - default.mixed (PennyLane-0.29.1)
> - default.qubit (PennyLane-0.29.1)
> - default.qubit.autograd (PennyLane-0.29.1)
> - default.qubit.jax (PennyLane-0.29.1)
> - default.qubit.tf (PennyLane-0.29.1)
> - default.qubit.torch (PennyLane-0.29.1)
> - default.qutrit (PennyLane-0.29.1)
> - null.qubit (PennyLane-0.29.1)
> - qiskit.aer (PennyLane-qiskit-0.29.0)
> - qiskit.basicaer (PennyLane-qiskit-0.29.0)
> - qiskit.ibmq (PennyLane-qiskit-0.29.0)
> - qiskit.ibmq.circuit_runner (PennyLane-qiskit-0.29.0)
> - qiskit.ibmq.sampler (PennyLane-qiskit-0.29.0)
> - lightning.qubit (PennyLane-Lightning-0.29.0)
> ```

Ah! So sorry @PoJung-Lu. It seems like this is a known issue for us — it’s hard for me to stay on top of everything sometimes :sweat_smile:.

It was first reported here.

We are working on a fix for supporting this in the next version of PennyLane! I’ll keep you up to date :smile:

Correction! Apologies again. The error you’re facing isn’t related to the one I posted above :sweat_smile:. It’s a new one! Looks like Qiskit changed a whole bunch of stuff lately that kinda messes with the pennylane-qiskit plugin.

Sorry for the confusion here @PoJung-Lu! I think the best course of action here is to make a github issue on our qiskit plugin repo:

I see. I will try to make a github issue when i have time.
Thanks!

1 Like

I will keep you updated on getting support for this!

1 Like

Hey @PoJung-Lu! pennylane-qiskit==0.30.1 should have this fixed :slight_smile:. Make sure to update!

1 Like

@isaacdevlugt I’ll check it out as soon as possible.
Thank you very much!

1 Like