diff --git a/mypy.ini b/mypy.ini index 1dfad53a..ad4e6a06 100644 --- a/mypy.ini +++ b/mypy.ini @@ -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 diff --git a/pytket/extensions/qiskit/__init__.py b/pytket/extensions/qiskit/__init__.py index 30ab234b..4f7dc6dd 100644 --- a/pytket/extensions/qiskit/__init__.py +++ b/pytket/extensions/qiskit/__init__.py @@ -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, diff --git a/pytket/extensions/qiskit/backends/aer.py b/pytket/extensions/qiskit/backends/aer.py index 26fc3ff9..cf037c6c 100644 --- a/pytket/extensions/qiskit/backends/aer.py +++ b/pytket/extensions/qiskit/backends/aer.py @@ -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, @@ -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, @@ -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 diff --git a/pytket/extensions/qiskit/backends/crosstalk_model.py b/pytket/extensions/qiskit/backends/crosstalk_model.py index b9736fe1..8576928f 100644 --- a/pytket/extensions/qiskit/backends/crosstalk_model.py +++ b/pytket/extensions/qiskit/backends/crosstalk_model.py @@ -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, @@ -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, diff --git a/pytket/extensions/qiskit/backends/ibm.py b/pytket/extensions/qiskit/backends/ibm.py index 3bfc0149..5db91cd0 100644 --- a/pytket/extensions/qiskit/backends/ibm.py +++ b/pytket/extensions/qiskit/backends/ibm.py @@ -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 @@ -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, @@ -74,7 +74,7 @@ SimplifyInitial, NaivePlacementPass, ) -from pytket.predicates import ( # type: ignore +from pytket.predicates import ( NoMidMeasurePredicate, NoSymbolsPredicate, GateSetPredicate, @@ -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 @@ -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) diff --git a/pytket/extensions/qiskit/backends/ibm_utils.py b/pytket/extensions/qiskit/backends/ibm_utils.py index 2bb07507..876274fe 100644 --- a/pytket/extensions/qiskit/backends/ibm_utils.py +++ b/pytket/extensions/qiskit/backends/ibm_utils.py @@ -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, diff --git a/pytket/extensions/qiskit/backends/ibmq_emulator.py b/pytket/extensions/qiskit/backends/ibmq_emulator.py index 9ad272ce..490e92f0 100644 --- a/pytket/extensions/qiskit/backends/ibmq_emulator.py +++ b/pytket/extensions/qiskit/backends/ibmq_emulator.py @@ -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 diff --git a/pytket/extensions/qiskit/qiskit_convert.py b/pytket/extensions/qiskit/qiskit_convert.py index 3aee56dc..14aaade2 100644 --- a/pytket/extensions/qiskit/qiskit_convert.py +++ b/pytket/extensions/qiskit/qiskit_convert.py @@ -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, @@ -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, @@ -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 @@ -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): diff --git a/pytket/extensions/qiskit/result_convert.py b/pytket/extensions/qiskit/result_convert.py index 6fc880e8..95dfc2a2 100644 --- a/pytket/extensions/qiskit/result_convert.py +++ b/pytket/extensions/qiskit/result_convert.py @@ -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, @@ -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 @@ -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: diff --git a/pytket/extensions/qiskit/tket_backend.py b/pytket/extensions/qiskit/tket_backend.py index c3bd62e5..80cd3df3 100644 --- a/pytket/extensions/qiskit/tket_backend.py +++ b/pytket/extensions/qiskit/tket_backend.py @@ -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]: diff --git a/pytket/extensions/qiskit/tket_job.py b/pytket/extensions/qiskit/tket_job.py index 8ed2f148..55d65a10 100644 --- a/pytket/extensions/qiskit/tket_job.py +++ b/pytket/extensions/qiskit/tket_job.py @@ -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, diff --git a/pytket/extensions/qiskit/tket_pass.py b/pytket/extensions/qiskit/tket_pass.py index 9e396e74..adb3b276 100644 --- a/pytket/extensions/qiskit/tket_pass.py +++ b/pytket/extensions/qiskit/tket_pass.py @@ -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, diff --git a/tests/backend_test.py b/tests/backend_test.py index f7c6b886..0b8b68f9 100644 --- a/tests/backend_test.py +++ b/tests/backend_test.py @@ -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, diff --git a/tests/mock_pytket_backend.py b/tests/mock_pytket_backend.py index bd2f0f47..3b304ced 100644 --- a/tests/mock_pytket_backend.py +++ b/tests/mock_pytket_backend.py @@ -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 diff --git a/tests/qiskit_backend_test.py b/tests/qiskit_backend_test.py index 61d5dc0d..0b5ef291 100644 --- a/tests/qiskit_backend_test.py +++ b/tests/qiskit_backend_test.py @@ -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 diff --git a/tests/qiskit_convert_test.py b/tests/qiskit_convert_test.py index 32632171..b3fe984a 100644 --- a/tests/qiskit_convert_test.py +++ b/tests/qiskit_convert_test.py @@ -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, @@ -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, @@ -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,