Skip to content

Commit

Permalink
Fix utils mypy errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Randl committed May 23, 2023
1 parent 08c3612 commit 03fadc0
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 22 deletions.
8 changes: 5 additions & 3 deletions qiskit/utils/deprecation.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import functools
import inspect
import warnings
from typing import Any, Callable, Dict, Optional, Type, Tuple, Union
from typing import Any, Callable, Dict, Optional, Type


def deprecate_func(
Expand Down Expand Up @@ -353,9 +353,11 @@ def _write_deprecation_msg(
pending: bool,
additional_msg: str,
removal_timeline: str,
) -> Tuple[str, Union[Type[DeprecationWarning], Type[PendingDeprecationWarning]]]:
) -> tuple[str, Type[DeprecationWarning] | Type[PendingDeprecationWarning]]:
if pending:
category = PendingDeprecationWarning
category: Type[DeprecationWarning] | Type[
PendingDeprecationWarning
] = PendingDeprecationWarning
deprecation_status = "pending deprecation"
removal_desc = f"marked deprecated in a future release, and then removed {removal_timeline}"
else:
Expand Down
13 changes: 7 additions & 6 deletions qiskit/utils/measurement_error_mitigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
# that they have been altered from the originals.

"""Measurement error mitigation"""
from __future__ import annotations

import copy
from typing import List, Optional, Tuple, Dict, Callable
from typing import List, Optional, Tuple, Dict, Callable, Type, Any

from qiskit import compiler
from qiskit.providers import Backend
Expand Down Expand Up @@ -129,12 +130,12 @@ def get_measured_qubits_from_qobj(qobj: QasmQobj) -> Tuple[List[int], Dict[str,
)
def build_measurement_error_mitigation_circuits(
qubit_list: List[int],
fitter_cls: Callable,
fitter_cls: Type[CompleteMeasFitter] | Type[TensoredMeasFitter],
backend: Backend,
backend_config: Optional[Dict] = None,
compile_config: Optional[Dict] = None,
mit_pattern: Optional[List[List[int]]] = None,
) -> Tuple[QuantumCircuit, List[str], List[str]]:
backend_config: dict[str, Any] | None = None,
compile_config: dict[str, Any] | None = None,
mit_pattern: list[list[int]] | None = None,
) -> Tuple[QuantumCircuit, list[str], list[str]]:
"""Deprecated: Build measurement error mitigation circuits
Args:
qubit_list: list of ordered qubits used in the algorithm
Expand Down
2 changes: 1 addition & 1 deletion qiskit/utils/mitigation/_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
Measurement correction filters.
"""

from __future__ import annotations
from typing import List, Dict, Any
from copy import deepcopy

Expand Down
23 changes: 13 additions & 10 deletions qiskit/utils/mitigation/circuits.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,18 @@
Measurement calibration circuits. To apply the measurement mitigation
use the fitters to produce a filter.
"""
from typing import List, Tuple, Union, Any, Optional, Collection
from __future__ import annotations

from collections.abc import Sequence
from typing import Any
from qiskit.utils.deprecation import deprecate_func


@deprecate_func(
since="0.24.0",
additional_msg="For code migration guidelines, visit https://qisk.it/qi_migration.",
)
def count_keys(num_qubits: int) -> List[str]:
def count_keys(num_qubits: int) -> list[str]:
"""Deprecated: Return ordered count keys.
Args:
Expand All @@ -45,11 +48,11 @@ def count_keys(num_qubits: int) -> List[str]:
additional_msg="For code migration guidelines, visit https://qisk.it/qi_migration.",
)
def complete_meas_cal(
qubit_list: Optional[List[int]] = None,
qr: Optional[Union[int, List[Any]]] = None,
cr: Optional[Union[int, List[Any]]] = None,
qubit_list: Sequence[int] | None = None,
qr: int | list | None = None,
cr: int | list | None = None,
circlabel: str = "",
) -> Tuple[List[Any], List[str]]:
) -> tuple[list, list[str]]:
"""
Deprecated: Return a list of measurement calibration circuits for the full
Hilbert space.
Expand Down Expand Up @@ -126,11 +129,11 @@ def complete_meas_cal(
additional_msg="For code migration guidelines, visit https://qisk.it/qi_migration.",
)
def tensored_meas_cal(
mit_pattern: Optional[List[List[int]]] = None,
qr: Optional[Union[int, Collection[Any]]] = None,
cr: Optional[Union[int, Collection[Any]]] = None,
mit_pattern: list[list[int]] | None = None,
qr: int | Sequence[Any] | None = None,
cr: int | Sequence[Any] | None = None,
circlabel: str = "",
) -> Tuple[List[Any], List[List[int]]]:
) -> tuple[list[Any], list[list[int]]]:
"""
Deprecated: Return a list of calibration circuits
Expand Down
4 changes: 2 additions & 2 deletions qiskit/utils/run_circuits.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# that they have been altered from the originals.

"""run circuits functions"""

from __future__ import annotations
from typing import Optional, Dict, Callable, List, Union, Tuple
import sys
import logging
Expand Down Expand Up @@ -59,7 +59,7 @@ def find_regs_by_name(
"""
found_reg = None
regs = circuit.qregs if qreg else circuit.cregs
regs: list[QuantumRegister] | list[ClassicalRegister] = circuit.qregs if qreg else circuit.cregs
for reg in regs:
if reg.name == name:
found_reg = reg
Expand Down

0 comments on commit 03fadc0

Please sign in to comment.