Skip to content

Commit

Permalink
Merge pull request zxcalc#234 from lia-approves/zxlive234
Browse files Browse the repository at this point in the history
fixing issue zxcalc#234 of ZXLive
  • Loading branch information
jvdwetering authored Jul 16, 2024
2 parents 9614c74 + 46ec07a commit d861a13
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
3 changes: 2 additions & 1 deletion pyzx/graph/jsonparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def string_to_phase(string: str, g: Union[BaseGraph,'GraphDiff']) -> Union[Fract
return Fraction(0)
try:
s = string.lower().replace(' ', '')
s = s.replace('*', '')
s = re.sub(r'\\?(pi|\u03c0)', '', s)
if s == '': return Fraction(1)
if s == '-': return Fraction(-1)
Expand All @@ -54,7 +55,7 @@ def string_to_phase(string: str, g: Union[BaseGraph,'GraphDiff']) -> Union[Fract
elif '/' in s:
a, b = s.split("/", 2)
if not a:
return Fraction(1, int(b))
return Fraction(int(1), int(b))
if a == '-':
a = '-1'
return Fraction(int(a), int(b))
Expand Down
10 changes: 6 additions & 4 deletions pyzx/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -854,8 +854,10 @@ def match_phase_gadgets(g: BaseGraph[VT,ET],vertexf:Optional[Callable[[VT],bool]
outputs = g.outputs()
# First we find all the phase-gadgets, and the list of vertices they act on
for v in candidates:
non_clifford = phases[v] != 0 and getattr(phases[v], 'denominator', 1) > 2
if isinstance(phases[v], Poly): non_clifford = True
if isinstance(phases[v], Poly):
non_clifford = True
else:
non_clifford = phases[v] != 0 and getattr(phases[v], 'denominator', 1) > 2
if non_clifford and len(list(g.neighbors(v)))==1:
n = list(g.neighbors(v))[0]
if phases[n] not in (0,1): continue # Not a real phase gadget (happens for scalar diagrams)
Expand Down Expand Up @@ -919,7 +921,7 @@ def match_supplementarity(g: BaseGraph[VT,ET], vertexf:Optional[Callable[[VT],bo
# First we find all the non-Clifford vertices and their list of neighbors
while len(candidates) > 0:
v = candidates.pop()
if phases[v] == 0 or phases[v].denominator <= 2: continue # Skip Clifford vertices
if phases[v] == 0 or (not isinstance(phases[v], Poly) and phases[v].denominator <= 2): continue # Skip Clifford vertices
neigh = set(g.neighbors(v))
if not neigh.isdisjoint(taken): continue
par = frozenset(neigh)
Expand All @@ -935,7 +937,7 @@ def match_supplementarity(g: BaseGraph[VT,ET], vertexf:Optional[Callable[[VT],bo
if v in taken: continue
else: parities[par] = [v]
for w in neigh:
if phases[w] == 0 or phases[w].denominator <= 2 or w in taken: continue
if phases[w] == 0 or (not isinstance(phases[w], Poly) and phases[w].denominator <= 2) or w in taken: continue
diff = neigh.symmetric_difference(g.neighbors(w))
if len(diff) == 2: # Perfect overlap
if (phases[v] + phases[w]) % 2 == 0 or (phases[v] - phases[w]) % 2 == 1:
Expand Down

0 comments on commit d861a13

Please sign in to comment.