#compilation #optimization #zx-calculus

bin+lib quizx

Quantum Circuit Optimisation and Compilation using the ZX-calculus

3 releases (breaking)

0.3.0 Jun 12, 2025
0.2.0 May 13, 2025
0.1.0 May 4, 2025

#1546 in Math

Download history 1/week @ 2025-10-10 6/week @ 2025-10-17 2/week @ 2025-10-24 491/week @ 2025-11-14 151/week @ 2025-11-21 66/week @ 2025-11-28 3/week @ 2025-12-05 68/week @ 2025-12-12 13/week @ 2025-12-19

190 downloads per month

Apache-2.0

475KB
11K SLoC

QuiZX: a quick Rust port of PyZX

crates msrv rs-docs

PyZX is a Python library for quantum circuit optimisation and compiling using the ZX-calculus. It's great for hacking, learning, and trying things out in Jupyter notebooks. However, it's written to maximise clarity and fun, not performance.

This is a port of some of the core functionality of PyZX to the Rust programming language. This is a modern systems programming language, which enables writing software that is very fast and memory efficient.

Check the Rust Changelog for the latest updates.

A bit about performance

As a very anecdotal example of the performance difference, the program spider_chain builds a chain of 1 million green spiders and fuses them all. In PyZX, you can fuse all the spiders in a ZX-diagram as follows:

from pyzx.basicrules import *

success = True
while success:
    success = any(fuse(g, g.edge_s(e), g.edge_t(e)) for e in g.edges())

In QuiZX, the Rust code is slightly more verbose, but similar in spirit:

use quizx::basic_rules::*;

loop {
    match g.find_edge(|v0,v1,_| check_spider_fusion(&g, v0, v1)) {
        Some((v0,v1,_)) => spider_fusion_unchecked(&mut g, v0, v1),
        None => break,
    };
}

On my laptop, the PyZX code takes about 98 seconds to fuse 1 million spiders, whereas the QuiZX code takes 17 milliseconds.

Dependencies

~12–20MB
~387K SLoC