Skip to content

Commit

Permalink
mypy warn-unused-ignore (#180)
Browse files Browse the repository at this point in the history
* warn-unused-ignore

* fix mypy

* fix format
  • Loading branch information
cqc-melf authored Sep 25, 2023
1 parent de74ab3 commit 02d811b
Show file tree
Hide file tree
Showing 16 changed files with 94 additions and 55 deletions.
2 changes: 1 addition & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace_packages = True
check_untyped_defs = True

warn_redundant_casts = True
warn_unused_ignores = False
warn_unused_ignores = True
warn_no_return = False
warn_return_any = True
warn_unreachable = True
Expand Down
2 changes: 1 addition & 1 deletion pytket/extensions/qiskit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"""Module for conversion between IBM Qiskit and tket primitives."""

# _metadata.py is copied to the folder after installation.
from ._metadata import __extension_version__, __extension_name__ # type: ignore
from ._metadata import __extension_version__, __extension_name__
from .backends import (
IBMQBackend,
NoIBMQCredentialsError,
Expand Down
16 changes: 8 additions & 8 deletions pytket/extensions/qiskit/backends/aer.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@
from qiskit.quantum_info.operators.symplectic.sparse_pauli_op import SparsePauliOp # type: ignore
from qiskit_aer import Aer # type: ignore
from qiskit_aer.library import save_expectation_value # type: ignore # pylint: disable=unused-import
from pytket.architecture import Architecture, FullyConnected # type: ignore
from pytket.architecture import Architecture, FullyConnected
from pytket.backends import Backend, CircuitNotRunError, CircuitStatus, ResultHandle
from pytket.backends.backendinfo import BackendInfo
from pytket.backends.backendresult import BackendResult
from pytket.backends.resulthandle import _ResultIdTuple
from pytket.circuit import Circuit, Node, OpType, Qubit # type: ignore
from pytket.passes import ( # type: ignore
from pytket.circuit import Circuit, Node, OpType, Qubit
from pytket.passes import (
BasePass,
CliffordSimp,
CXMappingPass,
Expand All @@ -52,9 +52,9 @@
auto_rebase_pass,
NaivePlacementPass,
)
from pytket.pauli import Pauli, QubitPauliString # type: ignore
from pytket.placement import NoiseAwarePlacement # type: ignore
from pytket.predicates import ( # type: ignore
from pytket.pauli import Pauli, QubitPauliString
from pytket.placement import NoiseAwarePlacement
from pytket.predicates import (
ConnectivityPredicate,
GateSetPredicate,
NoClassicalControlPredicate,
Expand Down Expand Up @@ -247,10 +247,10 @@ def process_circuits(
if valid_check:
self._check_all_circuits(circuits)

if hasattr(self, "_crosstalk_params") and self._crosstalk_params is not None: # type: ignore
if hasattr(self, "_crosstalk_params") and self._crosstalk_params is not None:
noisy_circuits = []
for c in circuits:
noisy_circ_builder = NoisyCircuitBuilder(c, self._crosstalk_params) # type: ignore
noisy_circ_builder = NoisyCircuitBuilder(c, self._crosstalk_params)
noisy_circ_builder.build()
noisy_circuits.append(noisy_circ_builder.get_circuit())
circuits = noisy_circuits
Expand Down
6 changes: 3 additions & 3 deletions pytket/extensions/qiskit/backends/crosstalk_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import numpy as np
from scipy.linalg import fractional_matrix_power # type: ignore

from pytket.circuit import ( # type: ignore
from pytket.circuit import (
Circuit,
Qubit,
Node,
Expand Down Expand Up @@ -170,9 +170,9 @@ def reset(self) -> None:
@staticmethod
def _get_qubits(inst: Instruction) -> List[Qubit]:
if isinstance(inst, Command):
return inst.qubits # type: ignore
return inst.qubits
else:
return inst.cmd.qubits # type: ignore
return inst.cmd.qubits

def _append(
self,
Expand Down
12 changes: 6 additions & 6 deletions pytket/extensions/qiskit/backends/ibm.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
RuntimeJob,
)

from pytket.circuit import Circuit, OpType # type: ignore
from pytket.circuit import Circuit, OpType
from pytket.backends import Backend, CircuitNotRunError, CircuitStatus, ResultHandle
from pytket.backends.backendinfo import BackendInfo
from pytket.backends.backendresult import BackendResult
Expand All @@ -60,7 +60,7 @@
get_avg_characterisation,
)
from pytket.extensions.qiskit._metadata import __extension_version__
from pytket.passes import ( # type: ignore
from pytket.passes import (
BasePass,
auto_rebase_pass,
KAKDecomposition,
Expand All @@ -74,7 +74,7 @@
SimplifyInitial,
NaivePlacementPass,
)
from pytket.predicates import ( # type: ignore
from pytket.predicates import (
NoMidMeasurePredicate,
NoSymbolsPredicate,
GateSetPredicate,
Expand All @@ -84,8 +84,8 @@
Predicate,
)
from pytket.extensions.qiskit.qiskit_convert import tk_to_qiskit, _tk_gate_set
from pytket.architecture import FullyConnected # type: ignore
from pytket.placement import NoiseAwarePlacement # type: ignore
from pytket.architecture import FullyConnected
from pytket.placement import NoiseAwarePlacement
from pytket.utils import prepare_circuit
from pytket.utils.outcomearray import OutcomeArray
from pytket.utils.results import KwargTypes
Expand Down Expand Up @@ -187,7 +187,7 @@ def __init__(
if provider is None
else provider
)
self._backend: "_QiskIBMBackend" = self._provider.get_backend(backend_name) # type: ignore
self._backend: "_QiskIBMBackend" = self._provider.get_backend(backend_name)
config = self._backend.configuration()
self._max_per_job = getattr(config, "max_experiments", 1)

Expand Down
2 changes: 1 addition & 1 deletion pytket/extensions/qiskit/backends/ibm_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from pytket.backends.status import StatusEnum

if TYPE_CHECKING:
from pytket.circuit import Circuit # type: ignore
from pytket.circuit import Circuit

_STATUS_MAP = {
JobStatus.CANCELLED: StatusEnum.CANCELLED,
Expand Down
6 changes: 3 additions & 3 deletions pytket/extensions/qiskit/backends/ibmq_emulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@
from pytket.backends.backendinfo import BackendInfo
from pytket.backends.backendresult import BackendResult
from pytket.backends.resulthandle import _ResultIdTuple
from pytket.circuit import Bit, Circuit, OpType # type: ignore
from pytket.circuit import Bit, Circuit, OpType
from pytket.extensions.qiskit.qiskit_convert import tk_to_qiskit
from pytket.passes import BasePass # type: ignore
from pytket.predicates import Predicate # type: ignore
from pytket.passes import BasePass
from pytket.predicates import Predicate
from pytket.utils import prepare_circuit
from pytket.utils.outcomearray import OutcomeArray
from pytket.utils.results import KwargTypes
Expand Down
16 changes: 8 additions & 8 deletions pytket/extensions/qiskit/qiskit_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

import numpy as np

import sympy # type: ignore
import sympy
import qiskit.circuit.library.standard_gates as qiskit_gates # type: ignore
from qiskit import (
ClassicalRegister,
Expand All @@ -53,11 +53,11 @@
ParameterExpression,
Reset,
)
from qiskit.circuit.library import CRYGate, RYGate, PauliEvolutionGate, StatePreparation # type: ignore
from qiskit.circuit.library import CRYGate, RYGate, PauliEvolutionGate, StatePreparation

from qiskit.extensions.unitary import UnitaryGate # type: ignore
from qiskit.extensions import Initialize # type: ignore
from pytket.circuit import ( # type: ignore
from pytket.circuit import (
CircBox,
Circuit,
Node,
Expand All @@ -73,12 +73,12 @@
QControlBox,
StatePreparationBox,
)
from pytket.unit_id import _TEMP_BIT_NAME # type: ignore
from pytket.pauli import Pauli, QubitPauliString # type: ignore
from pytket.architecture import Architecture, FullyConnected # type: ignore
from pytket.unit_id import _TEMP_BIT_NAME
from pytket.pauli import Pauli, QubitPauliString
from pytket.architecture import Architecture, FullyConnected
from pytket.utils import QubitPauliOperator, gen_term_sequence_circuit

from pytket.passes import RebaseCustom # type: ignore
from pytket.passes import RebaseCustom

if TYPE_CHECKING:
from qiskit.providers.backend import BackendV1 as QiskitBackend # type: ignore
Expand All @@ -87,7 +87,7 @@
Nduv,
)
from qiskit.circuit.quantumcircuitdata import QuantumCircuitData # type: ignore
from pytket.circuit import Op, UnitID # type: ignore
from pytket.circuit import Op, UnitID

_qiskit_gates_1q = {
# Exact equivalents (same signature except for factor of pi in each parameter):
Expand Down
19 changes: 17 additions & 2 deletions pytket/extensions/qiskit/result_convert.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
# Copyright 2019-2023 Cambridge Quantum Computing
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


from typing import (
List,
Iterator,
Expand All @@ -15,7 +30,7 @@
from qiskit.result import Result # type: ignore
from qiskit.result.models import ExperimentResult # type: ignore

from pytket.circuit import Bit, Qubit, UnitID, Circuit # type: ignore
from pytket.circuit import Bit, Qubit, UnitID, Circuit

from pytket.backends.backendresult import BackendResult
from pytket.utils.outcomearray import OutcomeArray
Expand Down Expand Up @@ -97,7 +112,7 @@ def qiskit_experimentresult_to_backendresult(
if _result_is_empty_shots(result):
n_bits = len(c_bits) if c_bits else 0
shots = OutcomeArray.from_readouts(
np.zeros((result.shots, n_bits), dtype=np.uint8) # type: ignore
np.zeros((result.shots, n_bits), dtype=np.uint8)
)
else:
if "memory" in datadict:
Expand Down
6 changes: 3 additions & 3 deletions pytket/extensions/qiskit/tket_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
from pytket.extensions.qiskit.qiskit_convert import qiskit_to_tk, _gate_str_2_optype_rev
from pytket.extensions.qiskit.tket_job import TketJob, JobInfo
from pytket.backends import Backend
from pytket.passes import BasePass # type: ignore
from pytket.predicates import ( # type: ignore
from pytket.passes import BasePass
from pytket.predicates import (
NoClassicalControlPredicate,
GateSetPredicate,
CompilationUnit,
)
from pytket.architecture import FullyConnected # type: ignore
from pytket.architecture import FullyConnected


def _extract_basis_gates(backend: Backend) -> List[str]:
Expand Down
2 changes: 1 addition & 1 deletion pytket/extensions/qiskit/tket_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from qiskit.result import Result # type: ignore
from pytket.backends import ResultHandle, StatusEnum
from pytket.backends.backend import Backend, KwargTypes
from pytket.circuit import UnitID, Qubit, Bit # type: ignore
from pytket.circuit import UnitID, Qubit, Bit
from pytket.extensions.qiskit.result_convert import (
backendresult_to_qiskit_resultdata,
_get_header_info,
Expand Down
2 changes: 1 addition & 1 deletion pytket/extensions/qiskit/tket_pass.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from qiskit_ibm_provider import IBMProvider # type: ignore


from pytket.passes import BasePass # type: ignore
from pytket.passes import BasePass
from pytket.extensions.qiskit import (
IBMQBackend,
AerBackend,
Expand Down
23 changes: 16 additions & 7 deletions tests/backend_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,22 @@
from qiskit_aer import Aer # type: ignore
from qiskit_ibm_provider.exceptions import IBMError # type: ignore

from pytket.circuit import Circuit, OpType, BasisOrder, Qubit, reg_eq, Unitary2qBox, QControlBox, CircBox # type: ignore
from pytket.passes import CliffordSimp # type: ignore
from pytket.pauli import Pauli, QubitPauliString # type: ignore
from pytket.predicates import CompilationUnit, NoMidMeasurePredicate # type: ignore
from pytket.architecture import Architecture # type: ignore
from pytket.mapping import MappingManager, LexiLabellingMethod, LexiRouteRoutingMethod # type: ignore
from pytket.transform import Transform # type: ignore
from pytket.circuit import (
Circuit,
OpType,
BasisOrder,
Qubit,
reg_eq,
Unitary2qBox,
QControlBox,
CircBox,
)
from pytket.passes import CliffordSimp
from pytket.pauli import Pauli, QubitPauliString
from pytket.predicates import CompilationUnit, NoMidMeasurePredicate
from pytket.architecture import Architecture
from pytket.mapping import MappingManager, LexiLabellingMethod, LexiRouteRoutingMethod
from pytket.transform import Transform
from pytket.backends import (
ResultHandle,
CircuitNotRunError,
Expand Down
23 changes: 19 additions & 4 deletions tests/mock_pytket_backend.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
# Copyright 2019-2023 Cambridge Quantum Computing
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


from typing import Optional, Union, List, Sequence, Set, cast
import json

from pytket.circuit import Circuit, OpType # type: ignore
from pytket.circuit import Circuit, OpType
from pytket.backends import Backend, CircuitStatus, ResultHandle, StatusEnum
from pytket.backends.backendinfo import BackendInfo
from pytket.architecture import Architecture, FullyConnected # type: ignore
from pytket.predicates import Predicate, GateSetPredicate # type: ignore
from pytket.passes import BasePass, CustomPass # type: ignore
from pytket.architecture import Architecture, FullyConnected
from pytket.predicates import Predicate, GateSetPredicate
from pytket.passes import BasePass, CustomPass
from pytket.backends.resulthandle import _ResultIdTuple
from pytket.backends.backendresult import BackendResult
from pytket.backends.backend import KwargTypes, ResultCache
Expand Down
4 changes: 2 additions & 2 deletions tests/qiskit_backend_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
IBMQEmulatorBackend,
)
from pytket.extensions.qiskit.tket_backend import TketBackend
from pytket.circuit import OpType # type: ignore
from pytket.architecture import Architecture, FullyConnected # type: ignore
from pytket.circuit import OpType
from pytket.architecture import Architecture, FullyConnected

from .mock_pytket_backend import MockShotBackend

Expand Down
8 changes: 4 additions & 4 deletions tests/qiskit_convert_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from typing import List, Set, Union
from math import pi
import pytest
from sympy import Symbol # type: ignore
from sympy import Symbol
import numpy as np
from qiskit import ( # type: ignore
QuantumCircuit,
Expand All @@ -30,12 +30,12 @@
from qiskit.transpiler import PassManager # type: ignore
from qiskit.circuit.library import RYGate, MCMT, XXPlusYYGate # type: ignore
import qiskit.circuit.library.standard_gates as qiskit_gates # type: ignore
from qiskit.circuit import Parameter # type: ignore
from qiskit.circuit import Parameter
from qiskit_aer import Aer # type: ignore
from qiskit.quantum_info import Statevector
from qiskit.extensions import UnitaryGate # type: ignore

from pytket.circuit import ( # type: ignore
from pytket.circuit import (
Circuit,
CircBox,
Unitary1qBox,
Expand All @@ -52,7 +52,7 @@
from pytket.extensions.qiskit.qiskit_convert import _gate_str_2_optype
from pytket.extensions.qiskit.tket_pass import TketPass, TketAutoPass
from pytket.extensions.qiskit.result_convert import qiskit_result_to_backendresult
from pytket.passes import RebaseTket, DecomposeBoxes, FullPeepholeOptimise, SequencePass # type: ignore
from pytket.passes import RebaseTket, DecomposeBoxes, FullPeepholeOptimise, SequencePass
from pytket.utils.results import (
compare_statevectors,
permute_rows_cols_in_unitary,
Expand Down

0 comments on commit 02d811b

Please sign in to comment.