From 6b8ef5f2c6a5ef77cfff691d1e04ffe3475c6779 Mon Sep 17 00:00:00 2001 From: kevin-tian Date: Wed, 2 Oct 2024 12:31:44 -0400 Subject: [PATCH 1/3] Don't cache in target_history() --- qiskit_ibm_runtime/ibm_backend.py | 34 +++++++++++++++++-------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/qiskit_ibm_runtime/ibm_backend.py b/qiskit_ibm_runtime/ibm_backend.py index 73d444f4b..e7bb69a80 100644 --- a/qiskit_ibm_runtime/ibm_backend.py +++ b/qiskit_ibm_runtime/ibm_backend.py @@ -221,7 +221,7 @@ def __getattr__(self, name: str) -> Any: "'{}' object has no attribute '{}'".format(self.__class__.__name__, name) ) # Lazy load properties and pulse defaults and construct the target object. - self._get_properties() + self._properties = self.properties() self._get_defaults() self._convert_to_target() # Check if the attribute now is available on IBMBackend class due to above steps @@ -238,16 +238,6 @@ def __getattr__(self, name: str) -> Any: "'{}' object has no attribute '{}'".format(self.__class__.__name__, name) ) - def _get_properties(self, datetime: Optional[python_datetime] = None) -> None: - """Gets backend properties and decodes it""" - if datetime: - datetime = local_to_utc(datetime) - if datetime or not self._properties: - api_properties = self._api_client.backend_properties(self.name, datetime=datetime) - if api_properties: - backend_properties = properties_from_server_data(api_properties) - self._properties = backend_properties - def _get_defaults(self) -> None: """Gets defaults if pulse backend and decodes it""" if not self._defaults and isinstance(self._configuration, PulseBackendConfiguration): @@ -341,7 +331,7 @@ def target(self) -> Target: Returns: Target """ - self._get_properties() + self._properties = self.properties() self._get_defaults() self._convert_to_target() return self._target @@ -352,10 +342,24 @@ def target_history(self, datetime: Optional[python_datetime] = None) -> Target: Returns: Target with properties found on `datetime` """ - self._get_properties(datetime=datetime) self._get_defaults() - self._convert_to_target(refresh=True) - return 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 + + # Do we want to cache the target here? + return convert_to_target( + configuration=self._configuration, # type: ignore[arg-type] + properties=self.properties(datetime=datetime), # pylint: disable=unexpected-keyword-arg + defaults=self._defaults, + include_control_flow=include_control_flow, + include_fractional_gates=include_fractional_gates, + ) def properties( self, refresh: bool = False, datetime: Optional[python_datetime] = None From e4a798faf1ff40eaa08c735ccc05aeaad0454a5a Mon Sep 17 00:00:00 2001 From: kevin-tian Date: Wed, 2 Oct 2024 12:50:17 -0400 Subject: [PATCH 2/3] Add test --- test/integration/test_backend.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/integration/test_backend.py b/test/integration/test_backend.py index 7fb88c756..0f7f9c445 100644 --- a/test/integration/test_backend.py +++ b/test/integration/test_backend.py @@ -119,6 +119,15 @@ def test_backend_target_history(self): self.assertIsNotNone(backend.target_history()) self.assertIsNotNone(backend.target_history(datetime=datetime.now() - timedelta(30))) + @production_only + def test_properties_not_cached_target_history(self): + """Check backend properties is not cached in target_history().""" + backend = self.backend + with self.subTest(backend=backend.name): + properties = backend.properties() + backend.target_history(datetime=datetime.now() - timedelta(60)) + self.assertEqual(properties, backend.properties()) + def test_backend_max_circuits(self): """Check if the max_circuits property is set.""" backend = self.backend From 2daff61d2e2cc14883d0e16d84f1ebe376dbddcd Mon Sep 17 00:00:00 2001 From: kevin-tian Date: Mon, 14 Oct 2024 15:03:11 -0400 Subject: [PATCH 3/3] Remove comment --- qiskit_ibm_runtime/ibm_backend.py | 1 - 1 file changed, 1 deletion(-) diff --git a/qiskit_ibm_runtime/ibm_backend.py b/qiskit_ibm_runtime/ibm_backend.py index e7bb69a80..7dd264a2e 100644 --- a/qiskit_ibm_runtime/ibm_backend.py +++ b/qiskit_ibm_runtime/ibm_backend.py @@ -352,7 +352,6 @@ def target_history(self, datetime: Optional[python_datetime] = None) -> Target: include_control_flow = not self.options.use_fractional_gates include_fractional_gates = self.options.use_fractional_gates - # Do we want to cache the target here? return convert_to_target( configuration=self._configuration, # type: ignore[arg-type] properties=self.properties(datetime=datetime), # pylint: disable=unexpected-keyword-arg