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

fix: gadget fusion #40

Merged
merged 3 commits into from
May 23, 2024
Merged

fix: gadget fusion #40

merged 3 commits into from
May 23, 2024

Conversation

y-richie-y
Copy link
Contributor

@y-richie-y y-richie-y commented May 20, 2024

Gadget fusion doesn't seem to work as it deletes all of the phase gadgets before trying to update the phase of the first gadget. The bug disappears when we leave the first phase gadget undeleted.

import pyzx as zx

def to_quizx(p_g):
    r_g = zx.Graph(backend='quizx-vec')
    v_map = dict()
    for v in p_g.vertices():
        new_v = r_g.add_vertex(ty=p_g.type(v), qubit=p_g.qubit(v), row=p_g.row(v), phase=p_g.phase(v))
        v_map[v] = new_v

    for e in p_g.edges():
        new_e = (v_map[e[0]], v_map[e[1]])
        r_g.add_edge(new_e, p_g.edge_type(e))
    return r_g

c = zx.Circuit(2)
c.add_gate("ZPhase", 0, 0.25)
c.add_gate("CNOT", 1, 0)
c.add_gate("ZPhase", 0, 0.25)
c.add_gate("CNOT", 1, 0)
c.add_gate("ZPhase", 0, 0.25)
c.add_gate("ZPhase", 1, 0.25)

g = c.to_graph()
g.apply_state('++')
g.apply_effect('++')

zx.draw(g, labels=True)
zx.clifford_simp(g)
zx.draw(g, labels=True)

r_g = to_quizx(g)

qzx.simplify.full_simp(r_g)
image
---------------------------------------------------------------------------
PanicException                            Traceback (most recent call last)
Cell In[6], line 33
     29 zx.draw(g, labels=True)
     31 r_g = to_quizx(g)
---> 33 qzx.simplify.full_simp(r_g)
     34 zx.draw(r_g, labels=True)

File ~/Documents/work/quizx/pybindings/quizx/simplify.py:13, in full_simp(g)
     12 def full_simp(g):
---> 13     _quizx.full_simp(g._g)

PanicException: Vertex not found 2

@ABorgna
Copy link
Collaborator

ABorgna commented May 21, 2024

Thanks for the fix!

Would you mind adding a unit tests for this?
I'll do it latter otherwise

@y-richie-y
Copy link
Contributor Author

Done!

Copy link
Collaborator

@ABorgna ABorgna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome. Thank you!

@ABorgna ABorgna merged commit e8ef605 into zxcalc:master May 23, 2024
9 checks passed
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

Successfully merging this pull request may close these issues.

2 participants