⚡️ tzap
Installation · Using tzap · Qiskit integration · PennyLane integration
A super fast, Rust-based optimizer for large Clifford+T circuits.
- tzap is state-of-the-art in speed, scalability, and gate-count reduction.
- 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 magnitude faster than other optimizers—and linearly scales to millions of gates!
Here's a runtime comparison to two powerful optimizers on increasingly larger circuits.
Installation
You can use tzap as a command-line utility or a library.
Install the binary
These options install the standalone native tzap executable.
Homebrew (macOS/Linux):
brew install qqq-wisc/tap/tzap
Prebuilt release binary (macOS/Linux):
curl -LsSf https://github.com/qqq-wisc/tzap/releases/latest/download/tzap-opt-installer.sh | sh
You can also build and install tzap from crates.io (cargo install tzap-opt) or build from source (cargo install --path .).
You can also use tzap through the Rust API; see the Rust API documentation.
Integrations with Qiskit and PennyLane
You can also use tzap as a Python library and apply it as Qiskit optimization pass or PennyLane transform. See the Qiskit API guide or PennyLane API guide for framework-specific setup.
Running tzap
The standard command-line workflow is described below.
Optimize a circuit
tzap input.qasm -o output.qasm
For example, using a benchmark in this repo:
$ tzap benchmarks/feynman/hwb12.qasm -o optimized.qasm
⚡️ tzap v0.4.3
Parsed benchmarks/feynman/hwb12.qasm (5.5 MB) in 0.098s
└─ 20 qubits · 514,412 gates
Loaded superoptimizer table in 0.018s
Converged after 6 rounds
┌─ Final result · 43.7% fewer gates · 2.169s ──────────────────────────┐
│ Gates ━━━━━━━━━━━━━╸────────────────── ↓43.7% · 514,412 → 289,484 │
│ 2q gates ━━━━━╸────────────────────────── ↓18.7% · 191,803 → 155,914 │
│ T/Tdg ━━━━━━━━━━━━━━━╸──────────────── ↓49.9% · 171,465 → 85,897 │
│ Depth ━━━━━━━╸──────────────────────── ↓24.3% · 274,781 → 207,940 │
└──────────────────────────────────────────────────────────────────────┘
wrote optimized.qasm
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/hwb12.qasm -O1 -o optimized.qasm
Python APIs
The package exposes the native optimizer through optimize_qasm, a
Qiskit optimization pass, and a
PennyLane transform.
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.
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,includefiles (besidesqelib1.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
- Fuzzing and equivalence verification on small random circuits and benchmark circuits.
- 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},
}
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tzap-0.4.4.tar.gz.
File metadata
- Download URL: tzap-0.4.4.tar.gz
- Upload date:
- Size: 257.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d88444299c60c7de9c0d226ffd93055a341a45eaf57ff16fd9caf98a35772fdc
|
|
| MD5 |
e18987058bf0ebb8402ff7ac9ebf12c2
|
|
| BLAKE2b-256 |
e15f4c787a09929bc08db5992e408c2a6727fec7a32714fbfa49702d20364ca1
|
File details
Details for the file tzap-0.4.4-cp310-abi3-win_amd64.whl.
File metadata
- Download URL: tzap-0.4.4-cp310-abi3-win_amd64.whl
- Upload date:
- Size: 752.4 kB
- Tags: CPython 3.10+, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5321e36e8f3261707e2bd90e35d5f45210f53462ef98973ec69ebd2eb0d5da77
|
|
| MD5 |
4b76905665fced58a4539bb1e8f23de4
|
|
| BLAKE2b-256 |
cd49b651b0418e926f398884cc4c63f3077503485eee9dce3118d606c5729dbb
|
File details
Details for the file tzap-0.4.4-cp310-abi3-musllinux_1_2_x86_64.whl.
File metadata
- Download URL: tzap-0.4.4-cp310-abi3-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 1.0 MB
- Tags: CPython 3.10+, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
988bd3be7547a2fc75030c6f7a2a21b4a5bd806ff8f06f6363ed6f364299418d
|
|
| MD5 |
96dfd549af3fd09d3c7faa837436085a
|
|
| BLAKE2b-256 |
2ba78f4e51f656ad389238c608cd3a74648690c1b6b74acae7233960d2d30b3d
|
File details
Details for the file tzap-0.4.4-cp310-abi3-musllinux_1_2_aarch64.whl.
File metadata
- Download URL: tzap-0.4.4-cp310-abi3-musllinux_1_2_aarch64.whl
- Upload date:
- Size: 949.8 kB
- Tags: CPython 3.10+, musllinux: musl 1.2+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1157b21bad722f40ae20518505e67ef68b7214c66b44a392bc22d415b5aab484
|
|
| MD5 |
ca270bedc75212c2c066e0bbe72d5e56
|
|
| BLAKE2b-256 |
461123e18cdd1b6c0dc1e0f0da6703d49cdf8213aee8c7795d369d13b7964796
|
File details
Details for the file tzap-0.4.4-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: tzap-0.4.4-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 824.4 kB
- Tags: CPython 3.10+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c8a5850a6b29b0d5801f1169212afe9163eb0a64cba4e570e421dfee41889817
|
|
| MD5 |
568b9bcbc314fec542368d312cad436b
|
|
| BLAKE2b-256 |
0f33632a47c1f4b3e8c2e3112db3b891e5f924b66a977290487b3536970ed342
|
File details
Details for the file tzap-0.4.4-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: tzap-0.4.4-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 772.2 kB
- Tags: CPython 3.10+, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bf6a37c7ddc1db3bd17711d5bde777054c7e39dc6d511c73e059040ceff99e0f
|
|
| MD5 |
0818181608c69bdb3b3e4180b435ed7e
|
|
| BLAKE2b-256 |
5a2896f7f28b5c54edaf9b74d3801154ac0ab492546a21fa1801e64f50a50511
|
File details
Details for the file tzap-0.4.4-cp310-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: tzap-0.4.4-cp310-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 753.1 kB
- Tags: CPython 3.10+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0db3145bc4a51949e945f280c6a134bdf8705a086015850598de6c7dc82efaf1
|
|
| MD5 |
b851485f27366de393ce11d6a8c6c559
|
|
| BLAKE2b-256 |
723a66fca9ada4a0d2259e935ddc00f3a123e02058da9b16accbe113bb8586b4
|
File details
Details for the file tzap-0.4.4-cp310-abi3-macosx_10_12_x86_64.whl.
File metadata
- Download URL: tzap-0.4.4-cp310-abi3-macosx_10_12_x86_64.whl
- Upload date:
- Size: 777.4 kB
- Tags: CPython 3.10+, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
16646aae3f4b9a577d6adbfa4bc420f364d0ce5787bb248ba75bcc05c50e820c
|
|
| MD5 |
dcc777fc4fe4cde9df369a6f17071a12
|
|
| BLAKE2b-256 |
cc74c154628bb6f19fe1f92f6d5eb760a1b676c95952b03adec46a702a70310f
|