Skip to content

Commit

Permalink
Fix providers mypy errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Randl committed May 23, 2023
1 parent a1cd15f commit 87f4bc6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
2 changes: 1 addition & 1 deletion qiskit/providers/fake_provider/utils/backend_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from qiskit.providers.models.pulsedefaults import PulseDefaults


def convert_to_target(conf_dict: dict, props_dict: dict = None, defs_dict: dict = None) -> Target:
def convert_to_target(conf_dict: dict, props_dict: dict | None = None, defs_dict: dict | None= None) -> Target:
"""Uses configuration, properties and pulse defaults dicts
to construct and return Target class.
"""
Expand Down
36 changes: 19 additions & 17 deletions qiskit/providers/models/backendproperties.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@

"""Backend Properties classes."""

from __future__ import annotations
import copy
import datetime
from typing import Any, Iterable, Tuple, Union, Dict, List
from collections.abc import Iterable
from typing import Any
import dateutil.parser

from qiskit.providers.exceptions import BackendPropertyError
Expand All @@ -31,7 +33,7 @@ class Nduv:
value: value.
"""

def __init__(self, date, name: str, unit: str, value):
def __init__(self, date: datetime.datetime, name: str, unit: str, value):
"""Initialize a new name-date-unit-value object
Args:
Expand Down Expand Up @@ -94,7 +96,7 @@ class Gate:

_data = {}

def __init__(self, qubits, gate: str, parameters: List[Nduv], **kwargs):
def __init__(self, qubits, gate: str, parameters: list[Nduv], **kwargs):
"""Initialize a new Gate object
Args:
Expand Down Expand Up @@ -168,12 +170,12 @@ class BackendProperties:

def __init__(
self,
backend_name,
backend_version,
last_update_date,
qubits,
gates: List[Gate],
general,
backend_name: str,
backend_version: str,
last_update_date: str | datetime.datetime,
qubits: list[list[Nduv]],
gates: list[Gate],
general: list[Nduv],
**kwargs,
):
"""Initialize a BackendProperties instance.
Expand Down Expand Up @@ -203,13 +205,13 @@ def __init__(

self._qubits = {}
for qubit, props in enumerate(qubits):
formatted_props = {}
formatted_props: dict[str, tuple[float, datetime.datetime]] = {}
for prop in props:
value = self._apply_prefix(prop.value, prop.unit)
formatted_props[prop.name] = (value, prop.date)
self._qubits[qubit] = formatted_props

self._gates: Dict[str, Dict[Tuple, Dict[str, Tuple]]] = {}
self._gates: dict[str, dict[tuple, dict[str, tuple[float, datetime.datetime]]]] = {}
for gate in gates:
if gate.gate not in self._gates:
self._gates[gate.gate] = {}
Expand Down Expand Up @@ -284,8 +286,8 @@ def __eq__(self, other):
return False

def gate_property(
self, gate: str, qubits: Union[int, Iterable[int]] = None, name: str = None
) -> Union[Tuple[Any, datetime.datetime], Dict[str, Tuple]]:
self, gate: str, qubits: int | Iterable[int] = None, name: str = None
) -> tuple[float, datetime.datetime] | dict[str, tuple]:
"""
Return the property of the given gate.
Expand Down Expand Up @@ -331,7 +333,7 @@ def faulty_gates(self):
faulty.append(gate)
return faulty

def is_gate_operational(self, gate: str, qubits: Union[int, Iterable[int]] = None) -> bool:
def is_gate_operational(self, gate: str, qubits: int | Iterable[int] | None = None) -> bool:
"""
Return the operational status of the given gate.
Expand All @@ -348,7 +350,7 @@ def is_gate_operational(self, gate: str, qubits: Union[int, Iterable[int]] = Non
return bool(properties["operational"][0])
return True # if property operational not existent, then True.

def gate_error(self, gate: str, qubits: Union[int, Iterable[int]]) -> float:
def gate_error(self, gate: str, qubits: int | Iterable[int]) -> float:
"""
Return gate error estimates from backend properties.
Expand All @@ -361,7 +363,7 @@ def gate_error(self, gate: str, qubits: Union[int, Iterable[int]]) -> float:
"""
return self.gate_property(gate, qubits, "gate_error")[0] # Throw away datetime at index 1

def gate_length(self, gate: str, qubits: Union[int, Iterable[int]]) -> float:
def gate_length(self, gate: str, qubits: int | Iterable[int]) -> float:
"""
Return the duration of the gate in units of seconds.
Expand All @@ -376,7 +378,7 @@ def gate_length(self, gate: str, qubits: Union[int, Iterable[int]]) -> float:

def qubit_property(
self, qubit: int, name: str = None
) -> Union[Tuple[Any, datetime.datetime], Dict[str, Tuple]]:
) -> tuple[Any, datetime.datetime] | dict[str, tuple]:
"""
Return the property of the given qubit.
Expand Down

0 comments on commit 87f4bc6

Please sign in to comment.