Skip to content
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
4 changes: 2 additions & 2 deletions pyzx/ft_simplify.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"""This file is structured the same way as `simplify.py`, but instead contains
simplifications with using only fault-equivalent rewrites"""

from pyzx.rewrite import RewriteSimpSingleVertex
from pyzx.rewrite import RewriteSimpSingleVertex, RewriteSimpDoubleVertex
from pyzx.rewrite_rules.fuse_1_FE_rule import *
from pyzx.rewrite_rules.unfuse_FE_rules import *
from pyzx.rewrite_rules.remove_id_rule import *
Expand All @@ -26,7 +26,7 @@
elim_FE_simp = RewriteSimpSingleVertex(check_remove_id, unsafe_remove_id)
"""Performs an Elim rewrite. Can be run automatically on the entire graph."""

fuse_1_FE_simp = RewriteSimpSingleVertex(check_fuse_1_FE, unsafe_fuse_1_FE)
fuse_1_FE_simp = RewriteSimpDoubleVertex(check_fuse_1_FE, unsafe_fuse_1_FE)
"""Performs a Fuse-1 rewrite. Can be run automatically on the entire graph."""

unfuse_1_FE_simp = RewriteSimpSingleVertex(check_unfuse_1_FE, unsafe_unfuse_1_FE)
Expand Down
20 changes: 13 additions & 7 deletions pyzx/rewrite_rules/fuse_1_FE_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,27 @@
fuse as _fuse,
)
from pyzx.utils import is_pauli, VertexType
from pyzx.rewrite_rules.fuse_rule import check_fuse


def check_fuse_1_FE(g: BaseGraph[VT, ET], v: VT) -> bool:
def check_fuse_1_FE(g: BaseGraph[VT, ET], v: VT, w: VT) -> bool:
neighs = g.neighbors(v)
return len(neighs) == 1 and g.type(neighs[0]) == g.type(v) and is_pauli(g.phase(v))
return len(neighs) == 1 and check_fuse(g, v, w) and is_pauli(g.phase(v))


def fuse_1_FE(g: BaseGraph[VT, ET], v: VT) -> bool:
if not check_fuse_1_FE(g, v):
#def check_fuse_1_FE(g: BaseGraph[VT, ET], v: VT) -> bool:
#neighs = g.neighbors(v)
#return len(neighs) == 1 and g.type(neighs[0]) == g.type(v) and is_pauli(g.phase(v))


def fuse_1_FE(g: BaseGraph[VT, ET], v: VT, w: VT) -> bool:
if not check_fuse_1_FE(g, v, w):
return False
return unsafe_fuse_1_FE(g, v)
return unsafe_fuse_1_FE(g, v, w)


def unsafe_fuse_1_FE(g: BaseGraph[VT, ET], v: VT) -> bool:
if not check_fuse_1_FE(g, v):
def unsafe_fuse_1_FE(g: BaseGraph[VT, ET], v: VT, w: VT) -> bool:
if not check_fuse_1_FE(g, v, w):
return False
[v2] = g.neighbors(v)
return _fuse(g, v, v2)
Expand Down