From 277f6f1a0172504819d7acfee49fae0df5409967 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elena=20Pe=C3=B1a=20Tapia?= Date: Fri, 8 Dec 2023 10:29:24 +0100 Subject: [PATCH] Fix lint --- .../fake_provider/fake_backend.py | 48 +++++++++++-------- .../fake_provider/fake_provider.py | 3 ++ .../fake_provider/fake_pulse_backend.py | 2 +- .../fake_provider/fake_qasm_backend.py | 4 +- 4 files changed, 35 insertions(+), 22 deletions(-) diff --git a/qiskit_ibm_runtime/fake_provider/fake_backend.py b/qiskit_ibm_runtime/fake_provider/fake_backend.py index 0a5646fcfe..205f226a40 100644 --- a/qiskit_ibm_runtime/fake_provider/fake_backend.py +++ b/qiskit_ibm_runtime/fake_provider/fake_backend.py @@ -117,9 +117,9 @@ def _parse_channels(self, channels): def _setup_sim(self): if _optionals.HAS_AER: - from qiskit.providers import aer + from qiskit_aer import AerSimulator # pylint: disable=import-outside-toplevel - self.sim = aer.AerSimulator() + self.sim = AerSimulator() if self.target and self._props_dict: noise_model = self._get_noise_model_from_backend_v2() self.sim.set_options(noise_model=noise_model) @@ -151,7 +151,9 @@ def _set_defs_dict_from_json(self): self._defs_dict = defs_dict def _load_json(self, filename: str) -> dict: - with open(os.path.join(self.dirname, filename)) as f_json: + with open( # pylint: disable=unspecified-encoding + os.path.join(self.dirname, filename) + ) as f_json: the_json = json.load(f_json) return the_json @@ -199,9 +201,9 @@ def _default_options(cls): default values set """ if _optionals.HAS_AER: - from qiskit.providers import aer + from qiskit_aer import AerSimulator # pylint: disable=import-outside-toplevel - return aer.AerSimulator._default_options() + return AerSimulator._default_options() else: return basicaer.QasmSimulatorPy._default_options() @@ -373,15 +375,19 @@ def _get_noise_model_from_backend_v2( from a BackendV2 object. """ - from qiskit.circuit import Delay - from qiskit.providers.exceptions import BackendPropertyError - from qiskit.providers.aer.noise import NoiseModel - from qiskit.providers.aer.noise.device.models import ( + from qiskit.circuit import Delay # pylint: disable=import-outside-toplevel + from qiskit.providers.exceptions import ( # pylint: disable=import-outside-toplevel + BackendPropertyError, + ) + from qiskit_aer.noise import NoiseModel # pylint: disable=import-outside-toplevel + from qiskit_aer.noise.device.models import ( # pylint: disable=import-outside-toplevel _excited_population, basic_device_gate_errors, basic_device_readout_errors, ) - from qiskit.providers.aer.noise.passes import RelaxationNoisePass + from qiskit_aer.noise.passes import ( # pylint: disable=import-outside-toplevel + RelaxationNoisePass, + ) if self._props_dict is None: self._set_props_dict_from_json() @@ -389,7 +395,7 @@ def _get_noise_model_from_backend_v2( properties = BackendProperties.from_dict(self._props_dict) basis_gates = self.operation_names num_qubits = self.num_qubits - dt = self.dt + dt = self.dt # pylint: disable=invalid-name noise_model = NoiseModel(basis_gates=basis_gates) @@ -402,7 +408,7 @@ def _get_noise_model_from_backend_v2( with warnings.catch_warnings(): warnings.filterwarnings( "ignore", - module="qiskit.providers.aer.noise.device.models", + module="qiskit_aer.noise.device.models", ) gate_errors = basic_device_gate_errors( properties, @@ -458,10 +464,10 @@ def __init__(self, configuration, time_alive=10): def _setup_sim(self): if _optionals.HAS_AER: - from qiskit.providers import aer - from qiskit.providers.aer.noise import NoiseModel + from qiskit_aer import AerSimulator # pylint: disable=import-outside-toplevel + from qiskit_aer.noise import NoiseModel # pylint: disable=import-outside-toplevel - self.sim = aer.AerSimulator() + self.sim = AerSimulator() if self.properties(): noise_model = NoiseModel.from_backend(self) self.sim.set_options(noise_model=noise_model) @@ -526,9 +532,9 @@ def properties(self): @classmethod def _default_options(cls): if _optionals.HAS_AER: - from qiskit.providers import aer + from qiskit_aer import QasmSimulator # pylint: disable=import-outside-toplevel - return aer.QasmSimulator._default_options() + return QasmSimulator._default_options() else: return basicaer.QasmSimulatorPy._default_options() @@ -553,11 +559,13 @@ def run(self, run_input, **kwargs): ) if pulse_job: if _optionals.HAS_AER: - from qiskit.providers import aer - from qiskit.providers.aer.pulse import PulseSystemModel + from qiskit_aer import AerProvider # pylint: disable=import-outside-toplevel + from qiskit.providers.aer.pulse import ( # pylint: disable=import-outside-toplevel + PulseSystemModel, + ) system_model = PulseSystemModel.from_backend(self) - sim = aer.Aer.get_backend("pulse_simulator") + sim = AerProvider().get_backend("pulse_simulator") job = sim.run(circuits, system_model=system_model, **kwargs) else: raise QiskitError("Unable to run pulse schedules without qiskit-aer installed") diff --git a/qiskit_ibm_runtime/fake_provider/fake_provider.py b/qiskit_ibm_runtime/fake_provider/fake_provider.py index 600573e67c..4c3becb49e 100644 --- a/qiskit_ibm_runtime/fake_provider/fake_provider.py +++ b/qiskit_ibm_runtime/fake_provider/fake_provider.py @@ -70,6 +70,9 @@ class FakeProviderForBackendV2(ProviderV1): """ def backend(self, name=None, **kwargs): # type: ignore + """ + Filter backends in provider by name. + """ backend = self._backends[0] if name: filtered_backends = [backend for backend in self._backends if backend.name() == name] diff --git a/qiskit_ibm_runtime/fake_provider/fake_pulse_backend.py b/qiskit_ibm_runtime/fake_provider/fake_pulse_backend.py index 1c3c0a9147..1ca7d5e54e 100644 --- a/qiskit_ibm_runtime/fake_provider/fake_pulse_backend.py +++ b/qiskit_ibm_runtime/fake_provider/fake_pulse_backend.py @@ -17,8 +17,8 @@ from qiskit.exceptions import QiskitError from qiskit.providers.models import PulseBackendConfiguration, PulseDefaults -from .fake_qasm_backend import FakeQasmBackend from qiskit.providers.fake_provider.utils.json_decoder import decode_pulse_defaults +from .fake_qasm_backend import FakeQasmBackend class FakePulseBackend(FakeQasmBackend): diff --git a/qiskit_ibm_runtime/fake_provider/fake_qasm_backend.py b/qiskit_ibm_runtime/fake_provider/fake_qasm_backend.py index 2a83c334d2..11a344e50d 100644 --- a/qiskit_ibm_runtime/fake_provider/fake_qasm_backend.py +++ b/qiskit_ibm_runtime/fake_provider/fake_qasm_backend.py @@ -64,7 +64,9 @@ def _set_props_from_json(self): self._properties = BackendProperties.from_dict(props) def _load_json(self, filename): - with open(os.path.join(self.dirname, filename)) as f_json: + with open( + os.path.join(self.dirname, filename) + ) as f_json: # pylint: disable=unspecified-encoding the_json = json.load(f_json) return the_json