Open rcasjimenez opened 5 months ago
The first thing seems to be a bug, potentially in the is_graph_like
function.
The second one is because removing an identity breaks the graph being graph like. You can see this in your last picture: there is a regular edge between vertices 38 and 48. If you want to make it graph like then you should fuse the spiders again.
I've now changed the default behaviour to is_graph_like
so that it makes sense here. The old behaviour you can get by setting the new parameter strict=True.
Thanks @jvdwetering.
In the first case, the result is now a "graph-like" (strict=False) graph according to the default behavior of the modified function.
In the second case, yes, if I only fuse the spiders again, the resulting graph is 'graph-like', as indicated by the is_graph_like
function.
Taking these results into account:
to_graph_like
function relating to:
- #ensure all I/O are connected to a Z-spider
https://github.com/zxcalc/pyzx/blob/b2bb04738d6d4b25848d52391ef1ca63d1877b9c/pyzx/simplify.py#L463
- #each Z-spider can only be connected to at most 1 I/O
https://github.com/zxcalc/pyzx/blob/b2bb04738d6d4b25848d52391ef1ca63d1877b9c/pyzx/simplify.py#L491 ?It depends on what you want to do with your graph-like diagram. But yes, fusing all spiders is definitely a necessity.
What I would like to do with my graph-type diagram is to be able to apply a set of transformations to a circuit, making sure that I do not modify the functionality/semantics of the graph corresponding to the circuit.
So this is my question, taking into account the new parameter in the function I can apply to a circuit:
Which one should I apply?
My goal is to apply a single transformation to a graph that satisfies the 'graph-like' precondition.
First approach
I tried to apply the following transformations mentioned in #199 (
to_gh
andspider_simp
):Output:
But the graph was not 'graph-like'.
Second approach
My second approach was using specific functions to convert to 'graph-like'.
I converted the 'mod5_4_before' circuit to a graph, and later to a 'graph-like' graph using the 'to_graph_like' function. I have to say that
to_graph_like
function appears in a code block with a note: "#The functions below haven't been updated in a while. Use at your own risk.", although the function appears to implement the requirements necessary for a graph to satisfy the 'graph-like' condition according to 'Hybrid quantum-classical circuit simplification with the ZX-calculus'. (page 6). After this, I applied the transformation 'zx.rules.remove_ids' to the graph of type 'graph-like', and checked the type of graph using the 'is_graph_like' function, this function returnedFalse
-> so, it was not a graph of type 'graph-like'.Output:
As I said at the beginning of this comment, my goal is to apply a transform to a circuit. In this case, I tested the 'zx.rules.remove_ids' transformation, and the result does not seem to be satisfactory.
I am very confused, please: