Skip to main content

A super fast, Rust-based optimizer for large Clifford+T circuits

Project description

⚡️ tzap

CI crates.io Rust Lean 4 License: Apache 2.0 arXiv

A super fast, Rust-based optimizer for large Clifford+T circuits.

  • tzap's philosophy is that each optimization pass should be linear in circuit size.
  • tzap minimizes T-count with a new linear-time phase folding algorithm, based on this paper.
  • tzap implements a new and fast superoptimization pass.
  • The core optimization algorithms are fully formalized in Lean under formalization.

tzap is multiple orders of mangitude faster than other optimizers—and linearly scales to millions of gates! Runtime comparison of tzap, VOQC, and QuiZX on GF multipliers

Installation

Homebrew (macOS/Linux, easiest option):

brew install qqq-wisc/tap/tzap

pip / pipx (no Rust required, downloads a prebuilt binary):

pipx install tzap

crates.io (requires Rust; builds from source):

cargo install tzap-opt

From source (this repo, requires Rust):

cargo install --path .

Prebuilt binary (no Rust required, downloads and runs a shell installer) — macOS/Linux:

curl -LsSf https://github.com/qqq-wisc/tzap/releases/latest/download/tzap-opt-installer.sh | sh

CLI Usage

tzap also works as a Rust library; see the Rust API documentation.

Optimize a circuit

tzap input.qasm -o output.qasm

For example, using a benchmark in this repo:

tzap benchmarks/feynman/gf2^256_mult.qasm -o optimized.qasm

tzap output:

⚡️ tzap
  Parsing benchmarks/feynman/gf2^256_mult.qasm (13.9 MB)
	└─ 768 qubits · 1,115,899 gates · 393,981 2q gates · 458,752 T/Tdg · 10,711 depth · 1.530s

  Final result
	├─ Gates    1,115,899 → 657,723 (↓41.1%)
	├─ 2q gates   393,981 → 393,981 (↓0.0%)
	├─ T/Tdg      458,752 → 262,400 (↓42.8%)
	├─ Depth       10,711 →   8,162 (↓23.8%)
	└─ Time        3.104s

Optimization levels

Level Description
-O1 Randomized phase folding + basic gate cancellation. Default.
-O2 Adds superoptimization to -O1.
-O3 Repeats -O2 until reaching a fixpoint.
-Osuper Like -O3, but with more superoptimization power (slower on first use).
tzap -O3 benchmarks/feynman/gf2^256_mult.qasm -o optimized.qasm

Decompose Rz into Clifford+T

Use --decompose-rz when the target backend only accepts Clifford+T; tzap uses gridsynth. --epsilon trades approximation accuracy for circuit size (default 1e-10; larger is coarser).

tzap input.qasm -o output.qasm --decompose-rz --epsilon 1e-6

Use --decompose-cz to decompose CZ gates into H+CX+H before the optimization pipeline. With --passes, it is prepended to the listed passes.

Custom pipeline

--passes runs an explicit, ordered sequence of passes in place of the default pipeline.

tzap input.qasm -o output.qasm --passes CancelGates,PhaseFoldRand

Circuit support

tzap supports a subset of OpenQASM 2.0:

  • Gates: h, x, z, s, sdg, t, tdg, rz, cx, ccx, ccz, cz, measure, reset
  • Declarations: qreg, creg
  • Not supported: classical conditionals (if), custom gate definitions (gate), barriers, include files (besides qelib1.inc, which is ignored)
  • Unrecognized lines produce an error

Toffoli (ccx) and doubly controlled-Z (ccz) are auto-decomposed into Clifford+T. Controlled-Z (cz) is kept native so phase folding and cancellation can operate through it; use --decompose-cz for H+CX output. Rz is left as-is unless you pass --decompose-rz.

Correctness

  1. Fuzzing and equivalence verification on small random circuits and benchmark circuits.
  2. Lean formalization: core algorithms are implemented and proven sound in Lean 4 — see formalization.

Citation

If you use tzap in your research, please cite:

@misc{albarghouthi2026tzap,
      title={Linear-Time T-Gate Optimization via Random Abstraction}, 
      author={Aws Albarghouthi},
      year={2026},
      eprint={2605.13929},
      archivePrefix={arXiv},
      primaryClass={cs.PL},
      url={https://arxiv.org/abs/2605.13929}, 
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

tzap-0.4.2-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (815.4 kB view details)

Uploaded Python 3manylinux: glibc 2.17+ x86-64

tzap-0.4.2-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (766.6 kB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARM64

tzap-0.4.2-py3-none-macosx_11_0_arm64.whl (765.7 kB view details)

Uploaded Python 3macOS 11.0+ ARM64

tzap-0.4.2-py3-none-macosx_10_12_x86_64.whl (791.4 kB view details)

Uploaded Python 3macOS 10.12+ x86-64

File details

Details for the file tzap-0.4.2-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for tzap-0.4.2-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f52e6ea5601d09d7e2f9d928567f3171f5c336a32c6c0194055482b255017cc3
MD5 83ac20a7c66db046d4735c9dc3100c7e
BLAKE2b-256 5e189184c6b9b03998b31bb34ca7877d5d93cd81059f60a2d7e8fa8fdb314b26

See more details on using hashes here.

File details

Details for the file tzap-0.4.2-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for tzap-0.4.2-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 79b5a0e78fb83c1675d67c8f92ea10d1b016b4bdab36bfee4b694981c27f94e8
MD5 a39668cb2ef50e7a5c6b9b58db105a89
BLAKE2b-256 a7931ff0d7a217f46a8f487db677c36ba560899f7144b8fde6b51acd440cb503

See more details on using hashes here.

File details

Details for the file tzap-0.4.2-py3-none-macosx_11_0_arm64.whl.

File metadata

  • Download URL: tzap-0.4.2-py3-none-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 765.7 kB
  • Tags: Python 3, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for tzap-0.4.2-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f8b69e7654bff5821af0af7541e0e98ad3ddecc2971113d1e148be2739ade630
MD5 763fbc06780d0229433dc7c5d927c3ef
BLAKE2b-256 9edf61407c17c7735ac72fc22231d7675a66f23ee6329d25deeccb93c29e0c18

See more details on using hashes here.

File details

Details for the file tzap-0.4.2-py3-none-macosx_10_12_x86_64.whl.

File metadata

  • Download URL: tzap-0.4.2-py3-none-macosx_10_12_x86_64.whl
  • Upload date:
  • Size: 791.4 kB
  • Tags: Python 3, macOS 10.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for tzap-0.4.2-py3-none-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 bd1d19cd91c0be01fc6e2069a2709da9d1b0f2f09bb3c4bd1d08c61c2239cd82
MD5 9915771265973fde866afc28e5a7e8c0
BLAKE2b-256 99837206d863615ec347e1df1b572ba2255e76e3a9ebb7671418aeaf6792d8c1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page