Qiskit / qiskit-ibm-runtime

IBM Client for Qiskit Runtime
https://docs.quantum.ibm.com/api/qiskit-ibm-runtime
Apache License 2.0
161 stars 157 forks source link

Runtime fails with `Error code 3211; Job not valid. Qubit(QuantumRegister(3, 'q1'), 0)` on valid job #1979

Closed jwoehr closed 1 month ago

jwoehr commented 1 month ago

Describe the bug Valid OpenQASM 3 source is imported, the circuit transpiled, and sent via QiskitRuntimeService. The job fails with Error code 3211; Job not valid. Qubit(QuantumRegister(3, 'q1'), 0)"

Steps to reproduce

$ cat test.qasm 
OPENQASM 3.0;
include "stdgates.inc";
bit[1] c0;
qubit[3] q1;

cx q1[0], q1[1];
cx q1[1], q1[2];
x q1[1];
x q1[2];
c0[0] = measure q1[0];
if (!c0[0]) {
  x q1[0];
  x q1[2];
}
$ python
>>> from qiskit_ibm_runtime import SamplerV2
>>> from qiskit import transpile
>>> from qiskit_ibm_runtime import QiskitRuntimeService
>>> p = QiskitRuntimeService()
>>> backend = p.least_busy(operational=True, simulator=False)
>>> backend.name
'ibm_sherbrooke'
>>> from qiskit import qasm3
>>> qc = qasm3.load('test.qasm')
>>> qc_t3 = transpile(qc, backend=backend)
>>> sampler=SamplerV2(backend)
>>> job=sampler.run([qc_t3], shots=1000)
>>> print(job.status())
ERROR
>>> print(job.result())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/jwoehr/work/Qiskit/qrel_env/lib/python3.10/site-packages/qiskit_ibm_runtime/runtime_job_v2.py", line 138, in result
    raise RuntimeJobFailureError(f"Unable to retrieve job result. {error_message}")
qiskit_ibm_runtime.exceptions.RuntimeJobFailureError: "Unable to retrieve job result. Error code 3211; Job not valid. Qubit(QuantumRegister(3, 'q1'), 0)"

This failing job ID was cw8ja50ggr6g0087p13g.

Expected behavior Job runs to completion

Suggested solutions Jake Lishman posts in Qiskit Slack:

That error is coming from the server side, so it seems like it’s related to backend code. Fwiw, I ran this:


import io
from qiskit import qasm3, transpile, qpy
from qiskit_ibm_runtime import QiskitRuntimeService

service = QiskitRuntimeService() backend = service.backend("ibm_sherbrooke")

prog = """ OPENQASM 3.0; include "stdgates.inc"; bit[1] c0; qubit[3] q1;

cx q1[0], q1[1]; cx q1[1], q1[2]; x q1[1]; x q1[2]; c0[0] = measure q1[0]; if (!c0[0]) { x q1[0]; x q1[2]; } """ qc = qasm3.loads(prog)

qc_t = transpile(qc, backend, seed_transpiler=0)

print(qasm3.dumps(qc_t))

with io.BytesIO() as fptr: qpy.dump(qc_t, fptr) fptr.seek(0) qc_qpy = qpy.load(fptr)[0] qc_qasm = qasm3.loads(qasm3.dumps(qc_t))

print(qasm3.dumps(qc_qpy)) print(qasm3.dumps(qc_qasm))

print(qc_t.draw(idle_wires=False)) print(qc_qpy.draw(idle_wires=False)) print(qc_qasm.draw(idle_wires=False))


>which brings in the circuit, roundtrips it through QPY, through QASM3, then outputs it again to OQ3 and draws it, and that all passes (and on a cursory glance looks correct too), which suggests that Qiskit’s data model is doing the right thing (otherwise I’d expect us to have errored out somewhere or drawn some nonsense).  It might be a similar trouble in the valid-circuits check on the backend side, but I wouldn’t know.

**Additional Information**

- **qiskit-ibm-runtime version**: 0.31.0
- **Python version**: 3.10.12
- **Operating system**: Linux PopOS Ubuntu-like 
jwoehr commented 1 month ago

Like #1969

kt474 commented 1 month ago

Commented here, but this should be fixed now.

jyu00 commented 1 month ago

I can confirm running the code in the OP failed for me yesterday but worked today.

jwoehr commented 1 month ago

Asking user via Slack to retest.

jwoehr commented 1 month ago

Works for myself and also for one other user reporting in on Qiskit Slack. Thanks!