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

Bug fix in simplify.to_clifford_normal_form_graph #269

Merged
merged 2 commits into from
Aug 28, 2024
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
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
Loading