Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Commit

Permalink
Raise exception when num circuits exceeds backend max_circuits (#668)
Browse files Browse the repository at this point in the history
* Added check that number of circuits does not exceed max_circuits of backend

* Release note

* Changed error message

* fix lint

---------

Co-authored-by: kevin-tian <kevin.tian@ibm.com>
  • Loading branch information
merav-aharoni and kt474 authored Jul 6, 2023
1 parent 0ad15f8 commit 4af64c2
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
5 changes: 5 additions & 0 deletions qiskit_ibm_provider/ibm_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,11 @@ def _check_circuits_attributes(self, circuits: List[QuantumCircuit]) -> None:
"https://qiskit.org/documentation/tutorials/circuits_advanced/05_pulse_gates.html` "
"on how to use pulse gates."
)
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, Schedule):
raise IBMBackendValueError(schedule_error_msg)
Expand Down
5 changes: 5 additions & 0 deletions releasenotes/notes/max_circuits-066b5eeebfe537a4.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
features:
- |
Raise an exception if the number of circuits passed to IBMBackend.run() exceeds
IBMBackend._max_circuits.
24 changes: 24 additions & 0 deletions test/unit/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from qiskit.providers.models import BackendStatus, BackendProperties

from qiskit_ibm_provider.ibm_backend import IBMBackend
from qiskit_ibm_provider.exceptions import IBMBackendValueError

from ..ibm_test_case import IBMTestCase

Expand Down Expand Up @@ -324,3 +325,26 @@ def test_deepcopy(self):
backend = self._create_dc_test_backend()
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 = FakeManila()
backend = IBMBackend(
configuration=model_backend.configuration(),
provider=mock.MagicMock(),
api_client=None,
instance=None,
)
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(IBMBackendValueError) as err:
backend.run(circs)
self.assertIn(
f"Number of circuits {max_circs+1} exceeds backend._max_circuits",
str(err.exception),
)

0 comments on commit 4af64c2

Please sign in to comment.