Describe the issue
Converting a measurement circuit to a graph, applying simplify.to_gh, and converting it back adds an unwanted Hadamard before the measurement. This changes the measurement basis: on input |0⟩, the original circuit always measures 0, while the extracted circuit measures 0 or 1 with equal probability.
The issue requires only ZX colour conversion, not a simplification pass.
Explain how to reproduce the bug or problem
import pyzx as zx
from pyzx import simplify
source = """OPENQASM 3.0;
include "stdgates.inc";
qubit[1] q;
bit[1] c;
c[0] = measure q[0];
"""
circuit = zx.Circuit.from_qasm(source)
graph = circuit.to_graph()
print("original:", [str(g) for g in circuit.gates])
print("roundtrip:", [str(g) for g in zx.Circuit.from_graph(graph).gates])
simplify.to_gh(graph)
print("after to_gh:", [str(g) for g in zx.Circuit.from_graph(graph).gates])
Observed output:
original: ['Measurement(0)']
roundtrip: ['Measurement(0)']
after to_gh: ['HAD(0)', 'Measurement(0)']
All three should represent the same measurement, without an added Hadamard. A related manifestation is that H; measure becomes measure after clifford_simp and extraction.
Version
PyZX 0.10.6, Python 3.10.14, Linux. Also reproduced on master at ad022cf1d9 (2026-09-17).
Root cause
to_gh converts the X-type measurement leaf to Z-type and toggles its incident edge. This preserves the graph semantics, but graph_to_circuit emits a plain Measurement without accounting for the leaf's colour, leaving an extra edge-induced Hadamard. Extraction should account for both the leaf colour and the edge type.
Describe the issue
Converting a measurement circuit to a graph, applying
simplify.to_gh, and converting it back adds an unwanted Hadamard before the measurement. This changes the measurement basis: on input|0⟩, the original circuit always measures 0, while the extracted circuit measures 0 or 1 with equal probability.The issue requires only ZX colour conversion, not a simplification pass.
Explain how to reproduce the bug or problem
Observed output:
All three should represent the same measurement, without an added Hadamard. A related manifestation is that
H; measurebecomesmeasureafterclifford_simpand extraction.Version
PyZX 0.10.6, Python 3.10.14, Linux. Also reproduced on
masteratad022cf1d9(2026-09-17).Root cause
to_ghconverts the X-type measurement leaf to Z-type and toggles its incident edge. This preserves the graph semantics, butgraph_to_circuitemits a plainMeasurementwithout accounting for the leaf's colour, leaving an extra edge-induced Hadamard. Extraction should account for both the leaf colour and the edge type.