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

ISA checks inside control flow operations sometimes fail for valid circuits #1843

Closed
yaelbh opened this issue Aug 6, 2024 · 3 comments · Fixed by #1916
Closed

ISA checks inside control flow operations sometimes fail for valid circuits #1843

yaelbh opened this issue Aug 6, 2024 · 3 comments · Fixed by #1916
Assignees
Labels
bug Something isn't working
Milestone

Comments

@yaelbh
Copy link
Collaborator

yaelbh commented Aug 6, 2024

Describe the bug

Recently, in #1784, we added ISA checks inside bodies of control flow operations. @ashsaki found an example similar to the one below, where a valid circuit is labeled as invalid by this new ISA check.

  • The bug seems to occur only for simulators. I was not able to reproduce it on a device.
  • By the error message, it appears that the bug is related to the qubit mapping here. Apparently qubit indices change inside the control operation blocks. I'm not sure exactly how, @mtreinish can you (or someone else from the qiskit team) elaborate? Can you please refer me to relevant documentation?

Steps to reproduce

from qiskit import QuantumCircuit

from qiskit_ibm_runtime import SamplerV2
from qiskit_ibm_runtime.fake_provider import FakeCairoV2


backend = FakeCairoV2()
sampler = SamplerV2(mode=backend)

circ = QuantumCircuit(5, 1)
circ.x(0)
circ.measure(0, 0)
with circ.if_test((0, 1)):
    circ.cx(1, 2)

res = sampler.run([circ]).result()

Output is:

  File "/mnt/wsl/balagan/saki.py", line 16, in <module>
    res = sampler.run([circ]).result()
  File "/root/miniforge3/envs/env2/lib/python3.10/site-packages/qiskit_ibm_runtime/sampler.py", line 159, in run
    return self._run(coerced_pubs)  # type: ignore[arg-type]
  File "/root/miniforge3/envs/env2/lib/python3.10/site-packages/qiskit_ibm_runtime/base_primitive.py", line 174, in _run
    validate_isa_circuits([pub.circuit], self._backend.target)
  File "/root/miniforge3/envs/env2/lib/python3.10/site-packages/qiskit_ibm_runtime/utils/validations.py", line 89, in validate_isa_circuits
    raise IBMInputValueError(
qiskit_ibm_runtime.exceptions.IBMInputValueError: 'The instruction cx on qubits (0, 1) is not supported by the target system. Circuits that do not match the target hardware definition are no longer supported after March 4, 2024. See the transpilation documentation (https://docs.quantum.ibm.com/transpile) for instructions to transform circuits and the primitive examples (https://docs.quantum.ibm.com/run/primitives-examples) to see this coupled with operator transformations.'

Expected behavior

Well, don't crash and let the circuit pass the ISA test.

Suggested solutions

Well, debug and fix 😄.

Additional Information

  • qiskit-ibm-runtime version:
  • Python version:
  • Operating system:
@ashsaki
Copy link
Contributor

ashsaki commented Aug 6, 2024

It happens on real backends as well. Switching the backend to ibm_sherbrooke threw me 'The instruction ecr on qubits (0, 1) is not supported by the target system.

Example:

from qiskit import QuantumCircuit, transpile

from qiskit_ibm_runtime import QiskitRuntimeService, SamplerV2
from qiskit_ibm_runtime.fake_provider import FakeCairoV2

service = QiskitRuntimeService()
backend = service.backend("ibm_sherbrooke")
sampler = SamplerV2(mode=backend)

circ = QuantumCircuit(5, 1)
circ.x(0)
circ.measure(0, 0)
with circ.if_test((0, 1)):
    circ.cx(1, 2)

trans_qc = transpile(circ, backend=backend, optimization_level=1)

res = sampler.run([trans_qc]).result()

@yaelbh
Copy link
Collaborator Author

yaelbh commented Aug 8, 2024

Consider replacing the entire ISA check implementation with qiskit's transpiler pass: Qiskit/qiskit#12916 (comment).

@yaelbh
Copy link
Collaborator Author

yaelbh commented Sep 11, 2024

Inside the control flow operation, when the ISA check checks cx(1, 2), it wrongly checks cx(0, 1), because of a bug. Since (0, 1) is not connected in Sherbrooke (only (1, 0) is connected - the other direction), the ISA check fails, in spite of (1, 2) being connected and valid.

This bug occurs also on the other way around: in Cusco, (0, 1) is connected but (1, 2) is not connected. Because of the bug, cx(1, 2) wrongly passes the ISA check, and the failure is deferred must later down the stack:

from qiskit import QuantumCircuit

from qiskit_ibm_runtime import QiskitRuntimeService, SamplerV2


service = QiskitRuntimeService()
backend = service.backend("ibm_cusco")
sampler = SamplerV2(mode=backend)

circ = QuantumCircuit(5, 1)
circ.x(0)
circ.measure(0, 0)
with circ.if_test((0, 1)):
    circ.ecr(1, 2)

job = sampler.run([circ])
print(job.job_id())
res = job.result()

print(res)

Output:

    raise RuntimeJobFailureError(f"Unable to retrieve job result. {error_message}")
qiskit_ibm_runtime.exceptions.RuntimeJobFailureError: 'Unable to retrieve job result. Error code 6103; Internal OpenQASM3 compilation error'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
3 participants