PennyLane
  • Why PennyLane
  • Getting Started
  • Documentation
  • Ecosystem
Install
Install
  1. Compilation/
  2. ZX-Calculus Intermediate Representation

ZX-Calculus Intermediate Representation

OverviewDetailsCompilationResources

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)

Example circuit as a ZX-diagram

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)
Example circuit after full_reduce

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
Korbinian Kottmann

Korbinian Kottmann

Quantum simulation & open source software

PennyLane

PennyLane is an open-source software framework for quantum machine learning, quantum chemistry, and quantum computing, with the ability to run on all hardware. Built with ❤️ by Xanadu.

Stay updated with our newsletter

For researchers

  • Research
  • Features
  • Demos
  • Compilation
  • Datasets
  • Performance
  • Learn
  • Videos
  • Documentation
  • Teach

For learners

  • Learn
  • Codebook
  • Teach
  • Videos
  • Challenges
  • Demos
  • Compilation
  • Glossary

For developers

  • Features
  • Documentation
  • API
  • GitHub
  • Datasets
  • Demos
  • Compilation
  • Performance
  • Devices
  • Catalyst

© Copyright 2025 | Xanadu | All rights reserved

TensorFlow, the TensorFlow logo and any related marks are trademarks of Google Inc.

Privacy Policy|Terms of Service|Cookie Policy|Code of Conduct