zxcalc/pyzx

Composing graphs loses grounds?

Closed this issue · 1 comments

To represent a one-qubit Z-measurement, I create a green phaseless spider with one input / one output and set it as a ground. At first glance, PyZX can handle this just fine:

c=zx.Circuit(1)
c.add_gate("ZPhase",0,phase=0)
g=c.to_graph()
g.set_ground(1)
zx.draw(g)
measurement

However, if I compose this graph with itself (zx.draw(g*g) then the second spider is no longer a ground:

measurement2

I've verified this as well for larger examples where the two graphs are different:

q=5;

c1=zx.Circuit(q)
for i in range(0,q-1,2):
    c1.add_gate("CNOT",i,i+1)
g1=c1.to_graph()
g1.auto_detect_io()

g2=zx.generate.identity(q)
for i in range(q):
    g2.set_type(2*i+1,1)
    g2.set_ground(2*i+1)
    v = g2.add_vertex(qubit=i,row=2)
    g2.add_edge(g2.edge(v,2*i+1),edgetype=zx.EdgeType.SIMPLE)
g2.auto_detect_io()
bad grounds

Can you try #178 ? That should fix it.