From d1cb5c49fdb6577e93c0af33ba9806ce0b9d8fb5 Mon Sep 17 00:00:00 2001 From: Alec Edgington Date: Sat, 2 Sep 2023 16:22:15 +0100 Subject: [PATCH] Revert "Fix errors after stub typing PR (#994)" This reverts commit ca98542133903faaaa2508cd73cc8b3f54a107b0. --- pytket/binders/circuit/Circuit/main.cpp | 12 ++---------- pytket/pytket/_tket/circuit.pyi | 2 +- pytket/pytket/utils/graph.py | 13 ++++++------- pytket/tests/__init__.py | 0 pytket/tests/assertion_test.py | 2 +- pytket/tests/backend_test.py | 4 ++-- pytket/tests/backendinfo_test.py | 2 +- pytket/tests/circuit_test.py | 4 ++-- pytket/tests/classical_test.py | 2 +- pytket/tests/passes_serialisation_test.py | 2 +- pytket/tests/predicates_test.py | 2 +- pytket/tests/qubitpaulioperator_test.py | 2 +- pytket/tests/transform_test.py | 2 +- pytket/tests/utils_test.py | 2 +- 14 files changed, 21 insertions(+), 30 deletions(-) create mode 100644 pytket/tests/__init__.py diff --git a/pytket/binders/circuit/Circuit/main.cpp b/pytket/binders/circuit/Circuit/main.cpp index 73aa661b37..fbb35358cc 100644 --- a/pytket/binders/circuit/Circuit/main.cpp +++ b/pytket/binders/circuit/Circuit/main.cpp @@ -895,7 +895,7 @@ void def_circuit(py::class_> &pyCircuit) { // set of tuples (source node, target node, source port, target // port, edge type) std::set< - std::tuple> + std::tuple> edge_data; BGL_FORALL_EDGES(e, circ.dag, DAG) { Vertex v_so = circ.source(e); @@ -903,17 +903,9 @@ void def_circuit(py::class_> &pyCircuit) { unsigned v_s = im[v_so]; unsigned v_t = im[v_ta]; EdgeType edge_type = circ.dag[e].type; - // This transformation is necessary due to a bug encountered - // with pybind11 on mac0S 11 only, that causes the python sided - // Enum class to take nonsensical values - std::string edge_type_str = - (edge_type == EdgeType::Quantum) ? "Quantum" - : (edge_type == EdgeType::Boolean) ? "Boolean" - : (edge_type == EdgeType::Classical) ? "Classical" - : "WASM"; edge_data.insert( {v_s, v_t, circ.get_source_port(e), circ.get_target_port(e), - edge_type_str}); + edge_type}); } return std::make_tuple( diff --git a/pytket/pytket/_tket/circuit.pyi b/pytket/pytket/_tket/circuit.pyi index 95897c44e8..b251e48130 100644 --- a/pytket/pytket/_tket/circuit.pyi +++ b/pytket/pytket/_tket/circuit.pyi @@ -518,7 +518,7 @@ class Circuit: def __rshift__(self, arg0: Circuit) -> Circuit: ... def __setstate__(self, arg0: tuple) -> None: ... @property - def _dag_data(self) -> Tuple[set[int],set[int],set[int],set[int],set[int],set[int],Dict[int,str],Dict[int,str],Dict[int,str],set[Tuple[int,int,int,int,str]]]: ... + def _dag_data(self) -> Tuple[set[int],set[int],set[int],set[int],set[int],set[int],Dict[int,str],Dict[int,str],Dict[int,str],set[Tuple[int,int,int,int,EdgeType]]]: ... @property def bit_readout(self) -> Dict[pytket._tket.unit_id.Bit,int]: ... @property diff --git a/pytket/pytket/utils/graph.py b/pytket/pytket/utils/graph.py index 99b3342a39..40a1d9904b 100644 --- a/pytket/pytket/utils/graph.py +++ b/pytket/pytket/utils/graph.py @@ -20,6 +20,7 @@ import networkx as nx # type: ignore import graphviz as gv # type: ignore +from pytket._tket.circuit import EdgeType from pytket.circuit import Circuit @@ -60,9 +61,7 @@ def __init__(self, c: Circuit): self.Gnx: Optional[nx.MultiDiGraph] = None self.G: Optional[gv.Digraph] = None self.Gqc: Optional[gv.Graph] = None - self.edge_data: dict[tuple[int, int], list[tuple[int, int, str]]] = defaultdict( - list - ) + self.edge_data = defaultdict(list) self.port_counts: dict = defaultdict(int) for src_node, tgt_node, src_port, tgt_port, edge_type in edge_data: self.edge_data[(src_node, tgt_node)].append((src_port, tgt_port, edge_type)) @@ -224,10 +223,10 @@ def get_DAG(self) -> gv.Digraph: for i in range(n_ports): c.node(name=str((node, i)), xlabel=str(i), **port_node_attr) edge_colors = { - "Quantum": q_color, - "Boolean": b_color, - "Classical": c_color, - "WASM": w_color, + EdgeType.Quantum: q_color, + EdgeType.Boolean: b_color, + EdgeType.Classical: c_color, + EdgeType.WASM: w_color, } edge_attr = { "weight": "2", diff --git a/pytket/tests/__init__.py b/pytket/tests/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/pytket/tests/assertion_test.py b/pytket/tests/assertion_test.py index a957dda1d5..ed953df01d 100644 --- a/pytket/tests/assertion_test.py +++ b/pytket/tests/assertion_test.py @@ -27,7 +27,7 @@ ) from pytket.pauli import PauliStabiliser, Pauli -from simulator import TketSimShotBackend # type: ignore +from .simulator import TketSimShotBackend def test_assertion_init() -> None: diff --git a/pytket/tests/backend_test.py b/pytket/tests/backend_test.py index ec44b23481..387044be4b 100644 --- a/pytket/tests/backend_test.py +++ b/pytket/tests/backend_test.py @@ -34,8 +34,8 @@ from pytket.backends.backend_exceptions import InvalidResultType, CircuitNotRunError from pytket.backends.status import CircuitStatus, StatusEnum -from strategies import outcomearrays, backendresults # type: ignore -from simulator import TketSimShotBackend, TketSimBackend # type: ignore +from .strategies import outcomearrays, backendresults +from .simulator import TketSimShotBackend, TketSimBackend def test_resulthandle() -> None: diff --git a/pytket/tests/backendinfo_test.py b/pytket/tests/backendinfo_test.py index c44a885651..799f9f5ff1 100644 --- a/pytket/tests/backendinfo_test.py +++ b/pytket/tests/backendinfo_test.py @@ -26,7 +26,7 @@ from pytket.architecture import SquareGrid, RingArch, FullyConnected from pytket.circuit import OpType, Node -import strategies as st # type: ignore +import tests.strategies as st def test_nodes() -> None: diff --git a/pytket/tests/circuit_test.py b/pytket/tests/circuit_test.py index f9a3e1ea00..5c873dc45d 100644 --- a/pytket/tests/circuit_test.py +++ b/pytket/tests/circuit_test.py @@ -71,8 +71,8 @@ import pytest # type: ignore from hypothesis import given, settings -import strategies as st # type: ignore -from useful_typedefs import ParamType # type: ignore +import tests.strategies as st +from tests.useful_typedefs import ParamType curr_file_path = Path(__file__).resolve().parent diff --git a/pytket/tests/classical_test.py b/pytket/tests/classical_test.py index 83c32c8954..2488b1325a 100644 --- a/pytket/tests/classical_test.py +++ b/pytket/tests/classical_test.py @@ -68,7 +68,7 @@ from pytket.passes import DecomposeClassicalExp, FlattenRegisters -from strategies import reg_name_regex, binary_digits, uint32 # type: ignore +from .strategies import reg_name_regex, binary_digits, uint32 curr_file_path = Path(__file__).resolve().parent diff --git a/pytket/tests/passes_serialisation_test.py b/pytket/tests/passes_serialisation_test.py index 6c0b04b415..6da794f2ae 100644 --- a/pytket/tests/passes_serialisation_test.py +++ b/pytket/tests/passes_serialisation_test.py @@ -46,7 +46,7 @@ MultiGateReorderRoutingMethod, BoxDecompositionRoutingMethod, ) -from useful_typedefs import ParamType # type: ignore +from tests.useful_typedefs import ParamType def standard_pass_dict(content: Dict[str, Any]) -> Dict[str, Any]: diff --git a/pytket/tests/predicates_test.py b/pytket/tests/predicates_test.py index d8ce02347e..7a06537650 100644 --- a/pytket/tests/predicates_test.py +++ b/pytket/tests/predicates_test.py @@ -86,7 +86,7 @@ from sympy import Symbol from typing import Dict, Any, List, cast -from useful_typedefs import ParamType as Param # type: ignore +from tests.useful_typedefs import ParamType as Param circ2 = Circuit(1) diff --git a/pytket/tests/qubitpaulioperator_test.py b/pytket/tests/qubitpaulioperator_test.py index 86d11e8912..7dbd7c3e54 100644 --- a/pytket/tests/qubitpaulioperator_test.py +++ b/pytket/tests/qubitpaulioperator_test.py @@ -25,7 +25,7 @@ from pytket.pauli import Pauli, QubitPauliString, pauli_string_mult from pytket.circuit import Qubit -import strategies as st # type: ignore +import tests.strategies as st def test_QubitPauliOperator_addition() -> None: diff --git a/pytket/tests/transform_test.py b/pytket/tests/transform_test.py index 0957c438ae..7d0ef6cd07 100644 --- a/pytket/tests/transform_test.py +++ b/pytket/tests/transform_test.py @@ -59,7 +59,7 @@ import json import pytest -from useful_typedefs import ParamType # type: ignore +from .useful_typedefs import ParamType def get_test_circuit() -> Circuit: diff --git a/pytket/tests/utils_test.py b/pytket/tests/utils_test.py index 7a45ec1bf7..86e31a0695 100644 --- a/pytket/tests/utils_test.py +++ b/pytket/tests/utils_test.py @@ -49,7 +49,7 @@ import types from sympy import symbols # type: ignore from typing import Any, Callable, Tuple, Dict, List -from simulator import TketSimShotBackend, TketSimBackend # type: ignore +from .simulator import TketSimShotBackend, TketSimBackend def test_append_measurements() -> None: