- Compilation/
ZX-Calculus Intermediate Representation
ZX-Calculus Intermediate Representation
ZX-calculus is a graphical language to describe linear operators between qubits. It can be utilized as an intermediate representation for quantum circuits and offers various compilation passes, in particular to reduce T gate count.
Inputs
- Arbitrary quantum circuit
Outputs
- ZX-diagram
Example
Consider a simple circuit containing phase gates, a CNOT and a Toffoli.
import pyzx as zx from fractions import Fraction circ = zx.Circuit(3) circ.add_gate("Z", 0) circ.add_gate("CNOT", 0, 1) circ.add_gate("ZPhase", 0, Fraction(1, 4)) circ.add_gate("TOF", 0, 1, 2) circ.add_gate("T", 2) zx.draw(circ)
Any ZX-diagram can be brought into a reduced gadget form (see compilation tab) via pyzx.full_reduce.
circ = circ.to_graph() zx.full_reduce(circ) zx.draw(circ)

Odd multiples of \frac{\pi}{4} correspond to T gates. The original circuit has seven T gates from the Toffoli, and another two plain T gates. The total T cost is reduced to seven in reduced gadget form.
Typical usage
ZX-calculus based compilation is broadly applicable to general quantum circuits, and works particularly well in conjunction with phase polynomial based methods such as TODD. Phase polynomial methods have an edge over ZX-calculus based methods when the circuits can be fully described by phase polynomials with no Hadamard layers splitting up the circuit.
References
[1] "Reducing T-count with the ZX-calculus", Aleks Kissinger, John van de Wetering, arXiv:1903.10477, 2019
[2] "Graph-theoretic Simplification of Quantum Circuits with the ZX-calculus", Ross Duncan, Aleks Kissinger, Simon Perdrix, John van de Wetering arXiv:1902.03178, 2019
[3] "There and back again: A circuit extraction tale", Miriam Backens, Hector Miller-Bakewell, Giovanni de Felice, Leo Lobski, John van de Wetering, arXiv:2003.01664, 2020
Cite this page
@misc{PennyLane-ZX-Calculus, title={ZX-Calculus Intermediate Representation}, howpublished={\url{https://pennylane.ai/compilation/zx-calculus-intermediate-representation}}, year={2025} }
Page author(s)
Korbinian Kottmann
Quantum simulation & open source software