Skip to content

Commit

Permalink
Merge pull request #269 from rafaelha/master
Browse files Browse the repository at this point in the history
Bug fix in simplify.to_clifford_normal_form_graph
  • Loading branch information
jvdwetering authored Aug 28, 2024
2 parents 81ebc5f + 8cf74db commit 4d2038b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
10 changes: 6 additions & 4 deletions pyzx/simplify.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,9 +546,10 @@ def to_clifford_normal_form_graph(g: BaseGraph[VT,ET]) -> None:
v = v_inputs[q]
i = inputs[q]
e = g.edge(v,i)
if g.edge_type(e) == EdgeType.HADAMARD or g.phase(v) != 0:
e_type = g.edge_type(e)
if e_type == EdgeType.HADAMARD or g.phase(v) != 0:
h = g.add_vertex(VertexType.Z, q, row=1, phase=g.phase(v))
g.add_edge((i,h),EdgeType.HADAMARD)
g.add_edge((i,h),e_type)
g.add_edge((h,v),EdgeType.SIMPLE)
g.remove_edge(e)
g.set_phase(v,0)
Expand All @@ -558,9 +559,10 @@ def to_clifford_normal_form_graph(g: BaseGraph[VT,ET]) -> None:
v = v_outputs[q]
o = outputs[q]
e = g.edge(v,o)
if g.edge_type(e) == EdgeType.HADAMARD or g.phase(v) != 0:
e_type = g.edge_type(e)
if e_type == EdgeType.HADAMARD or g.phase(v) != 0:
h = g.add_vertex(VertexType.Z, q, row=7, phase=g.phase(v))
g.add_edge((h,o),EdgeType.HADAMARD)
g.add_edge((h,o),e_type)
g.add_edge((v,h),EdgeType.SIMPLE)
g.remove_edge(e)
g.set_phase(v,0)
Expand Down
11 changes: 10 additions & 1 deletion tests/test_simplify.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
from fractions import Fraction
from pyzx.generate import cliffordT
from pyzx.simplify import *
from pyzx.simplify import supplementarity_simp
from pyzx.simplify import supplementarity_simp, to_clifford_normal_form_graph
from pyzx import compare_tensors
from pyzx.generate import cliffordT

np: Optional[ModuleType]
try:
Expand Down Expand Up @@ -130,6 +132,13 @@ def test_full_reduce_with_h_box(self):
full_reduce(g)
self.assertTrue("Input graph is not a ZX-diagram" in str(context.exception))

def test_to_clifford_normal_form_graph(self):
for _ in range(10):
g = cliffordT(4, 20, p_t=0)
g0 = g.copy()
to_clifford_normal_form_graph(g)
self.assertTrue(compare_tensors(g0, g, preserve_scalar=True))


qasm_1 = """OPENQASM 2.0;
include "qelib1.inc";
Expand Down

0 comments on commit 4d2038b

Please sign in to comment.