Hi @CatalinaAlbornoz , thank you for the nice response.
I am trying to use qiskit-runtime to run my circuit recently.
The advantage to use runtime program is that they have many built-in features like error mitigation.
Nevertheless, the most important thing to me is that it can open a session so that I can keep submit jobs to quantum device without queuing again until the session is closed. This is very convenient to me since my circuits are usually short but needed to execute many times.
However, I didn’t find many document introducing this program from pennylane.
According to doc1 & doc2, there are two runtime program: circuit_runner and sampler
I adjust my code as follows:
# minimum qiskit-runtime connect-testing code
import time
import pennylane as qml
from qiskit_ibm_provider import IBMProvider
sleep_time = 5
num_retries = 5
str_error = None
initial_layout = None #[0,1] #
program_id = 'qiskit.ibmq.circuit_runner' # 'qiskit.ibmq.sampler' #
backend = 'ibmq_qasm_simulator' # or 'ibm_brisbane' #
provider = IBMProvider()
dev = qml.device(program_id, wires=2, backend=backend
, provider=provider,initial_layout=initial_layout)
@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=0)),qml.expval(qml.PauliY(wires=1))
data = iter([[[0.1,0.2,0.3],[0.2,0.3,0.4]],[[0.4,0.5,0.6],[0.5,0.6,0.7]]])
while True:
try:
if not str_error:
databatch=next(data)
for x in range(0, num_retries):
try:
rst = circuit(*databatch)
print('result:',rst)
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
Through this code, I tested different situation as follows
- A.1 If circuit_runner program is used and initial_layout=None, this code runs fine on both simulator and real device.
- A.2 If circuit_runner program is used and initial_layout is specified, both simulator and real device show error:
RuntimeJobFailureError: 'Unable to retrieve job result. TRANSPILERERROR: "\'INITIAL_LAYOUT\' (2) AND CIRCUIT (32) HAD DIFFERENT NUMBERS OF QUBITS'
-
A.3 If sampler program is used and initial_layout=None, this code runs fine on both simulator and real device.
-
A.4 If sampler program is used and initial_layout is specified, this code runs fine on simulator; as for real device, it usually runs fine but sometimes shows errors:
ValueError: probabilities are not non-negative
- A.5 Another wierd thing is that connection warning (see below) often occurs when using pennylane-qiskit plugins, but I never see this kind of warning when i was using qiskit packages.
WARNING: urllib3.connectionpool:Retrying (PostForcelistRetry(total=4, connect=3, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))': /jobs/cjfo31d7ui1f8qb4o8g0
The table below should conclude my experiments.

I have checked document of pennylane_qiskit.runtime(doc2) and QiskitRuntimeService, it seems that qiskit has update the sampler program.
Sampler is now a indivial class under QiskitRuntimeService.
Instead of calling QiskitRuntimeService.run function and specify program_id=sampler (old way), we can simply import Sampler and run circuit with many built-in features now (new way).
Given that the current version of pennylane_qiskit.runtime is not working properly, maybe pennylane can fix these problems by changing the ‘old way’ of implementing qiskit runtime to the ‘new way’.
Since features like error mitigation and session-opening are very important to my works, and they are not available from current version of sampler program, I really hope pennylane can fix these issues soon.
Plese let me know if fixing these runtime issues in the plan of Xandadu in the near future. If not, I think I would need to rewrite my code into qiskit version. Many thanks!