Skip to content

Handle 0.37 deprecations #2235

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
17 changes: 5 additions & 12 deletions qiskit_ibm_runtime/fake_provider/fake_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,20 +278,13 @@ def target(self) -> Target:
return self._target

@property
def max_circuits(self) -> int:
"""(DEPRECATED) The maximum number of circuits

The maximum number of circuits that the backend supports in a single execution.
Note that the actual number of circuits the service allows may be different.
def max_circuits(self) -> None:
"""This property used to return the `max_experiments` value from the
backend configuration but this value is no longer an accurate representation
of backend circuit limits. New fields will be added to indicate new limits.
"""

issue_deprecation_msg(
"max_circuits is deprecated",
"0.37.0",
"Please see our documentation on job limits "
"https://docs.quantum.ibm.com/guides/job-limits#job-limits.",
)
return self.configuration().max_experiments
return None

@classmethod
def _default_options(cls) -> Options:
Expand Down
55 changes: 6 additions & 49 deletions qiskit_ibm_runtime/ibm_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"""Module for interfacing with an IBM Quantum Backend."""

import logging
from typing import Union, Optional, Any, List
from typing import Optional, Any, List
from datetime import datetime as python_datetime
from copy import deepcopy
from packaging.version import Version
Expand All @@ -36,7 +36,6 @@
from .api.clients import RuntimeClient
from .exceptions import (
IBMBackendApiProtocolError,
IBMBackendValueError,
IBMBackendError,
)
from .utils.backend_converter import convert_to_target
Expand Down Expand Up @@ -94,7 +93,6 @@ class IBMBackend(Backend):
* conditional: backend supports conditional operations.
* open_pulse: backend supports open pulse.
* memory: backend supports memory.
* max_shots: (DEPRECATED) maximum number of shots supported.
* coupling_map (list): The coupling map for the device
* supported_instructions (List[str]): Instructions supported by the backend.
* dynamic_reprate_enabled (bool): whether delay between primitives can be set dynamically
Expand Down Expand Up @@ -125,7 +123,6 @@ class IBMBackend(Backend):
[d->u->m] x n_registers. Latency (in units of dt) to do a
conditional operation on channel n from register slot m
* meas_map (list): Grouping of measurement which are multiplexed
* max_circuits (int): (DEPRECATED) The maximum number of experiments per job
* sample_name (str): Sample name for the backend
* n_registers (int): Number of register slots available for feedback
(if conditional is True)
Expand Down Expand Up @@ -182,16 +179,13 @@ def __init__(
self._properties: Any = None
self._defaults: Any = None
self._target: Any = None
self._max_circuits = configuration.max_experiments
if (
not self._configuration.simulator
and hasattr(self.options, "noise_model")
and hasattr(self.options, "seed_simulator")
):
self.options.set_validator("noise_model", type(None))
self.options.set_validator("seed_simulator", type(None))
if hasattr(configuration, "max_shots"):
self.options.set_validator("shots", (1, configuration.max_shots))
if hasattr(configuration, "rep_delay_range"):
self.options.set_validator(
"rep_delay",
Expand All @@ -210,13 +204,6 @@ def __getattr__(self, name: str) -> Any:
"'{}' object has no attribute '{}'".format(self.__class__.__name__, name)
)

if name in ["max_experiments", "max_shots"]:
issue_deprecation_msg(
f"{name} is deprecated",
"0.37.0",
"Please see our documentation on job limits "
"https://docs.quantum.ibm.com/guides/job-limits#job-limits.",
)
# Lazy load properties and pulse defaults and construct the target object.
self.properties()
self.defaults()
Expand Down Expand Up @@ -282,20 +269,13 @@ def dtm(self) -> float:
return self._configuration.dtm

@property
def max_circuits(self) -> int:
"""(DEPRECATED) The maximum number of circuits

The maximum number of circuits that can be
run in a single job. If there is no limit this will return None.
def max_circuits(self) -> None:
"""This property used to return the `max_experiments` value from the
backend configuration but this value is no longer an accurate representation
of backend circuit limits. New fields will be added to indicate new limits.
"""

issue_deprecation_msg(
"max_circuits is deprecated",
"0.37.0",
"Please see our documentation on job limits "
"https://docs.quantum.ibm.com/guides/job-limits#job-limits.",
)
return self._max_circuits
return None

@property
def meas_map(self) -> List[List[int]]:
Expand Down Expand Up @@ -488,26 +468,6 @@ def __call__(self) -> "IBMBackend":
# For backward compatibility only, can be removed later.
return self

def _check_circuits_attributes(self, circuits: List[Union[QuantumCircuit, str]]) -> None:
"""Check that circuits can be executed on backend.
Raises:
IBMBackendValueError:
- If one of the circuits contains more qubits than on the backend."""

if len(circuits) > self._max_circuits:
raise IBMBackendValueError(
f"Number of circuits, {len(circuits)} exceeds the "
f"maximum for this backend, {self._max_circuits})"
)
for circ in circuits:
if isinstance(circ, QuantumCircuit):
if circ.num_qubits > self._configuration.num_qubits:
raise IBMBackendValueError(
f"Circuit contains {circ.num_qubits} qubits, "
f"but backend has only {self.num_qubits}."
)
self.check_faulty(circ)

