From 3cd3a77eaeba572560b4cf3bd3d61a29c85bb886 Mon Sep 17 00:00:00 2001 From: Alec Edgington <54802828+cqc-alec@users.noreply.github.com> Date: Fri, 13 Oct 2023 15:33:33 +0100 Subject: [PATCH] Remove unneeded "type: ignore" comments. (#188) --- pytket/extensions/qiskit/backends/config.py | 4 ++-- pytket/extensions/qiskit/backends/ibm.py | 2 +- pytket/extensions/qiskit/qiskit_convert.py | 12 ++++++------ tests/qiskit_convert_test.py | 12 ++++++------ 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/pytket/extensions/qiskit/backends/config.py b/pytket/extensions/qiskit/backends/config.py index 5845445d..f52de41d 100644 --- a/pytket/extensions/qiskit/backends/config.py +++ b/pytket/extensions/qiskit/backends/config.py @@ -45,7 +45,7 @@ def set_ibmq_config( config = QiskitConfig.from_default_config_file() if instance is not None: - config.instance = instance # type: ignore + config.instance = instance if ibmq_api_token is not None: - config.ibmq_api_token = ibmq_api_token # type: ignore + config.ibmq_api_token = ibmq_api_token config.update_default_config_file() diff --git a/pytket/extensions/qiskit/backends/ibm.py b/pytket/extensions/qiskit/backends/ibm.py index f2090074..4d68e90e 100644 --- a/pytket/extensions/qiskit/backends/ibm.py +++ b/pytket/extensions/qiskit/backends/ibm.py @@ -183,7 +183,7 @@ def __init__( super().__init__() self._pytket_config = QiskitConfig.from_default_config_file() self._provider = ( - self._get_provider(instance=instance, qiskit_config=self._pytket_config) # type: ignore + self._get_provider(instance=instance, qiskit_config=self._pytket_config) if provider is None else provider ) diff --git a/pytket/extensions/qiskit/qiskit_convert.py b/pytket/extensions/qiskit/qiskit_convert.py index 14aaade2..b516e11f 100644 --- a/pytket/extensions/qiskit/qiskit_convert.py +++ b/pytket/extensions/qiskit/qiskit_convert.py @@ -394,10 +394,10 @@ def add_qiskit_data(self, data: "QuantumCircuitData") -> None: sub_circ = Circuit(n_base_qubits) # use base gate name for the CircBox (shows in renderer) sub_circ.name = instr.base_gate.name.capitalize() - sub_circ.add_gate(base_tket_gate, params, list(range(n_base_qubits))) # type: ignore + sub_circ.add_gate(base_tket_gate, params, list(range(n_base_qubits))) c_box = CircBox(sub_circ) q_ctrl_box = QControlBox(c_box, instr.num_ctrl_qubits) - self.tkc.add_qcontrolbox(q_ctrl_box, qubits) # type: ignore + self.tkc.add_qcontrolbox(q_ctrl_box, qubits) elif isinstance(instr, (Initialize, StatePreparation)): # Check how Initialize or StatePrep is constructed @@ -421,7 +421,7 @@ def add_qiskit_data(self, data: "QuantumCircuitData") -> None: ) # Need to reverse qubits here (endian-ness) reversed_qubits = list(reversed(qubits)) - self.tkc.add_gate(pytket_state_prep_box, reversed_qubits) # type: ignore + self.tkc.add_gate(pytket_state_prep_box, reversed_qubits) elif isinstance(instr.params[0], complex) and len(instr.params) == 1: # convert int to a binary string and apply X for |1> @@ -437,7 +437,7 @@ def add_qiskit_data(self, data: "QuantumCircuitData") -> None: empty_circ = Circuit(len(qargs)) circ = gen_term_sequence_circuit(qpo, empty_circ) ccbox = CircBox(circ) - self.tkc.add_circbox(ccbox, qubits) # type: ignore + self.tkc.add_circbox(ccbox, qubits) elif type(instr) == UnitaryGate: # Note reversal of qubits, to account for endianness (pytket unitaries # are ILO-BE == DLO-LE; qiskit unitaries are ILO-LE == DLO-BE). @@ -471,7 +471,7 @@ def add_qiskit_data(self, data: "QuantumCircuitData") -> None: ) elif optype == OpType.Barrier: - self.tkc.add_barrier(qubits) # type: ignore + self.tkc.add_barrier(qubits) elif optype in (OpType.CircBox, OpType.CustomGate): qregs = ( [QuantumRegister(instr.num_qubits, "q")] @@ -502,7 +502,7 @@ def add_qiskit_data(self, data: "QuantumCircuitData") -> None: self.tkc.add_gate( optype, [param_to_tk(p) for p in instr.params[:-1]], - qubits, # type: ignore + qubits, **condition_kwargs, ) else: diff --git a/tests/qiskit_convert_test.py b/tests/qiskit_convert_test.py index 5d8d0ec1..c1292ce2 100644 --- a/tests/qiskit_convert_test.py +++ b/tests/qiskit_convert_test.py @@ -731,15 +731,15 @@ def test_parameter_equality() -> None: # https://github.com/CQCL/pytket-extensions/issues/275 def test_convert_multi_c_reg() -> None: c = Circuit() - q0, q1 = c.add_q_register("q", 2) # type: ignore + q0, q1 = c.add_q_register("q", 2) c.add_c_register("c", 2) - [m0] = c.add_c_register("m", 1) # type: ignore - c.add_gate(OpType.X, [], [q1], condition_bits=[m0], condition_value=1) # type: ignore - c.CX(q0, q1) # type: ignore - c.add_gate(OpType.TK1, [0.5, 0.5, 0.5], [q0]) # type: ignore + [m0] = c.add_c_register("m", 1) + c.add_gate(OpType.X, [], [q1], condition_bits=[m0], condition_value=1) + c.CX(q0, q1) + c.add_gate(OpType.TK1, [0.5, 0.5, 0.5], [q0]) qcirc = tk_to_qiskit(c) circ = qiskit_to_tk(qcirc) - assert circ.get_commands()[0].args == [m0, q1] # type: ignore + assert circ.get_commands()[0].args == [m0, q1] # test that tk_to_qiskit works after adding OpType.CRx and OpType.CRy