Skip to content

Commit c216883

Browse files
authored
Handle 0.37 deprecations (#2235)
* handle 0.37 deprecations * add reno
1 parent f3433d4 commit c216883

File tree

6 files changed

+14
-102
lines changed

6 files changed

+14
-102
lines changed

qiskit_ibm_runtime/fake_provider/fake_backend.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -278,20 +278,13 @@ def target(self) -> Target:
278278
return self._target
279279

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

288-
issue_deprecation_msg(
289-
"max_circuits is deprecated",
290-
"0.37.0",
291-
"Please see our documentation on job limits "
292-
"https://quantum.cloud.ibm.com/docs/guides/job-limits#job-limits.",
293-
)
294-
return self.configuration().max_experiments
287+
return None
295288

296289
@classmethod
297290
def _default_options(cls) -> Options:

qiskit_ibm_runtime/ibm_backend.py

Lines changed: 6 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"""Module for interfacing with an IBM Quantum Backend."""
1414

1515
import logging
16-
from typing import Union, Optional, Any, List
16+
from typing import Optional, Any, List
1717
from datetime import datetime as python_datetime
1818
from copy import deepcopy
1919
from packaging.version import Version
@@ -36,7 +36,6 @@
3636
from .api.clients import RuntimeClient
3737
from .exceptions import (
3838
IBMBackendApiProtocolError,
39-
IBMBackendValueError,
4039
IBMBackendError,
4140
)
4241
from .utils.backend_converter import convert_to_target
@@ -94,7 +93,6 @@ class IBMBackend(Backend):
9493
* conditional: backend supports conditional operations.
9594
* open_pulse: backend supports open pulse.
9695
* memory: backend supports memory.
97-
* max_shots: (DEPRECATED) maximum number of shots supported.
9896
* coupling_map (list): The coupling map for the device
9997
* supported_instructions (List[str]): Instructions supported by the backend.
10098
* dynamic_reprate_enabled (bool): whether delay between primitives can be set dynamically
@@ -125,7 +123,6 @@ class IBMBackend(Backend):
125123
[d->u->m] x n_registers. Latency (in units of dt) to do a
126124
conditional operation on channel n from register slot m
127125
* meas_map (list): Grouping of measurement which are multiplexed
128-
* max_circuits (int): (DEPRECATED) The maximum number of experiments per job
129126
* sample_name (str): Sample name for the backend
130127
* n_registers (int): Number of register slots available for feedback
131128
(if conditional is True)
@@ -182,16 +179,13 @@ def __init__(
182179
self._properties: Any = None
183180
self._defaults: Any = None
184181
self._target: Any = None
185-
self._max_circuits = configuration.max_experiments
186182
if (
187183
not self._configuration.simulator
188184
and hasattr(self.options, "noise_model")
189185
and hasattr(self.options, "seed_simulator")
190186
):
191187
self.options.set_validator("noise_model", type(None))
192188
self.options.set_validator("seed_simulator", type(None))
193-
if hasattr(configuration, "max_shots"):
194-
self.options.set_validator("shots", (1, configuration.max_shots))
195189
if hasattr(configuration, "rep_delay_range"):
196190
self.options.set_validator(
197191
"rep_delay",
@@ -210,13 +204,6 @@ def __getattr__(self, name: str) -> Any:
210204
"'{}' object has no attribute '{}'".format(self.__class__.__name__, name)
211205
)
212206

213-
if name in ["max_experiments", "max_shots"]:
214-
issue_deprecation_msg(
215-
f"{name} is deprecated",
216-
"0.37.0",
217-
"Please see our documentation on job limits "
218-
"https://quantum.cloud.ibm.com/docs/guides/job-limits#job-limits.",
219-
)
220207
# Lazy load properties and pulse defaults and construct the target object.
221208
self.properties()
222209
self.defaults()
@@ -282,20 +269,13 @@ def dtm(self) -> float:
282269
return self._configuration.dtm
283270

284271
@property
285-
def max_circuits(self) -> int:
286-
"""(DEPRECATED) The maximum number of circuits
287-
288-
The maximum number of circuits that can be
289-
run in a single job. If there is no limit this will return None.
272+
def max_circuits(self) -> None:
273+
"""This property used to return the `max_experiments` value from the
274+
backend configuration but this value is no longer an accurate representation
275+
of backend circuit limits. New fields will be added to indicate new limits.
290276
"""
291277

292-
issue_deprecation_msg(
293-
"max_circuits is deprecated",
294-
"0.37.0",
295-
"Please see our documentation on job limits "
296-
"https://quantum.cloud.ibm.com/docs/guides/job-limits#job-limits.",
297-
)
298-
return self._max_circuits
278+
return None
299279

300280
@property
301281
def meas_map(self) -> List[List[int]]:
@@ -489,26 +469,6 @@ def __call__(self) -> "IBMBackend":
489469
# For backward compatibility only, can be removed later.
490470
return self
491471

492-
def _check_circuits_attributes(self, circuits: List[Union[QuantumCircuit, str]]) -> None:
493-
"""Check that circuits can be executed on backend.
494-
Raises:
495-
IBMBackendValueError:
496-
- If one of the circuits contains more qubits than on the backend."""
497-
498-
if len(circuits) > self._max_circuits:
499-
raise IBMBackendValueError(
500-
f"Number of circuits, {len(circuits)} exceeds the "
501-
f"maximum for this backend, {self._max_circuits})"
502-
)
503-
for circ in circuits:
504-
if isinstance(circ, QuantumCircuit):
505-
if circ.num_qubits > self._configuration.num_qubits:
506-
raise IBMBackendValueError(
507-
f"Circuit contains {circ.num_qubits} qubits, "
508-
f"but backend has only {self.num_qubits}."
509-
)
510-
self.check_faulty(circ)
511-
512472
def check_faulty(self, circuit: QuantumCircuit) -> None:
513473
"""Check if the input circuit uses faulty qubits or edges.
514474
@@ -557,7 +517,6 @@ def __deepcopy__(self, _memo: dict = None) -> "IBMBackend":
557517
cpy._coupling_map = self._coupling_map
558518
cpy._defaults = deepcopy(self._defaults, _memo)
559519
cpy._target = deepcopy(self._target, _memo)
560-
cpy._max_circuits = self._max_circuits
561520
cpy._options = deepcopy(self._options, _memo)
562521
return cpy
563522

@@ -640,9 +599,7 @@ def from_name(
640599
conditional=False,
641600
open_pulse=False,
642601
memory=False,
643-
max_shots=1,
644602
gates=[GateConfig(name="TODO", parameters=[], qasm_def="TODO")],
645603
coupling_map=[[0, 1]],
646-
max_experiments=300,
647604
)
648605
return cls(configuration, api)

qiskit_ibm_runtime/models/backend_configuration.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,6 @@ class QasmBackendConfiguration:
201201
conditional: backend supports conditional operations.
202202
open_pulse: backend supports open pulse.
203203
memory: backend supports memory.
204-
max_shots: maximum number of shots supported.
205204
"""
206205

207206
_data: Dict[Any, Any] = {}
@@ -218,7 +217,6 @@ def __init__(
218217
conditional: bool,
219218
open_pulse: bool,
220219
memory: bool,
221-
max_shots: int,
222220
coupling_map: list,
223221
meas_levels: List[int] = None,
224222
meas_kernels: List[str] = None,
@@ -228,7 +226,6 @@ def __init__(
228226
dynamic_reprate_enabled: bool = False,
229227
rep_delay_range: List[float] = None,
230228
default_rep_delay: float = None,
231-
max_experiments: int = None,
232229
sample_name: str = None,
233230
n_registers: int = None,
234231
register_map: list = None,
@@ -260,7 +257,6 @@ def __init__(
260257
operations
261258
open_pulse (bool): True if the backend supports OpenPulse
262259
memory (bool): True if the backend supports memory
263-
max_shots (DEPRECATED) (int): The maximum number of shots allowed on the backend
264260
coupling_map (list): The coupling map for the device
265261
meas_levels: Supported measurement levels.
266262
meas_kernels: Supported measurement kernels.
@@ -275,7 +271,6 @@ def __init__(
275271
``dynamic_reprate_enabled=True``.
276272
default_rep_delay (float): Value of ``rep_delay`` if not specified by user and
277273
``dynamic_reprate_enabled=True``.
278-
max_experiments (DEPRECATED) (int): The maximum number of experiments per job
279274
sample_name (str): Sample name for the backend
280275
n_registers (int): Number of register slots available for feedback
281276
(if conditional is True)
@@ -316,7 +311,6 @@ def __init__(
316311
self.conditional = conditional
317312
self.open_pulse = open_pulse
318313
self.memory = memory
319-
self.max_shots = max_shots
320314
self.coupling_map = coupling_map
321315
self.meas_levels = meas_levels
322316
self.meas_kernels = meas_kernels
@@ -332,9 +326,6 @@ def __init__(
332326
if default_rep_delay is not None:
333327
self.default_rep_delay = default_rep_delay * 1e-6 # convert to sec
334328

335-
# max_experiments must be >=1
336-
if max_experiments:
337-
self.max_experiments = max_experiments
338329
if sample_name is not None:
339330
self.sample_name = sample_name
340331
# n_registers must be >=1
@@ -426,7 +417,6 @@ def to_dict(self) -> Dict[str, Any]:
426417
"conditional": self.conditional,
427418
"open_pulse": self.open_pulse,
428419
"memory": self.memory,
429-
"max_shots": self.max_shots,
430420
"coupling_map": self.coupling_map,
431421
"dynamic_reprate_enabled": self.dynamic_reprate_enabled,
432422
"meas_levels": self.meas_levels,
@@ -445,7 +435,6 @@ def to_dict(self) -> Dict[str, Any]:
445435
out_dict["default_rep_delay"] = self.default_rep_delay * 1e6
446436

447437
for kwarg in [
448-
"max_experiments",
449438
"sample_name",
450439
"n_registers",
451440
"register_map",
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
The deprecated :class:`.IBMBackend` attributes ``max_shots`` and
2+
``max_experiments``, have been removed and the :meth:`.IBMBackend.max_circuits` method now
3+
returns ``None``. See the `job limits guide <https://quantum.cloud.ibm.com/docs/guides/job-limits#job-limits>`__ for details.

test/integration/test_backend.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,6 @@ def test_backend_target_refresh(self):
124124
self.assertIsNot(old_properties, backend.properties())
125125
self.assertIsNot(old_defaults, backend.defaults())
126126

127-
def test_backend_max_circuits(self):
128-
"""Check if the max_circuits property is set."""
129-
backend = self.backend
130-
with self.subTest(backend=backend.name):
131-
self.assertIsNotNone(backend.max_circuits)
132-
133127
@production_only
134128
def test_backend_qubit_properties(self):
135129
"""Check if the qubit properties are set."""

test/unit/test_backend.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -234,30 +234,6 @@ def test_deepcopy(self):
234234
backend_copy = copy.deepcopy(backend)
235235
self.assertEqual(backend_copy.name, backend.name)
236236

237-
def test_too_many_circuits(self):
238-
"""Test exception when number of circuits exceeds backend._max_circuits"""
239-
model_backend = FakeManilaV2()
240-
backend = IBMBackend(
241-
configuration=model_backend.configuration(),
242-
service=mock.MagicMock(),
243-
api_client=None,
244-
instance=None,
245-
)
246-
sampler = SamplerV2(backend)
247-
max_circs = backend.configuration().max_experiments
248-
249-
circs = []
250-
for _ in range(max_circs + 1):
251-
circ = QuantumCircuit(1)
252-
circ.x(0)
253-
circs.append(circ)
254-
with self.assertRaises(ValueError) as err:
255-
sampler.run([circs])
256-
self.assertIn(
257-
f"{max_circs+1}",
258-
str(err.exception),
259-
)
260-
261237
def test_control_flow_converter(self):
262238
"""Test that control flow instructions are properly added to the target."""
263239
backend = FakeSherbrooke()

0 commit comments

Comments
 (0)