Skip to content

[Bug]: to_pyzx_graph/from_pyzx_graph don't preserve the semantics when calling pyzx.simplify.full_reduce. #235

@thierry-martinez

Description

@thierry-martinez

The following code should output fidelity 1, but outputs fidelity 0.5. The code takes a circuit with a Toffoli gate, transpiles it, converts the pattern to a PyZX graph, performs full_reduce and then converts the resulting graph back to a pattern: simulating the two patterns don't give equivalent state vectors.

from graphix import Circuit
from graphix.opengraph import OpenGraph
import pyzx
from graphix.pyzx import to_pyzx_graph, from_pyzx_graph
import numpy as np
from copy import deepcopy

c = Circuit(3)
c.ccx(0, 1, 2)
p = c.transpile(opt=False).pattern
og = OpenGraph.from_pattern(p)
pyg = to_pyzx_graph(og)
pyg.normalize()
pyg_copy = deepcopy(pyg)
pyzx.simplify.full_reduce(pyg)
pyg.normalize()
t = pyzx.tensorfy(pyg)
t2 = pyzx.tensorfy(pyg_copy)
assert pyzx.compare_tensors(t, t2)
og2 = from_pyzx_graph(pyg)
p2 = og2.to_pattern()
s = p.simulate_pattern()
s2 = p2.simulate_pattern()
print(np.abs(np.dot(s.flatten().conj(), s2.flatten())))

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions