Stim supports six result formats for storing measurement samples, detection event samples, and observable frame change samples. All formats are intentionally minimalist: they contain no metadata about the circuit, the shot count, or the number of bits per shot. That context must be supplied by the caller. The choice of format depends on whether human readability or binary compactness is preferred, and whether the data is dense (many 1s) or sparse (few 1s).Documentation Index
Fetch the complete documentation index at: https://mintlify.com/quantumlib/Stim/llms.txt
Use this file to discover all available pages before exploring further.
01
Dense text — one character per bit. Easiest to read and debug.
b8
Dense binary — 8 bits per byte, little-endian within each byte. Efficient for storage.
r8
Sparse binary — run-length encoding of gaps between 1s. Efficient when 1s are rare.
ptb64
Dense binary — transposed layout optimized for SIMD. Requires shot count divisible by 64.
hits
Sparse text — comma-separated indices of set bits. Readable and compact for sparse data.
dets
Sparse labeled text — prefixed detector (
D) and observable (L) indices. Human-readable detection events.01 — ASCII text format
The 01 format stores each shot as a line of 0 and 1 characters, terminated by a newline (\n). It is the default format used by Stim because it is the simplest to inspect.
Each character maps directly to one bit: '0' means False, '1' means True.
Example output — 10 shots of the same deterministic circuit:
b8 — packed binary format
The b8 format stores each shot as ceil(n / 8) bytes, where n is the number of bits per shot. Shots are padded with trailing False bits to reach a byte boundary. Bits are packed in significance order: the least significant bit (2⁰ position) holds the first bit of the shot, the 2¹ position holds the second, and so on up to the 2⁷ position for the eighth bit.
This format requires the reader to know the number of bits per shot.
Example output — 10 shots of 14 bits: f0 2c f0 2c f0 2c ... (hex, 20 bytes total — 2 bytes per shot)
When to use: Storage efficiency when data is dense and the bit count per shot is known.
r8 — run-length encoded binary format
The r8 format stores each shot as a sequence of bytes, where each byte encodes the number of False bits before the next True bit. The maximum byte value (255) is special: it means “255 False bits, with no following True bit.” A sentinel True bit is appended to each shot before encoding, so the decoder knows when one shot ends and the next begins.
This format requires the reader to know bits_per_shot.
Example output — 10 shots of a 14-bit pattern 00001111001101: 4 0 0 0 2 0 1 0 per shot (hex: 04 00 00 00 02 00 01 00)
When to use: Detection event sampling where only a small fraction of bits are 1 (sparse data).
ptb64 — transposed bit-packed format
The ptb64 format arranges data for SIMD-parallel processing across 64 shots at a time. Instead of storing all bits of shot 0 followed by all bits of shot 1, it stores all 64 copies of measurement 0 (one bit per shot) packed into a single 8-byte word, followed by all 64 copies of measurement 1, and so on. After the full set of measurements for 64 shots, the pattern repeats for the next group of 64 shots.
Bits within each 8-byte word are stored in shot order, least-significant bit first.
Constraints:
- The number of shots must be a multiple of 64.
- The reader must know both
bits_per_shotand the total shot count.
M 0 1, with qubit 1 always 1): 0 0 0 0 0 0 0 0 ff ff ff ff ff ff ff ff (hex — 8 zero bytes for measurement 0, 8 0xff bytes for measurement 1)
When to use: High-throughput data processing pipelines that can exploit SIMD instructions (e.g., fast decoding with bitwise operations).
hits — sparse integer list format
The hits format stores each shot as a newline-terminated line of comma-separated integers. Each integer is the zero-based index of a bit that was True. Bits not listed were False. An empty line represents a shot with no True bits.
This format requires the reader to know bits_per_shot to reconstruct a dense bit vector.
Example output — 10 shots of a 14-bit pattern 00001111001101:
dets.
dets — labeled detector/observable format
The dets format stores each shot as a line beginning with the word shot, followed by space-separated labeled values. Each value is a prefix letter followed by an index:
| Prefix | Meaning |
|---|---|
M | Measurement result at that index was True |
D | Detection event at that index fired |
L | Logical observable at that index was flipped |
True are listed. An empty shot is represented as shot with nothing after it.
Example output — 3 shots with detector D1 and observable L5 set:
When sampling detection events with
compile_detector_sampler(), pass append_observables=True to include observable frame changes as L values in the output.Format comparison
| Format | Type | Density | Requires bits_per_shot? | Notes |
|---|---|---|---|---|
01 | Text | Dense | No | Default; easiest to inspect |
b8 | Binary | Dense | Yes | Most compact for dense data |
r8 | Binary | Sparse | Yes | Compact when few bits are 1 |
ptb64 | Binary | Dense | Yes | SIMD-optimized; shots must be multiple of 64 |
hits | Text | Sparse | Yes (for dense reconstruction) | Readable sparse format |
dets | Text | Sparse | Yes (for dense reconstruction) | Labeled; preferred for detection events |