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

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

cargo install tzap-opt

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

pip install tzap  # uv pip install tzap

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. Fastest; already captures most of the T-gate reduction.
-O2 Adds superoptimization to -O1.
-O3 Repeats -O2 until reaching a fixpoint. Default.
-Osuper Like -O3, but with more superoptimization power (slower on first use).
tzap 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.

Custom pipeline

--passes runs an explicit, ordered sequence of passes in place of the default pipeline. It cannot be combined with --decompose-rz or --decompose-cz — list DecomposeRz/DecomposeCz as pass names instead.

tzap input.qasm -o output.qasm --passes CancelGates,PhaseFoldRand
tzap input.qasm -o output.qasm --passes DecomposeCz,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.3-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (815.0 kB view details)

Uploaded Python 3manylinux: glibc 2.17+ x86-64

tzap-0.4.3-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (765.4 kB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARM64

tzap-0.4.3-py3-none-macosx_11_0_arm64.whl (766.5 kB view details)

Uploaded Python 3macOS 11.0+ ARM64

tzap-0.4.3-py3-none-macosx_10_12_x86_64.whl (792.7 kB view details)

Uploaded Python 3macOS 10.12+ x86-64

File details

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

File metadata

File hashes

Hashes for tzap-0.4.3-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 dc16dc7037d1137f7fc28bd9dd2fca4550ef32bfe54b823c0986ae5cadaccca5
MD5 c7d40a61213344f98f5e28cf951450d5
BLAKE2b-256 f8b8af5029a49e52c43e7630c0859333f6ebbc7f5a24a5369b703e7e513cb038

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tzap-0.4.3-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 ecdf9d3e6c442e906b982b3bd992b180a8661f7de91d04861afe2eef1f909754
MD5 b02f45b4566cec34e17d2361e7a03b2f
BLAKE2b-256 02be1aacce1c18328bbcee45bc7ff72435e25c9f3f14cf2d87bdf37d1e770789

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tzap-0.4.3-py3-none-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 766.5 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.3-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a261b54d4cfb25c72979ace3327220959c34cee3696f2dc953d305719b9ee1ed
MD5 fd681b9db593c6a1e2de96b8636a1a86
BLAKE2b-256 c002e6a11d37344b930a636a139e1de4ece634bef203a1613d64b0b8348a3dea

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tzap-0.4.3-py3-none-macosx_10_12_x86_64.whl
  • Upload date:
  • Size: 792.7 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.3-py3-none-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 ae27f8f75c7773afc70e2fa04ee8eaabaa94ea337d6d7c575b932ed133449794
MD5 92ae8225133d41f787a8a311b802260b
BLAKE2b-256 9b0e4c4bdade1eae912a618228ddb1b56fafcbe2c751aa67533e8f9bd49f3bc2

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