def check_faulty(self, circuit: QuantumCircuit) -> None:
"""Check if the input circuit uses faulty qubits or edges.

Expand Down Expand Up @@ -556,7 +516,6 @@ def __deepcopy__(self, _memo: dict = None) -> "IBMBackend":
cpy._coupling_map = self._coupling_map
cpy._defaults = deepcopy(self._defaults, _memo)
cpy._target = deepcopy(self._target, _memo)
cpy._max_circuits = self._max_circuits
cpy._options = deepcopy(self._options, _memo)
return cpy

Expand Down Expand Up @@ -639,9 +598,7 @@ def from_name(
conditional=False,
open_pulse=False,
memory=False,
max_shots=1,
gates=[GateConfig(name="TODO", parameters=[], qasm_def="TODO")],
coupling_map=[[0, 1]],
max_experiments=300,
)
return cls(configuration, api)
11 changes: 0 additions & 11 deletions qiskit_ibm_runtime/models/backend_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@ class QasmBackendConfiguration:
conditional: backend supports conditional operations.
open_pulse: backend supports open pulse.
memory: backend supports memory.
max_shots: maximum number of shots supported.
"""

_data: Dict[Any, Any] = {}
Expand All @@ -218,7 +217,6 @@ def __init__(
conditional: bool,
open_pulse: bool,
memory: bool,
max_shots: int,
coupling_map: list,
meas_levels: List[int] = None,
meas_kernels: List[str] = None,
Expand All @@ -228,7 +226,6 @@ def __init__(
dynamic_reprate_enabled: bool = False,
rep_delay_range: List[float] = None,
default_rep_delay: float = None,
max_experiments: int = None,
sample_name: str = None,
n_registers: int = None,
register_map: list = None,
Expand Down Expand Up @@ -260,7 +257,6 @@ def __init__(
operations
open_pulse (bool): True if the backend supports OpenPulse
memory (bool): True if the backend supports memory
max_shots (DEPRECATED) (int): The maximum number of shots allowed on the backend
coupling_map (list): The coupling map for the device
meas_levels: Supported measurement levels.
meas_kernels: Supported measurement kernels.
Expand All @@ -275,7 +271,6 @@ def __init__(
``dynamic_reprate_enabled=True``.
default_rep_delay (float): Value of ``rep_delay`` if not specified by user and
``dynamic_reprate_enabled=True``.
max_experiments (DEPRECATED) (int): The maximum number of experiments per job
sample_name (str): Sample name for the backend
n_registers (int): Number of register slots available for feedback
(if conditional is True)
Expand Down Expand Up @@ -316,7 +311,6 @@ def __init__(
self.conditional = conditional
self.open_pulse = open_pulse
self.memory = memory
self.max_shots = max_shots
self.coupling_map = coupling_map
self.meas_levels = meas_levels
self.meas_kernels = meas_kernels
Expand All @@ -332,9 +326,6 @@ def __init__(
if default_rep_delay is not None:
self.default_rep_delay = default_rep_delay * 1e-6 # convert to sec

# max_experiments must be >=1
if max_experiments:
self.max_experiments = max_experiments
if sample_name is not None:
self.sample_name = sample_name
# n_registers must be >=1
Expand Down Expand Up @@ -426,7 +417,6 @@ def to_dict(self) -> Dict[str, Any]:
"conditional": self.conditional,
"open_pulse": self.open_pulse,
"memory": self.memory,
"max_shots": self.max_shots,
"coupling_map": self.coupling_map,
"dynamic_reprate_enabled": self.dynamic_reprate_enabled,
"meas_levels": self.meas_levels,
Expand All @@ -445,7 +435,6 @@ def to_dict(self) -> Dict[str, Any]:
out_dict["default_rep_delay"] = self.default_rep_delay * 1e6

for kwarg in [
"max_experiments",
"sample_name",
"n_registers",
"register_map",
Expand Down
6 changes: 0 additions & 6 deletions test/integration/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,6 @@ def test_backend_target_refresh(self):
self.assertIsNot(old_properties, backend.properties())
self.assertIsNot(old_defaults, backend.defaults())

def test_backend_max_circuits(self):
"""Check if the max_circuits property is set."""
backend = self.backend
with self.subTest(backend=backend.name):
self.assertIsNotNone(backend.max_circuits)

@production_only
def test_backend_qubit_properties(self):
"""Check if the qubit properties are set."""
Expand Down
24 changes: 0 additions & 24 deletions test/unit/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,30 +234,6 @@ def test_deepcopy(self):
backend_copy = copy.deepcopy(backend)
self.assertEqual(backend_copy.name, backend.name)

def test_too_many_circuits(self):
"""Test exception when number of circuits exceeds backend._max_circuits"""
model_backend = FakeManilaV2()
backend = IBMBackend(
configuration=model_backend.configuration(),
service=mock.MagicMock(),
api_client=None,
instance=None,
)
sampler = SamplerV2(backend)
max_circs = backend.configuration().max_experiments

circs = []
for _ in range(max_circs + 1):
circ = QuantumCircuit(1)
circ.x(0)
circs.append(circ)
with self.assertRaises(ValueError) as err:
sampler.run([circs])
self.assertIn(
f"{max_circs+1}",
str(err.exception),
)

def test_control_flow_converter(self):
"""Test that control flow instructions are properly added to the target."""
backend = FakeSherbrooke()
Expand Down