Quick start
An introductory tutorial is available here. For many existing scripts, replacingstim with tsim should just work. tsim mirrors the Stim API and 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.
Installation
Architecture
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,True values, whereas the same circuit would result in False values in Stim. To reproduce the behavior of Stim, you can use the following:
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.
Postselected simulations
For postselected QEC experiments, pass a boolean mask toCompiledDetectorSampler.sample. The mask has length num_detectors; a shot is
discarded when any masked detector fires.
sample always returns exactly shots rows. Shots discarded by a direct
postselected detector skip the expensive JAX autoregressive loop; their direct
detector columns are still correct, and all other columns are filled with
False. Re-apply the mask to the detector columns (as above) to recover the
surviving shots. Detectors that live inside a JAX component cannot be evaluated
without running JAX, so those shots are always computed in full.
This is independent of prepend_observables, append_observables,
separate_observables, and bit_packed. When combined with
use_detector_reference_sample, the reference XOR is applied before the
postselection discard check. On surviving rows it is applied to every detector
column; on direct-discarded partial rows it is applied only to direct detector
columns (component columns stay False). When combined with
use_observable_reference_sample, the reference XOR is applied to every row
that ran JAX; direct-discarded partial rows are left unchanged.