From 3015d0f85e80ed84829abf300427540b61ad2a9e Mon Sep 17 00:00:00 2001 From: Jessie Yu Date: Fri, 20 Sep 2024 14:37:20 -0400 Subject: [PATCH 1/2] allow no filtering --- qiskit_ibm_runtime/ibm_backend.py | 15 +++++++++++---- qiskit_ibm_runtime/qiskit_runtime_service.py | 8 ++++++-- test/unit/test_backend_retrieval.py | 11 +++++++++++ 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/qiskit_ibm_runtime/ibm_backend.py b/qiskit_ibm_runtime/ibm_backend.py index f2b66d6e2..73d444f4b 100644 --- a/qiskit_ibm_runtime/ibm_backend.py +++ b/qiskit_ibm_runtime/ibm_backend.py @@ -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 diff --git a/qiskit_ibm_runtime/qiskit_runtime_service.py b/qiskit_ibm_runtime/qiskit_runtime_service.py index 21219e0fb..2f2f33bff 100644 --- a/qiskit_ibm_runtime/qiskit_runtime_service.py +++ b/qiskit_ibm_runtime/qiskit_runtime_service.py @@ -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. @@ -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. @@ -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. @@ -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. diff --git a/test/unit/test_backend_retrieval.py b/test/unit/test_backend_retrieval.py index 4c0d50c91..3521b6895 100644 --- a/test/unit/test_backend_retrieval.py +++ b/test/unit/test_backend_retrieval.py @@ -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) From 7856d577bb876034c9d00e28fae49ded4c9f2a58 Mon Sep 17 00:00:00 2001 From: Jessie Yu Date: Fri, 20 Sep 2024 14:43:53 -0400 Subject: [PATCH 2/2] release note --- release-notes/unreleased/1938.feat.rst | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 release-notes/unreleased/1938.feat.rst diff --git a/release-notes/unreleased/1938.feat.rst b/release-notes/unreleased/1938.feat.rst new file mode 100644 index 000000000..c86bf1f57 --- /dev/null +++ b/release-notes/unreleased/1938.feat.rst @@ -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. \ No newline at end of file