Skip to content

Commit

Permalink
Merge pull request #220 from wlcsm/add-ocm-step
Browse files Browse the repository at this point in the history
Add OCM step
  • Loading branch information
RazinShaikh committed Jan 25, 2024
2 parents d6fd3d4 + e6cf6c1 commit eb1f41e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
21 changes: 4 additions & 17 deletions zxlive/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,10 @@ class GoToRewriteStep(SetGraph):
def __init__(self, graph_view: GraphView, step_view: QListView, old_step: int, step: int) -> None:
proof_model = step_view.model()
assert isinstance(proof_model, ProofModel)

# Save any vertex rearrangements to the proof step
proof_model.set_graph(old_step, graph_view.graph_scene.g)

SetGraph.__init__(self, graph_view, proof_model.get_graph(step))
self.step_view = step_view
self.step = step
Expand All @@ -445,20 +449,3 @@ def undo(self) -> None:
self.step_view.selectionModel().blockSignals(False)
self.step_view.update(idx)
super().undo()


@dataclass
class MoveNodeInStep(MoveNode):
step_view: QListView

def redo(self) -> None:
super().redo()
model = self.step_view.model()
assert isinstance(model, ProofModel)
model.set_graph(self.step_view.currentIndex().row(), self.g)

def undo(self) -> None:
super().undo()
model = self.step_view.model()
assert isinstance(model, ProofModel)
model.set_graph(self.step_view.currentIndex().row(), self.g)
4 changes: 2 additions & 2 deletions zxlive/proof_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from . import animations as anims
from .base_panel import BasePanel, ToolbarSection
from .commands import AddRewriteStep, GoToRewriteStep, MoveNodeInStep, UndoableChange
from .commands import AddRewriteStep, GoToRewriteStep, MoveNode, UndoableChange
from .common import (ET, VT, GraphT, get_data,
pos_from_view, pos_to_view, colors)
from .dialogs import show_error_msg
Expand Down Expand Up @@ -156,7 +156,7 @@ def parse_selection(self) -> tuple[list[VT], list[ET]]:
return selection, list(edges)

def _vert_moved(self, vs: list[tuple[VT, float, float]]) -> None:
cmd = MoveNodeInStep(self.graph_view, vs, self.step_view)
cmd = MoveNode(self.graph_view, vs)
self.undo_stack.push(cmd)

def _selection_clicked(self) -> None:
Expand Down
15 changes: 14 additions & 1 deletion zxlive/rewrite_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,19 @@ def _extract_circuit(graph: GraphT, matches: list) -> GraphT:
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[ET, VT]:
return ({}, [], [], True)

ocm_action: RewriteData = {
"text": "OCM",
"tooltip": "Saves the graph with the current vertex positions",
"matcher": const_true,
"rule": ocm_rule,
"type": MATCHES_VERTICES,
}

simplifications: dict[str, RewriteData] = {
'bialg_simp': {
"text": "bialgebra simp",
Expand Down Expand Up @@ -239,7 +252,7 @@ def _extract_circuit(graph: GraphT, matches: list) -> GraphT:
rules_zh = {"had2edge", "fuse_hbox", "mult_hbox"}

action_groups = {
"Basic rules": {key: operations[key] for key in rules_basic},
"Basic rules": {'ocm': ocm_action} | {key: operations[key] for key in rules_basic},
"Custom rules": {},
"Graph-like rules": rewrites_graph_theoretic,
"ZXW rules": {key: operations[key] for key in rules_zxw},
Expand Down

0 comments on commit eb1f41e

Please sign in to comment.