Skip to content

Commit

Permalink
Fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
ElePT committed Dec 8, 2023
1 parent b1fdd85 commit 277f6f1
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 22 deletions.
48 changes: 28 additions & 20 deletions qiskit_ibm_runtime/fake_provider/fake_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -373,23 +375,27 @@ 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()

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)

Expand All @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()

Expand All @@ -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")
Expand Down
3 changes: 3 additions & 0 deletions qiskit_ibm_runtime/fake_provider/fake_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion qiskit_ibm_runtime/fake_provider/fake_pulse_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 3 additions & 1 deletion qiskit_ibm_runtime/fake_provider/fake_qasm_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 277f6f1

Please sign in to comment.