Skip to content

Commit

Permalink
added optional parameter up_to_global_phase to circuit equality check…
Browse files Browse the repository at this point in the history
…er. closes #143
  • Loading branch information
akissinger committed Jan 15, 2025
1 parent 683b033 commit ac00da0
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions pyzx/circuit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def adjoint(self) -> 'Circuit':
return c


def verify_equality(self, other: 'Circuit', up_to_swaps: bool = False) -> bool:
def verify_equality(self, other: 'Circuit', up_to_swaps: bool = False, up_to_global_phase: bool = True) -> bool:
"""Composes the other circuit with the adjoint of this circuit, and tries to reduce
it to the identity using :func:`simplify.full_reduce``. If successful returns True,
if not returns None.
Expand All @@ -95,10 +95,8 @@ def verify_equality(self, other: 'Circuit', up_to_swaps: bool = False) -> bool:
full_reduce(g)
if (g.num_vertices() == self.qubits*2 and
all(g.edge_type(e) == EdgeType.SIMPLE for e in g.edges())):
if up_to_swaps:
return True
else:
return all(g.connected(v,w) for v,w in zip(g.inputs(),g.outputs()))
return ((up_to_swaps or all(g.connected(v,w) for v,w in zip(g.inputs(),g.outputs()))) and
(up_to_global_phase or g.scalar.phase == 0))
else:
return False

Expand Down

0 comments on commit ac00da0

Please sign in to comment.