Tsim
A GPU-accelerated quantum circuit sampler based on ZX-calculus stabilizer rank decomposition. Tsim feels just like Stim, but supports non-Clifford gates.
Installation
Install with pip:
pip install bloqade-tsim
Or with uv:
uv add bloqade-tsim
If your machine has a GPU, use:
pip install "bloqade-tsim[cuda13]"
Quick Start
An introductory tutorial is available here. Please also refer to the documentation.
For many existing scripts, replacing stim with tsim should just work. Tsim mirrors the Stim API and currently supports all Stim instructions.
Additionally, Tsim supports the instructions T, T_DAG, R_Z, R_X, R_Y, U3, TPP, TPP_DAG, R_XX, R_YY, R_ZZ, R_PAULI, CCZ, and CCX.
import tsim
c = tsim.Circuit(
"""
RX 0
R 1
T 0
PAULI_CHANNEL_1(0.1, 0.1, 0.2) 0 1
H 0
CNOT 0 1
DEPOLARIZE2(0.01) 0 1
M 0 1
DETECTOR rec[-1] rec[-2]
"""
)
detector_sampler = c.compile_detector_sampler()
samples = detector_sampler.sample(shots=100)
Architecture
A detailed description of Tsim's architecture is given in arXiv:2604.01059.
Quantum programs are translated into ZX diagrams in which Pauli noise channels appear as parameterized vertices with binary variables $e_i$.
ZX simplification factors the diagram into a classical part that represents the Tanner graph and a quantum part containing the observable circuit. Both parts define a new basis of error mechanisms $f_i = \bigoplus_j T_{ij},e_j$.
The observable diagram is used to compute marginal probabilities for autoregressive sampling. Here, each diagram is decomposed into a sum of Clifford terms via stabilizer rank decomposition, following Sutcliffe and Kissinger (2024), and compiled into binary JAX tensors $g_{tki}$.
At sampling time, JIT-compiled XLA kernels contract $g_{tki}$ with batched noise configurations $f_i^{s}$ to evaluate marginal probabilities and autoregressively sample detector and observable bits.
Differences from Stim
Tsim supports non-deterministic detectors and observables. An important consequence is that Tsim will simulate actual detector samples, whereas Stim only reports detection flips (i.e. detection samples XORed with a noiseless reference sample). Concretely,
c = tsim.Circuit(
"""
X 0
M 0
DETECTOR rec[-1]
"""
)
sampler = c.compile_detector_sampler()
samples = sampler.sample(shots=100)
print(samples)
will report True values, whereas the same circuit would result in False values in Stim. To reproduce the behavior of Stim, you can use the following:
samples = sampler.sample(
shots=100,
use_detector_reference_sample=True,
use_observable_reference_sample=True,
)
When set to True, a noiseless reference sample is computed and XORed with the
results, so that output values represent deviations from the noiseless baseline.
Note that this feature should be used carefully. If detectors or observables are not deterministic, this may lead to incorrect statistics.
Benchmarks
With GPU acceleration, Tsim can achieve sampling throughput for low-magic circuits that approaches the throughput of Stim on Clifford circuits of the same size. The figure below shows a comparison for distillation circuits (35 and 85 qubits), cultivation circuits, and rotated surface code circuits. Tsim can be five orders of magnitude faster than quizx.
Supported Instructions
Tsim supports all Stim instructions. In addition, Tsim defines the following non-Clifford instructions:
T and T_DAG
The T gate applies a π/4 phase rotation around the Z axis, and T_DAG is its inverse:
T 0 1 2 # Apply T to qubits 0, 1, 2
T_DAG 0 # Apply T_DAG to qubit 0
Rotation Gates: R_X, R_Y, R_Z
Rotation gates around the X, Y, and Z axes by an angle θ = α·π (where α is specified as the parameter):
R_X(0.11) 0 # Rotate qubit 0 around X by 0.11π
R_Y(0.25) 1 # Rotate qubit 1 around Y by π/4
R_Z(0.125) 2 # Rotate qubit 2 around Z by π/8
U3 Gate
The general single-qubit unitary with three parameters (θ, φ, λ), each specified as a multiple of π:
U3(0.5, 0.25, 0.125) 0 # Apply U3 with θ=π/2, φ=π/4, λ=π/8
TPP and TPP_DAG (Pauli Product Phase)
TPP applies exp(−i π/8 · P) (up to global phase) for a Pauli product P, phasing the −1 eigenspace of P by exp(i π/4). TPP_DAG applies exp(+i π/8 · P), phasing by exp(−i π/4). For a single qubit, TPP Z0 is the T gate.
TPP X0*Y1 # Apply exp(-i π/8 · X0⊗Y1) (up to global phase)
TPP_DAG Z0 # Apply exp(+i π/8 · Z) = T_DAG (up to global phase)
Pauli Rotation Gates: R_XX, R_YY, R_ZZ, R_PAULI
Parametric Pauli-product rotations apply exp(−i α·π/2 · P) for a Pauli product P, where α is specified as the parameter (in half-turns, matching R_X/R_Y/R_Z). R_XX, R_YY and R_ZZ are the two-qubit specializations; R_PAULI takes an arbitrary Pauli product (up to 64 qubits) in Stim's X0*Y1*Z2 syntax. The two target qubits of R_XX/R_YY/R_ZZ must be distinct.
R_XX(0.5) 0 1 # Apply exp(-i π/4 · X0⊗X1)
R_YY(0.25) 0 1 # Apply exp(-i π/8 · Y0⊗Y1)
R_ZZ(0.5) 0 2 # Apply exp(-i π/4 · Z0⊗Z2)
R_PAULI(0.3) X0*Y1*Z2 # Apply exp(-i 0.3·π/2 · X0⊗Y1⊗Z2)
CCZ and CCX Gates
CCZ applies a controlled-controlled Z gate, and CCX applies the controlled-controlled X gate (Toffoli). Both gates are expanded internally into a Clifford+T decomposition:
CCZ 0 1 2 # Apply CCZ with controls 0 and 1, target 2
CCX 0 1 2 # Apply Toffoli/CCX with controls 0 and 1, target 2
Publications Using Tsim
- Simulating magic state cultivation with few Clifford terms by Kwok Ho Wan and Zhenghao Zhong (2025).
Contributing
We welcome contributions! Please see the contributing guide for details on setting up your development environment, running tests, and code style guidelines.
Citing Tsim
If you use Tsim, please consider citing the paper describing the core simulation approach:
@article{tsim2026,
title={Tsim: Fast Universal Simulator for Quantum Error Correction},
author={Haenel, Rafael and Luo, Xiuzhe and Zhao, Chen},
journal={arXiv preprint arXiv:2604.01059},
year={2026}
}
You may also cite the work by Sutcliffe and Kissinger (2024):
@article{sutcliffe2024fast,
title={Fast classical simulation of quantum circuits via parametric rewriting in the ZX-calculus},
author={Sutcliffe, Matthew and Kissinger, Aleks},
journal={arXiv preprint arXiv:2403.06777},
year={2024}
}
Metadata
Release files for bloqade-tsim 0.1.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| bloqade_tsim-0.1.5.tar.gz | 1.2 MB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| bloqade_tsim-0.1.5-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 1.3 MB
Release files / bloqade_tsim-0.1.5.tar.gz
| Download URL | bloqade_tsim-0.1.5.tar.gz |
|---|---|
| Size | 1.2 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d50d75edea34cecc6827bc7f320786b74217cd308615abbb7e4ce0545ca9fe20
|
|
BLAKE2b-256 checksum How to use checksums |
c2b65e85c7c9f3e021114facf6b80baa36bf1d8853a237a40760d88476e201dc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 21, 2026.
Transparency logRelease files / bloqade_tsim-0.1.5-py3-none-any.whl
| Download URL | bloqade_tsim-0.1.5-py3-none-any.whl |
|---|---|
| Size | 96.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
31512e004618ad1f7d8fe531ce924d16e9ee02057b521101ac4b5fdc6a2e4d75
|
|
BLAKE2b-256 checksum How to use checksums |
e02d748b475304692d54ce9e7669bfaea96a680ce693f29cc64f67989d188077
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 21, 2026.
Transparency log