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

Raise if abstract circuits are used #1437

Merged
merged 16 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions qiskit_ibm_runtime/base_primitive.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ def _run_primitive(self, primitive_inputs: Dict, user_kwargs: Dict) -> RuntimeJo
and isinstance(self._backend, IBMBackend)
and isinstance(self._backend.service, QiskitRuntimeService)
and hasattr(self._backend, "target")
and self._service._channel_strategy != "q-ctrl"
):
validate_isa_circuits(primitive_inputs["circuits"], self._backend.target)

Expand Down
12 changes: 4 additions & 8 deletions qiskit_ibm_runtime/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import os
import re
import hashlib
import warnings
from queue import Queue
from threading import Condition
from typing import List, Optional, Any, Dict, Union, Tuple, Sequence
Expand Down Expand Up @@ -74,17 +73,14 @@ def validate_isa_circuits(circuits: Sequence[QuantumCircuit], target: Target) ->
for circuit in circuits:
message = is_isa_circuit(circuit, target)
if message:
warnings.warn(
raise IBMInputValueError(
message
+ " Circuits that do not match the target hardware definition will no longer be "
"supported after March 1, 2024. See the transpilation documentation "
+ " Circuits that do not match the target hardware definition are no longer "
"supported after 4 March 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.",
DeprecationWarning,
stacklevel=6,
"this coupled with operator transformations."
)
break


def validate_job_tags(job_tags: Optional[List[str]]) -> None:
Expand Down
10 changes: 10 additions & 0 deletions releasenotes/notes/isa-circuit-required-ed361bd65cef5ed8.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
upgrade:
- |
Circuits that do not match the target hardware definition are no longer
supported by Qiskit Runtime primitives, unless ``channel_strategy="q-ctrl"``
is used. 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.
20 changes: 19 additions & 1 deletion test/unit/test_ibm_primitives.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
)
from qiskit_ibm_runtime.ibm_backend import IBMBackend
from qiskit_ibm_runtime.utils.default_session import _DEFAULT_SESSION
from qiskit_ibm_runtime.exceptions import IBMInputValueError

from ..ibm_test_case import IBMTestCase
from ..utils import (
Expand Down Expand Up @@ -866,7 +867,7 @@ def test_abstract_circuits(self, primitive):
else:
circ.measure_all()

with self.assertWarnsRegex(DeprecationWarning, "target hardware"):
with self.assertRaisesRegex(IBMInputValueError, "target hardware"):
inst.run(**run_input)

@data(Sampler, Estimator)
Expand Down Expand Up @@ -995,3 +996,20 @@ def test_qctrl_unsupported_values_for_options(self):
_ = inst.run(self.qx, observables=self.obs, **bad_opt)

self.assertIn(expected_message, str(exc.exception))

@data(Sampler, Estimator)
def test_qctrl_abstract_circuit(self, primitive):
"""Test q-ctrl can still accept abstract circuits."""
backend = get_mocked_backend()
backend._service._channel_strategy = "q-ctrl"
inst = primitive(backend=backend)

circ = QuantumCircuit(3, 3)
circ.cx(0, 2)
run_input = {"circuits": circ}
if isinstance(inst, Estimator):
run_input["observables"] = SparsePauliOp("ZZZ")
else:
circ.measure_all()

inst.run(**run_input)
Loading