Skip to content
Python library for quantum circuit rewriting and optimisation using the ZX-calculus
Branch: master
Clone or download
Type Name Latest commit message Commit time
Failed to load latest commit information.
circuits added circuit Mar 24, 2019
demos added challenge notebook Mar 23, 2019
js d3 code cleanup Feb 8, 2019
pyzx Seemed to have fixed the bug in phase teleportation? Mar 24, 2019
scratchpads Fixes to teleport_reduce Mar 22, 2019
tests Fixes to teleport_reduce Mar 22, 2019
.gitignore Starting documentation using Sphynx Jun 29, 2018
LICENSE * Moved some large circuits to a different folder Sep 13, 2018
makedoc.bat Started Benchmarking our simplifier Sep 3, 2018
runtests.bat Added loads of tests. They currently all pass. Jul 23, 2018 Intialize and requiremennts.txt to allow installation via pip Aug 20, 2018


Unitary Fund

PyZX (pronounce as Pisics) is a Python tool implementing the theory of ZX-calculus for the creation, visualisation, and automated rewriting of large-scale quantum circuits. Please watch this 2-minute video for a short introduction.

PyZX currently allows you to:

  • Read in quantum circuits in the file format of QASM, Quipper or Quantomatic.
  • Rewrite circuits into a pseudo-normal form using the ZX-calculus.
  • Extract new simplified circuits from these reduced graphs.
  • Visualise the ZX-graphs and rewrites using either Matplotlib, Quantomatic or as a TikZ file for use in LaTeX documents.
  • Output the optimised circuits in QASM, QC or QUIPPER format.

About the ZX-calculus

ZX-diagrams are a type of tensor network built out of combinations of linear maps known as spiders. There are 2 types of spiders: the Z-spiders (represented as green dots in PyZX) and the X-spiders (represented as red dots). Every linear map between some set of qubits can be represented by a ZX-diagram. The ZX-calculus is a set of rewrite rules for ZX-diagrams. There are various extensive set of rewrite rules. PyZX however, uses only rewrite rules concerning the Clifford fragment of the ZX-calculus. Importantly, this set of rewrite rules is complete for Clifford diagrams, meaning that two representations of a Clifford map can be rewritten into one another if and only if the two linear maps they represent are equal.

For a short introduction to the ZX-calculus see this paper while for a complete overview we recommend this book. PyZX extensively uses two derived rewrite rules known as local complementation and pivoting. More information about these operations can be found in this paper.


To install pyzx from source, clone this repository, cd into it, and run:

pip install -e .


See the Documentation for a full overview of the features of PyZX.

If you have Jupyter installed you can use one of the demonstration notebooks in the demos folder for an illustration of what PyZX can do.

This is some example Python code for generating a random circuit, optimizing it, and finally displaying it:

import pyzx as zx
qubit_amount = 5
gate_count = 80
#Generate random circuit of Clifford gates
circuit = zx.generate.cliffordT(qubit_amount, gate_count)
#If running in Jupyter, draw the circuit
#Use one of the built-in rewriting strategies to simplify the circuit
#See the result

PyZX can also be run from the commandline. To optimise a circuit you can for instance run python -m pyzx opt input_circuit.qasm

You can’t perform that action at this time.