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 e1056ee commit a1cd15f
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 14 deletions.
4 changes: 2 additions & 2 deletions qiskit/providers/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ def operation_names(self) -> List[str]:
"""A list of instruction names that the backend supports."""
return list(self.target.operation_names)

@property
@property # type: ignore
@abstractmethod
def target(self):
"""A :class:`qiskit.transpiler.Target` object for the backend.
Expand All @@ -397,7 +397,7 @@ def instruction_durations(self):
"""Return the :class:`~qiskit.transpiler.InstructionDurations` object."""
return self.target.durations()

@property
@property # type: ignore
@abstractmethod
def max_circuits(self):
"""The maximum number of circuits (or Pulse schedules) that can be
Expand Down
4 changes: 3 additions & 1 deletion qiskit/providers/basicaer/basicaertools.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
"""

from string import ascii_uppercase, ascii_lowercase
from typing import List, Optional
from typing import List, Optional, Type

import numpy as np

import qiskit.circuit.library.standard_gates as gates
from qiskit.circuit import Gate
from qiskit.exceptions import QiskitError

# Single qubit gates supported by ``single_gate_params``.
Expand All @@ -41,6 +42,7 @@ def single_gate_matrix(gate: str, params: Optional[List[float]] = None):
if params is None:
params = []

gc: Type[Gate]
if gate == "U":
gc = gates.UGate
elif gate == "u3":
Expand Down
5 changes: 3 additions & 2 deletions qiskit/providers/fake_provider/utils/backend_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
Utilities for constructing Target object from configuration, properties and
pulse defaults json files
"""
from typing import Dict, List

from qiskit.transpiler.target import Target, InstructionProperties
from qiskit.providers.backend import QubitProperties
Expand Down Expand Up @@ -47,7 +48,7 @@ def convert_to_target(conf_dict: dict, props_dict: dict = None, defs_dict: dict
# Parse from properties if it exsits
if props_dict is not None:
# Parse instructions
gates = {}
gates: Dict[str, Dict] = {}
for gate in props_dict["gates"]:
name = gate["gate"]
if name in name_mapping:
Expand Down Expand Up @@ -132,7 +133,7 @@ def convert_to_target(conf_dict: dict, props_dict: dict = None, defs_dict: dict
return target


def qubit_props_from_props(properties: dict) -> list:
def qubit_props_from_props(properties: dict) -> List[QubitProperties]:
"""Returns a dictionary of `qiskit.providers.backend.QubitProperties` using
a backend properties dictionary created by loading props.json payload.
"""
Expand Down
4 changes: 2 additions & 2 deletions qiskit/providers/models/backendconfiguration.py
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,7 @@ def describe(self, channel: ControlChannel) -> Dict[DriveChannel, complex]:
result[DriveChannel(u_chan_lo.q)] = u_chan_lo.scale
return result

def _parse_channels(self, channels: Dict[set, Any]) -> Dict[Any, Any]:
def _parse_channels(self, channels: Dict[str, Any]) -> Dict[Any, Any]:
r"""
Generates a dictionaries of ``Channel``\s, and tuple of qubit(s) they operate on.
Expand Down Expand Up @@ -987,7 +987,7 @@ def _parse_channels(self, channels: Dict[set, Any]) -> Dict[Any, Any]:
control_channels[qubits].append(channel_type(index))
return dict(qubit_channel_map), dict(channel_qubit_map), dict(control_channels)

def _get_channel_prefix_index(self, channel: str) -> str:
def _get_channel_prefix_index(self, channel: str) -> Tuple[Union[str, Any], int]:
"""Return channel prefix and index from the given ``channel``.
Args:
Expand Down
23 changes: 16 additions & 7 deletions qiskit/providers/models/backendproperties.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import copy
import datetime
from typing import Any, Iterable, Tuple, Union
from typing import Any, Iterable, Tuple, Union, Dict, List
import dateutil.parser

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

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

_data = {}

def __init__(self, qubits, gate, parameters, **kwargs):
def __init__(self, qubits, gate: str, parameters: List[Nduv], **kwargs):
"""Initialize a new Gate object
Args:
Expand Down Expand Up @@ -167,7 +167,14 @@ class BackendProperties:
_data = {}

def __init__(
self, backend_name, backend_version, last_update_date, qubits, gates, general, **kwargs
self,
backend_name,
backend_version,
last_update_date,
qubits,
gates: List[Gate],
general,
**kwargs,
):
"""Initialize a BackendProperties instance.
Expand Down Expand Up @@ -202,7 +209,7 @@ def __init__(
formatted_props[prop.name] = (value, prop.date)
self._qubits[qubit] = formatted_props

self._gates = {}
self._gates: Dict[str, Dict[Tuple, Dict[str, Tuple]]] = {}
for gate in gates:
if gate.gate not in self._gates:
self._gates[gate.gate] = {}
Expand Down Expand Up @@ -278,7 +285,7 @@ def __eq__(self, other):

def gate_property(
self, gate: str, qubits: Union[int, Iterable[int]] = None, name: str = None
) -> Tuple[Any, datetime.datetime]:
) -> Union[Tuple[Any, datetime.datetime], Dict[str, Tuple]]:
"""
Return the property of the given gate.
Expand Down Expand Up @@ -367,7 +374,9 @@ def gate_length(self, gate: str, qubits: Union[int, Iterable[int]]) -> float:
"""
return self.gate_property(gate, qubits, "gate_length")[0] # Throw away datetime at index 1

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

0 comments on commit a1cd15f

Please sign in to comment.