A GPU-accelerated circuit sampler via ZX-calculus stabilizer rank decomposition. Tsim feels just like Stim, but supports non-Clifford gates.
It is based on Sutcliffe and Kissinger (2025).
Tsim is not yet released on PyPI. Install directly from GitHub:
pip install git+https://github.com/QuEraComputing/tsim.gitOr with uv:
uv add git+https://github.com/QuEraComputing/tsim.gitIf your machine has a GPU, use:
pip install "git+https://github.com/QuEraComputing/tsim.git#egg=tsim[cuda13]"An introductory tutorial is available here.
For many existing scripts, replacing stim with tsim should just work. Tsim mirrors the Stim API and currently supports all Stim gates.
Additionally, Tsim supports the instructions T, T_DAG, R_Z, R_X, R_Y, and U3 (see below for more details).
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)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.
Tsim is a quantum circuit simulator that supports fast sampling from Clifford+T circuits with Pauli noise. Its underlying algorithm is stabilizer rank decomposition, together with ZX-calculus simplification rules.
As such, Tsim can simulate hundreds of qubits, as long as the circuit does not have too many non-Clifford instructions.
Just like Stim, Tsim compiles circuits into measurement or detector samplers. These samplers manage a contiguous data structure that allows for efficient sampling on CPU or GPU, following the approach described in Sutcliffe and Kissinger (2025).
Tsim supports all Stim instructions.
In addition, Tsim supports the following non-Clifford instructions:
The T gate applies a π/4 phase rotation, 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 around the X, Y, and Z axes by an angle θ = α·π (where α is specified as the parameter):
R_X(0.5) 0 # Rotate qubit 0 around X by π/2
R_Y(0.25) 1 # Rotate qubit 1 around Y by π/4
R_Z(1.0) 2 # Rotate qubit 2 around Z by π
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