From ff12e2ceb379bc4c5d9c43012eda380a501dbba9 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Wed, 16 Oct 2024 11:49:56 +0100 Subject: [PATCH] added basic_simp function --- pyzx/simplify.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pyzx/simplify.py b/pyzx/simplify.py index e25b45aa..dd7e7978 100644 --- a/pyzx/simplify.py +++ b/pyzx/simplify.py @@ -144,6 +144,19 @@ def phase_free_simp(g: BaseGraph[VT,ET], quiet:bool=False, stats:Optional[Stats] i2 = bialg_simp(g, quiet=quiet, stats=stats) return i1+i2 +def basic_simp(g: BaseGraph[VT,ET], matchf: Optional[Callable[[Union[VT, ET]],bool]]=None, quiet:bool=False, stats:Optional[Stats]=None) -> int: + """Keeps doing the simplifications ``id_simp`` and ``spider_simp`` until none of them can be applied anymore. If + starting from a circuit, the result should still have causal flow.""" + spider_simp(g, matchf=matchf, quiet=quiet, stats=stats) + to_gh(g) + i = 0 + while True: + i1 = id_simp(g, matchf=matchf, quiet=quiet, stats=stats) + i2 = spider_simp(g, matchf=matchf, quiet=quiet, stats=stats) + if i1+i2==0: break + i += 1 + return i + def interior_clifford_simp(g: BaseGraph[VT,ET], matchf: Optional[Callable[[Union[VT, ET]],bool]]=None, quiet:bool=False, stats:Optional[Stats]=None) -> int: """Keeps doing the simplifications ``id_simp``, ``spider_simp``, ``pivot_simp`` and ``lcomp_simp`` until none of them can be applied anymore."""