Skip to content

Commit

Permalink
Auto merge parallel edges
Browse files Browse the repository at this point in the history
  • Loading branch information
colltoaction committed Jan 31, 2025
1 parent b80e0b7 commit 362844c
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions zxlive/rewrite_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,24 @@ def read_custom_rules() -> list[RewriteData]:
custom_rules.append(rule)
return custom_rules

const_true = lambda graph, matches: matches


def apply_simplification(simplification: Callable[[GraphT], Optional[int]]) -> Callable[
[GraphT, list], pyzx.rules.RewriteOutputType[VT, ET]]:
def rule(g: GraphT, matches: list) -> pyzx.rules.RewriteOutputType[VT, ET]:
simplification(g)
return ({}, [], [], True)

return rule


def _extract_circuit(graph: GraphT, matches: list) -> GraphT:
graph.auto_detect_io()
simplify.full_reduce(graph)
return cast(GraphT, extract_circuit(graph).to_graph())


# We want additional actions that are not part of the original PyZX editor
# So we add them to operations

Expand All @@ -67,7 +85,7 @@ def read_custom_rules() -> list[RewriteData]:
"text": "pivot",
"tooltip": "Deletes a pair of spiders with 0/pi phases by performing a pivot",
"matcher": lambda g, matchf: pyzx.rules.match_pivot_parallel(g, matchf, check_edge_types=True),
"rule": pyzx.rules.pivot,
"rule": apply_simplification(simplify.pivot_simp),
"type": MATCHES_EDGES,
"copy_first": True,
"picture": "pivot_regular.png"
Expand Down Expand Up @@ -108,24 +126,6 @@ def read_custom_rules() -> list[RewriteData]:
},
}

const_true = lambda graph, matches: matches


def apply_simplification(simplification: Callable[[GraphT], Optional[int]]) -> Callable[
[GraphT, list], pyzx.rules.RewriteOutputType[VT, ET]]:
def rule(g: GraphT, matches: list) -> pyzx.rules.RewriteOutputType[VT, ET]:
simplification(g)
return ({}, [], [], True)

return rule


def _extract_circuit(graph: GraphT, matches: list) -> GraphT:
graph.auto_detect_io()
simplify.full_reduce(graph)
return cast(GraphT, extract_circuit(graph).to_graph())


# The OCM action simply saves the current graph without modifying anything.
# This can be used to make repositioning the vertices an explicit proof step.
def ocm_rule(_graph: GraphT, _matches: list) -> pyzx.rules.RewriteOutputType[VT, ET]:
Expand Down

0 comments on commit 362844c

Please sign in to comment.