Skip to content

Commit

Permalink
Remove IBMSimulator class
Browse files Browse the repository at this point in the history
IBMBackend class can be used to represent a system or simulator, so that configuration need to not be fetched when instantiating IBMBackend, but lazily on attribute access
  • Loading branch information
rathishcholarajan committed Jan 24, 2022
1 parent a2e3dd4 commit 857c8c0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 28 deletions.
5 changes: 1 addition & 4 deletions qiskit_ibm_runtime/hub_group_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,7 @@ def _discover_remote_backends(self) -> Dict[str, "ibm_backend.IBMBackend"]:
)
if not config:
continue
backend_cls = (
ibm_backend.IBMSimulator if config.simulator else ibm_backend.IBMBackend
)
ret[config.backend_name] = backend_cls(
ret[config.backend_name] = ibm_backend.IBMBackend(
configuration=config,
api_client=self._api_client,
)
Expand Down
28 changes: 9 additions & 19 deletions qiskit_ibm_runtime/ibm_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ def __init__(
self._defaults = None
self._target = None
self._max_circuits = configuration.max_experiments
if not self._configuration.simulator:
self.options.set_validator("noise_model", type(None))
self.options.set_validator("seed_simulator", type(None))

def __getattr__(self, name: str) -> Any:
self._get_properties()
Expand Down Expand Up @@ -153,6 +156,9 @@ def _default_options(cls) -> Options:
rep_delay=None,
init_qubits=True,
use_measure_esp=None,
# Simulator only
noise_model=None,
seed_simulator=None,
)

@property
Expand Down Expand Up @@ -229,12 +235,14 @@ def properties(
NotImplementedError: If `datetime` is specified when cloud rutime is used.
"""
# pylint: disable=arguments-differ
if self._configuration.simulator:
# Simulators do not have backend properties.
return None
if not isinstance(refresh, bool):
raise TypeError(
"The 'refresh' argument needs to be a boolean. "
"{} is of type {}".format(refresh, type(refresh))
)

if datetime:
if not isinstance(datetime, python_datetime):
raise TypeError("'{}' is not of type 'datetime'.")
Expand All @@ -243,7 +251,6 @@ def properties(
"'datetime' is not supported by cloud runtime."
)
datetime = local_to_utc(datetime)

if datetime or refresh or self._properties is None:
api_properties = self._api_client.backend_properties(
self.name, datetime=datetime
Expand Down Expand Up @@ -331,23 +338,6 @@ def run(self, *args: Any, **kwargs: Any) -> None:
)


class IBMSimulator(IBMBackend):
"""Backend class interfacing with an IBM Quantum simulator."""

@classmethod
def _default_options(cls) -> Options:
"""Default runtime options."""
options = super()._default_options()
options.update_options(noise_model=None, seed_simulator=None)
return options

def properties(
self, refresh: bool = False, datetime: Optional[python_datetime] = None
) -> None:
"""Return ``None``, simulators do not have backend properties."""
return None


class IBMRetiredBackend(IBMBackend):
"""Backend class interfacing with an IBM Quantum device no longer available."""

Expand Down
6 changes: 1 addition & 5 deletions qiskit_ibm_runtime/ibm_runtime_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,14 +282,10 @@ def _discover_cloud_backends(self) -> Dict[str, "ibm_backend.IBMBackend"]:
)
if not config:
continue
backend_cls = (
ibm_backend.IBMSimulator if config.simulator else ibm_backend.IBMBackend
)
ret[config.backend_name] = backend_cls(
ret[config.backend_name] = ibm_backend.IBMBackend(
configuration=config,
api_client=self._api_client,
)

return ret

def _authenticate_legacy_account(
Expand Down

0 comments on commit 857c8c0

Please sign in to comment.