Skip to content

Commit

Permalink
Replace _get_defaults() with defaults() (#2019)
Browse files Browse the repository at this point in the history
* Consolidate _get_defaults()

* Fix integration test
  • Loading branch information
kt474 authored Nov 7, 2024
1 parent 1f2d343 commit b80e4a0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 14 deletions.
17 changes: 4 additions & 13 deletions qiskit_ibm_runtime/ibm_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def __getattr__(self, name: str) -> Any:
)
# Lazy load properties and pulse defaults and construct the target object.
self.properties()
self._get_defaults()
self.defaults()
self._convert_to_target()
# Check if the attribute now is available on IBMBackend class due to above steps
try:
Expand All @@ -239,15 +239,6 @@ def __getattr__(self, name: str) -> Any:
"'{}' object has no attribute '{}'".format(self.__class__.__name__, name)
)

def _get_defaults(self, refresh: bool = False) -> None:
"""Gets defaults if pulse backend and decodes it"""
if (
not self._defaults and isinstance(self._configuration, PulseBackendConfiguration)
) or refresh:
api_defaults = self._api_client.backend_pulse_defaults(self.name)
if api_defaults:
self._defaults = defaults_from_server_data(api_defaults)

def _convert_to_target(self, refresh: bool = False) -> None:
"""Converts backend configuration, properties and defaults to Target object"""
if refresh or not self._target:
Expand Down Expand Up @@ -330,7 +321,7 @@ def target(self) -> Target:
Target
"""
self.properties()
self._get_defaults()
self.defaults()
self._convert_to_target()
return self._target

Expand All @@ -340,7 +331,7 @@ def target_history(self, datetime: Optional[python_datetime] = None) -> Target:
Returns:
Target with properties found on `datetime`
"""
self._get_defaults()
self.defaults()

return convert_to_target(
configuration=self._configuration, # type: ignore[arg-type]
Expand All @@ -362,7 +353,7 @@ def refresh(self) -> None:
):
self._configuration = config
self.properties(refresh=True) # pylint: disable=unexpected-keyword-arg
self._get_defaults(refresh=True)
self.defaults(refresh=True)
self._convert_to_target(refresh=True)

def properties(
Expand Down
2 changes: 1 addition & 1 deletion test/integration/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def test_backend_deepcopy(self):
self.assertEqual(
backend_copy._service._backend_allowed_list, backend._service._backend_allowed_list
)
self.assertEqual(backend_copy._get_defaults(), backend._get_defaults())
self.assertEqual(backend_copy.defaults().to_dict(), backend.defaults().to_dict())
self.assertEqual(
backend_copy._api_client._session.base_url,
backend._api_client._session.base_url,
Expand Down

0 comments on commit b80e4a0

Please sign in to comment.