diff --git a/pytket/binders/circuit/Circuit/main.cpp b/pytket/binders/circuit/Circuit/main.cpp index fbb35358cc..73aa661b37 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,9 +903,17 @@ 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}); + edge_type_str}); } return std::make_tuple( diff --git a/pytket/pytket/_tket/circuit.pyi b/pytket/pytket/_tket/circuit.pyi index b251e48130..95897c44e8 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,EdgeType]]]: ... + 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]]]: ... @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 40a1d9904b..99b3342a39 100644 --- a/pytket/pytket/utils/graph.py +++ b/pytket/pytket/utils/graph.py @@ -20,7 +20,6 @@ import networkx as nx # type: ignore import graphviz as gv # type: ignore -from pytket._tket.circuit import EdgeType from pytket.circuit import Circuit @@ -61,7 +60,9 @@ 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 = defaultdict(list) + self.edge_data: dict[tuple[int, int], list[tuple[int, int, str]]] = 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)) @@ -223,10 +224,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 = { - EdgeType.Quantum: q_color, - EdgeType.Boolean: b_color, - EdgeType.Classical: c_color, - EdgeType.WASM: w_color, + "Quantum": q_color, + "Boolean": b_color, + "Classical": c_color, + "WASM": w_color, } edge_attr = { "weight": "2", diff --git a/pytket/tests/__init__.py b/pytket/tests/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/pytket/tests/assertion_test.py b/pytket/tests/assertion_test.py index ed953df01d..a957dda1d5 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 +from simulator import TketSimShotBackend # type: ignore def test_assertion_init() -> None: diff --git a/pytket/tests/backend_test.py b/pytket/tests/backend_test.py index 387044be4b..ec44b23481 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 -from .simulator import TketSimShotBackend, TketSimBackend +from strategies import outcomearrays, backendresults # type: ignore +from simulator import TketSimShotBackend, TketSimBackend # type: ignore def test_resulthandle() -> None: diff --git a/pytket/tests/backendinfo_test.py b/pytket/tests/backendinfo_test.py index 799f9f5ff1..c44a885651 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 tests.strategies as st +import strategies as st # type: ignore def test_nodes() -> None: diff --git a/pytket/tests/circuit_test.py b/pytket/tests/circuit_test.py index 5c873dc45d..f9a3e1ea00 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 tests.strategies as st -from tests.useful_typedefs import ParamType +import strategies as st # type: ignore +from useful_typedefs import ParamType # type: ignore curr_file_path = Path(__file__).resolve().parent diff --git a/pytket/tests/classical_test.py b/pytket/tests/classical_test.py index 2488b1325a..83c32c8954 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 +from strategies import reg_name_regex, binary_digits, uint32 # type: ignore curr_file_path = Path(__file__).resolve().parent diff --git a/pytket/tests/passes_serialisation_test.py b/pytket/tests/passes_serialisation_test.py index 6da794f2ae..6c0b04b415 100644 --- a/pytket/tests/passes_serialisation_test.py +++ b/pytket/tests/passes_serialisation_test.py @@ -46,7 +46,7 @@ MultiGateReorderRoutingMethod, BoxDecompositionRoutingMethod, ) -from tests.useful_typedefs import ParamType +from useful_typedefs import ParamType # type: ignore 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 7a06537650..d8ce02347e 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 tests.useful_typedefs import ParamType as Param +from useful_typedefs import ParamType as Param # type: ignore circ2 = Circuit(1) diff --git a/pytket/tests/qubitpaulioperator_test.py b/pytket/tests/qubitpaulioperator_test.py index 7dbd7c3e54..86d11e8912 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 tests.strategies as st +import strategies as st # type: ignore def test_QubitPauliOperator_addition() -> None: diff --git a/pytket/tests/transform_test.py b/pytket/tests/transform_test.py index 7d0ef6cd07..0957c438ae 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 +from useful_typedefs import ParamType # type: ignore def get_test_circuit() -> Circuit: diff --git a/pytket/tests/utils_test.py b/pytket/tests/utils_test.py index 86e31a0695..7a45ec1bf7 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 +from simulator import TketSimShotBackend, TketSimBackend # type: ignore def test_append_measurements() -> None: