Skip to content

Commit

Permalink
shifted auto_simplify methods into base class, since the instance che…
Browse files Browse the repository at this point in the history
…ck wasn't working
  • Loading branch information
akissinger committed Oct 27, 2024
1 parent 163b386 commit d096ea4
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 3,967 deletions.
4 changes: 2 additions & 2 deletions pyzx/gflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
gFlowaux (V,Gamma,In,Out,k) =
begin
C := {}
for all u in V \ Out do
Solve in F2 : Gamma[V \ Out, Out \ In] * I[X] = I[{u}]
for all u in V \\ Out do
Solve in F2 : Gamma[V \\ Out, Out \\ In] * I[X] = I[{u}]
if there is a solution X0 then
C := C union {u}
g(u) := X0
Expand Down
12 changes: 12 additions & 0 deletions pyzx/graph/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -996,3 +996,15 @@ def is_well_formed(self) -> bool:
if self.vertex_degree(v) < 2:
return False
return True

def get_auto_simplify(self) -> bool:
"""Returns whether this graph auto-simplifies parallel edges
For multigraphs, this parameter might change, but simple graphs should always return True."""
return True

def set_auto_simplify(self, s: bool) -> None:
"""Set whether this graph auto-simplifies parallel edges
Simple graphs should always auto-simplify, so this method is a no-op."""
pass
2 changes: 1 addition & 1 deletion pyzx/optimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

"""This module implements several optimization methods on ``Circuit``\ s.
"""This module implements several optimization methods on ``Circuit``\\ s.
The function :func:`basic_optimization` runs a set of back-and-forth gate commutation and cancellation routines.
:func:`phase_block_optimize` does phase polynomial optimization using the TODD algorithm,
and :func:`full_optimize` combines these two methods."""
Expand Down
4 changes: 2 additions & 2 deletions pyzx/simplify.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def simp(
Returns:
Number of iterations of ``rewrite`` that had to be applied before no more matches were found."""

if auto_simplify_parallel_edges and isinstance(g, Multigraph):
if auto_simplify_parallel_edges:
auto_simp_value = g.get_auto_simplify()
g.set_auto_simplify(True)
i = 0
Expand All @@ -110,7 +110,7 @@ def simp(
new_matches = True
if stats is not None: stats.count_rewrites(name, len(m))
if not quiet and i>0: print(' {!s} iterations'.format(i))
if auto_simplify_parallel_edges and isinstance(g, Multigraph):
if auto_simplify_parallel_edges:
g.set_auto_simplify(auto_simp_value)
return i

Expand Down
Loading

0 comments on commit d096ea4

Please sign in to comment.