Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplification does not preserve 'circuit-like-ness' #15

Closed
obtext opened this issue Aug 8, 2019 · 2 comments
Closed

Simplification does not preserve 'circuit-like-ness' #15

obtext opened this issue Aug 8, 2019 · 2 comments

Comments

@obtext
Copy link

obtext commented Aug 8, 2019

This may be related to #10; at least the symptom sounds the same.

Running the sequence of commands in the "Getting Started" document leads (usually) to an error after running Circuit.from_graph after clifford_simp, with the message "Graph doesn't seem circuit like: multiple parents".

A simple example that demonstrates the issue is:

def bad_graph():
    g = zx.Graph()
    g.add_vertices(8)
    g.set_type(2,1)
    g.set_type(3,1)
    g.set_type(4,2)
    g.set_type(5,1)
    g.set_position(0,0,0)
    g.set_position(1,1,0)
    g.set_position(2,0,1)
    g.set_position(3,1,1)
    g.set_position(4,0,2)
    g.set_position(5,1,2)
    g.set_position(6,0,3)
    g.set_position(7,1,3)
    g.add_edges([(0,2),(2,4),(4,6),(1,3),(3,5),(5,7),(4,5)])
    g.inputs.extend([0,1])
    g.outputs.extend([6,7])
    return g

g = bad_graph()
zx.simplify.clifford_simp(g)
Circuit.from_graph(g)

In fact, just doing spider_simp (the first step in clifford_simp) is enough to cause the error.

The problem is that the two green spiders on qubit 1 get merged to a position to the left of the (previously) red spider to which they remain connected.

I am not sure what the actual bug is or even if this is supposed to work -- but in any case the example code is not working.

@jvdwetering
Copy link
Collaborator

jvdwetering commented Aug 8, 2019

Hi, Thanks for the report. Circuit.from_graph does nothing fancy and hence only works if the ZX diagram already looks like a circuit. The line you are referring to in the getting started document: c = zx.Circuit.from_graph(g) is a typo and should have read:
c = zx.Circuit.from_graph(c)
which would have made sense in a previous version of PyZX where the extraction returned a circuit-like graph instead of a Circuit. I've updated the getting started document to reflect the change in PyZX.

@obtext
Copy link
Author

obtext commented Aug 8, 2019

OK, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants