Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix errors after stub typing PR #994

Merged
merged 2 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions pytket/binders/circuit/Circuit/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -895,17 +895,25 @@ void def_circuit(py::class_<Circuit, std::shared_ptr<Circuit>> &pyCircuit) {
// set of tuples (source node, target node, source port, target
// port, edge type)
std::set<
std::tuple<unsigned, unsigned, unsigned, unsigned, EdgeType>>
std::tuple<unsigned, unsigned, unsigned, unsigned, std::string>>
edge_data;
BGL_FORALL_EDGES(e, circ.dag, DAG) {
Vertex v_so = circ.source(e);
Vertex v_ta = circ.target(e);
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(
Expand Down
2 changes: 1 addition & 1 deletion pytket/pytket/_tket/circuit.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 7 additions & 6 deletions pytket/pytket/utils/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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",
Expand Down
Empty file removed pytket/tests/__init__.py
Empty file.
2 changes: 1 addition & 1 deletion pytket/tests/assertion_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions pytket/tests/backend_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion pytket/tests/backendinfo_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions pytket/tests/circuit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion pytket/tests/classical_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion pytket/tests/passes_serialisation_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down
2 changes: 1 addition & 1 deletion pytket/tests/predicates_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pytket/tests/qubitpaulioperator_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion pytket/tests/transform_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion pytket/tests/utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading