Skip to content

Commit

Permalink
added some missing mypy
Browse files Browse the repository at this point in the history
  • Loading branch information
akissinger committed Aug 24, 2020
1 parent 0642ee3 commit 2fc062d
Show file tree
Hide file tree
Showing 7 changed files with 717 additions and 17 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.mypy_cache
venv
.idea
notebooks/.ipynb_checkpoints
doc/_build
build
Expand Down
2 changes: 1 addition & 1 deletion pyzx/circuit/qasmparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def parse_custom_gate(self, data: str) -> None:
else:
raise TypeError("Custom gate specification doesn't have any "
"arguments: {}".format(data))
registers = {}
registers : Dict[str,Tuple[int,int]] = {}
qubit_count = 0
for a in args.split(","):
a = a.strip()
Expand Down
7 changes: 3 additions & 4 deletions pyzx/hrules.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,19 @@

from fractions import Fraction
from itertools import combinations
from typing import Dict, List, Tuple, Callable, Optional

from typing import Dict, List, Tuple, Callable, Optional, Set
from .utils import EdgeType, VertexType, toggle_edge, FractionLike, FloatInt
from .simplify import *
from .graph.base import BaseGraph, ET, VT
from . import rules


def match_hadamards(g: BaseGraph[VT,ET],
def match_hadamards(g: BaseGraph[VT,ET],
vertexf: Optional[Callable[[VT],bool]] = None
) -> List[VT]:
if vertexf is not None: candidates = set([v for v in g.vertices() if vertexf(v)])
else: candidates = g.vertex_set()
m = set()
m : Set[VT] = set()
ty = g.types()
for v in candidates:
if ty[v] == VertexType.H_BOX and g.vertex_degree(v) == 2 and g.phase(v) == 1:
Expand Down
8 changes: 4 additions & 4 deletions pyzx/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
from fractions import Fraction
from typing import List, Dict, Any

from .utils import FractionLike
from .graph import Graph, EdgeType, VertexType
from .graph.base import BaseGraph, VT, ET
from .simplify import id_simp
from .utils import FractionLike # type: ignore
from .graph import Graph, EdgeType, VertexType # type: ignore
from .graph.base import BaseGraph, VT, ET # type: ignore
from .simplify import id_simp # type: ignore

__all__ = ['json_to_graph', 'graph_to_json', 'to_graphml']

Expand Down
4 changes: 2 additions & 2 deletions pyzx/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ def match_pivot_boundary(
rs = g.rows()

edge_list = []
consumed_vertices = set()
consumed_vertices : Set[VT] = set()
i = 0
m: List[MatchPivotType[VT]] = []
while (num == -1 or i < num) and len(candidates) > 0:
Expand Down Expand Up @@ -638,7 +638,7 @@ def match_ids_parallel(
def remove_ids(g: BaseGraph[VT,ET], matches: List[MatchIdType[VT]]) -> RewriteOutputType[ET,VT]:
"""Given the output of ``match_ids(_parallel)``, returns a list of edges to add,
and vertices to remove."""
etab = dict()
etab : Dict[ET,List[int]] = dict()
rem = []
for v,v0,v1,et in matches:
rem.append(v)
Expand Down
4 changes: 2 additions & 2 deletions pyzx/simulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def sample(self,
if not quiet: print("Estimated original norm:", norm)
if norm < 0.01 and not quiet:
print("Norm very close to zero. Possibly post-selected to zero probability event?")
probs = {}
probs : Dict[str,float] = {}
outputs = []
for i in range(amount):
if not quiet: print("Sample", i)
Expand Down Expand Up @@ -225,7 +225,7 @@ def calculate_path_sum(g: BaseGraph[VT,ET]) -> complex:
if g.num_vertices() < 2: return g.to_tensor().flatten()[0]
phases = g.phases()
prefactor = 0
variable_dict = dict()
variable_dict : Dict[VT,int] = dict()
variables: List[int] = [] # Contains the phases of each of the variables
czs = []
xors = dict()
Expand Down
Loading

0 comments on commit 2fc062d

Please sign in to comment.