zxcalc/pyzx

Incorrect diagram colors after simplification (X --> Z)

Closed this issue · 2 comments

I find often the colors in the diagrams seem to be incorrect, as in attached diagram, related to below code. The nodes either side of the Z phase should still be X type, after the top two are fused. I'm not sure if the data in the graph is correct and just the display colors wrong, or if the graph itself is incorrect, but it's interesting the general structure seems to be correct, and just the colors wrong.
I have found this in other instances, where all the X type seem to be colored as Z type after simplification (even though the simplification looks to have the correct structure otherwise).

Version: 0.7.3 (via pip). Device: MacbookPro M1. Python 3.9.13.

import pyzx as zx
c = zx.Circuit(2)
c.add_gate("CNOT", 0, 1)
c.add_gate("ZPhase", 1, phase=0.1)
c.add_gate("CNOT", 0, 1)

zx.draw(c)

g = c.to_graph()
zx.simplify.full_reduce(g)
zx.draw(g)
pyzx_bug

The resulting diagram is correct. Note the blue edges represent edges that have a Hadamard gate on them, following the convention e.g. of https://arxiv.org/abs/1902.03178 .

Most simplification procedures in PyZX start by converting everything to this Z+hadamard form before performing other reductions.

Ahhh, my apologies, and thank you for your quick response.