Skip to content

Commit

Permalink
Allow retrieving a backend with no instruction filtering (#1938)
Browse files Browse the repository at this point in the history
* allow no filtering

* release note
  • Loading branch information
jyu00 authored Sep 20, 2024
1 parent aba6b2f commit 819808e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
15 changes: 11 additions & 4 deletions qiskit_ibm_runtime/ibm_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,14 +258,21 @@ def _get_defaults(self) -> None:
def _convert_to_target(self, refresh: bool = False) -> None:
"""Converts backend configuration, properties and defaults to Target object"""
if refresh or not self._target:
if self.options.use_fractional_gates is None:
include_control_flow = True
include_fractional_gates = True
else:
# In IBM backend architecture as of today
# these features can be only exclusively supported.
include_control_flow = not self.options.use_fractional_gates
include_fractional_gates = self.options.use_fractional_gates

self._target = convert_to_target(
configuration=self._configuration, # type: ignore[arg-type]
properties=self._properties,
defaults=self._defaults,
# In IBM backend architecture as of today
# these features can be only exclusively supported.
include_control_flow=not self.options.use_fractional_gates,
include_fractional_gates=self.options.use_fractional_gates,
include_control_flow=include_control_flow,
include_fractional_gates=include_fractional_gates,
)

@classmethod
Expand Down
8 changes: 6 additions & 2 deletions qiskit_ibm_runtime/qiskit_runtime_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ def backends(
dynamic_circuits: Optional[bool] = None,
filters: Optional[Callable[["ibm_backend.IBMBackend"], bool]] = None,
*,
use_fractional_gates: bool = False,
use_fractional_gates: Optional[bool] = False,
**kwargs: Any,
) -> List["ibm_backend.IBMBackend"]:
"""Return all backends accessible via this account, subject to optional filtering.
Expand Down Expand Up @@ -517,6 +517,8 @@ def backends(
algorithm, you must disable this flag to create executable ISA circuits.
This flag might be modified or removed when our backend
supports dynamic circuits and fractional gates simultaneously.
If ``None``, then both fractional gates and control flow operations are
included in the backend targets.
**kwargs: Simple filters that require a specific value for an attribute in
backend configuration or status.
Expand Down Expand Up @@ -781,7 +783,7 @@ def backend(
self,
name: str = None,
instance: Optional[str] = None,
use_fractional_gates: bool = False,
use_fractional_gates: Optional[bool] = False,
) -> Backend:
"""Return a single backend matching the specified filtering.
Expand All @@ -800,6 +802,8 @@ def backend(
algorithm, you must disable this flag to create executable ISA circuits.
This flag might be modified or removed when our backend
supports dynamic circuits and fractional gates simultaneously.
If ``None``, then both fractional gates and control flow operations are
included in the backend targets.
Returns:
Backend: A backend matching the filtering.
Expand Down
4 changes: 4 additions & 0 deletions release-notes/unreleased/1938.feat.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
The ``use_fractional_gates`` flag for ``QiskitRuntimeService.backend()`` and
``QiskitRuntimeService.backends()`` can now be ``None``. When set to ``None``,
no instruction filtering is done, and the returned backend target may contain
both fractional gates and control flow operations.
11 changes: 11 additions & 0 deletions test/unit/test_backend_retrieval.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,3 +316,14 @@ def test_backend_with_and_without_fractional_from_same_service(self):
self.assertIn("rx", backend_with_fg.target)

self.assertIsNot(backend_with_fg, backend_without_fg)

def test_get_backend_with_no_instr_filtering(self):
"""Test getting backend with no instruction filtering."""
service = FakeRuntimeService(
channel="ibm_quantum",
token="my_token",
backend_specs=[FakeApiBackendSpecs(backend_name="FakeFractionalBackend")],
)
test_backend = service.backends("fake_fractional", use_fractional_gates=None)[0]
for instr in ["rx", "rzx", "if_else", "while_loop"]:
self.assertIn(instr, test_backend.target)

0 comments on commit 819808e

Please sign in to comment.