Performance and SIMD
Internals are in Fusion Pipeline and Threading, SIMD, and Memory Layout.
Fusion, tiling and SIMD
-
Fusion merges small gate passes into fewer, larger ones before execution, reducing memory traffic over the statevector. It is gated on qubit count and costs nothing when it does not apply.
-
Cache tiling keeps batched gates on data that stays hot across a pass. At startup, the tile budget is
min(L2 per core, LLC per logical CPU / 4), clamped to 256 KB to 1 MB (256 KB on the i7-6700K reference host, where 1 MB tiles ran 2x slower at 22 and 24 qubits).MultiFusedruns targets fitting the budget on budget tiles (bits 0 to 13 at 256 KB), bits 14 to 16 on 2 MB tiles when they fit the last level cache, and higher targets untiled.Multi2qandMultiPauliRotgather contiguous 64-amplitude low runs plus up to eight high qubits into a 2^14 tile (MultiPauliRotcounts only X/Y qubits, since external Z bits fix one sign per tile). Override withPRISM_TILE_KB,PRISM_MULTI_2Q_TILE_BITS, andPRISM_MULTI_2Q_LOW_BITS; budgets above 256 KB are derived rather than measured. -
SIMD vectorizes the inner complex arithmetic loop, picking the tier at runtime: AVX-512 (opt-in via
PRISM_AVX512), AVX2+FMA, FMA or SSE2 on x86_64, NEON on aarch64, scalar elsewhere.
Removing arithmetic beats issuing it faster. A kernel whose operations an algebraic identity or operator structure eliminates hits the memory floor, while a vectorized kernel remains bounded by complex arithmetic issue.
Threading
Rayon parallel kernels engage at 15 qubits, below which pool overhead dominates, with
MIN_PAR_ELEMS = 4096 per task. The pool defaults to all logical cores.
Set RAYON_NUM_THREADS to cap parallelism. Hyperthreading helps at 24+ qubits by hiding
memory latency, but on a contended host it adds noise to benchmarks.
An application that already owns a Rayon pool can keep it: build a
ThreadPool::with_threads(n) and run simulations inside install. The global pool is
left unbuilt on that path.
Determinism
Unitary evolution and seeded terminal sampling on the dense backends are bitwise reproducible at any thread count; parallel reductions and the batched compiled sampler are not. Determinism states the contract per path.
Tuning environment variables
Every knob is read once per process, on first use, and cached. A value that fails to parse or falls below its minimum prints a stderr warning and is treated as unset. Any value switches a flag knob off.
Limits (also settable in code)
Each cap below is both a Limits field and an environment variable. Simulate::limits
(Python Simulation.limits) overrides one request and set_default_limits sets the
process default (request > process default > variable). memory_budget_bytes sets the
shared budget (half of physical memory by default) and discards lower layer individual
caps. auto_mps_bond_dim (default 256) has no variable.
Limits field | Variable | Default | Effect |
|---|---|---|---|
max_statevector_qubits | PRISM_MAX_SV_QUBITS | detected | Statevector qubit cap; see Backends |
max_density_matrix_qubits | PRISM_MAX_DM_QUBITS | floor(cap_sv / 2) | Density-matrix qubit cap, bounded by the statevector cap |
max_probability_qubits | PRISM_MAX_PROB_QUBITS | detected | Dense probability output cap |
max_export_qubits | PRISM_MAX_EXPORT_QUBITS | detected | Dense statevector export cap |
max_sparse_qubits | PRISM_MAX_SPARSE_QUBITS | detected | Sparse amplitude map cap (2^q entries) |
max_factored_merge_qubits | PRISM_MAX_FACTORED_MERGE_QUBITS | detected | Factored merged block width |
max_mps_workspace_qubits | PRISM_MAX_MPS_WORKSPACE_QUBITS | detected | MPS contraction workspace (2^q amplitudes) |
max_tn_peak_qubits | PRISM_MAX_TN_PEAK_QUBITS | detected | Largest planned tensor-network intermediate (2^q elements) |
max_tn_slices | PRISM_MAX_TN_SLICES | 1024 | Max tensor-network slices to fit the peak cap (1 disables slicing) |
max_stabilizer_cluster_qubits | PRISM_MAX_STABILIZER_CLUSTER_QUBITS | detected | Factored stabilizer merged cluster width |
max_qec_reference_qubits | PRISM_MAX_QEC_REFERENCE_QUBITS | 20 | Widest EXP_VAL program sent to the reference runner (not a memory cap) |
Tuning (environment only)
| Variable | Default | Effect |
|---|---|---|
PRISM_MAX_DENSE_OUTCOME_BITS | detected | Measured bit cap for dense terminal sampling |
PRISM_QFT_TWIDDLE_CACHE_LIMIT_MB | 256 | Soft cap on cached QFT twiddle tables (0 disables caching) |
PRISM_AVX512 | unset | 1 enables AVX-512 kernels (statevector, QFT, density-matrix 2q Kraus, stabilizer rows, compiled sampler) where avx512f and avx512vpopcntdq exist; verified under emulation, not yet timed on AVX-512 silicon |
PRISM_GPU_MIN_QUBITS | 14 | Auto GPU crossover qubit count (gpu feature) |
PRISM_STABILIZER_GPU_MIN_QUBITS | 1000 | Stabilizer GPU crossover qubit count |
PRISM_GPU_BTS_MIN_SHOTS | 131072 | Shot threshold for compiled BTS sampling on device |
PRISM_GPU_BTS_MIN_RANK | 4 | Compiled sampler rank threshold for device BTS sampling (min 1) |
PRISM_GPU_BTS_MIN_WEIGHT_FACTOR | 2 | Parity weight factor for device BTS route (min 1) |
PRISM_DIST_MIN_LOCAL_QUBITS | 10 | Minimum local qubits per rank before distribution (min 1) |
PRISM_DIST_EXCHANGE_CHUNK | 536870912 (2^29) | Amplitudes per rank exchange message (min 1) |
PRISM_DIST_RELABEL | 1 | 0/false disables qubit relabeling in distributed backend |
RAYON_NUM_THREADS | all cores | Rayon thread count, read by Rayon |
PRISM_NO_AVX2_2Q | unset | Flag: force the 128-bit FMA two-qubit kernel |
PRISM_MIN_TILES_PER_CPU | 1 | Minimum tiles per hardware thread (0 keeps budget tile) |
PRISM_TILE_KB | detected | Tile budget in KB (power of two, 128 to 2048; 256 on 256 KB L2) |
PRISM_MULTI_2Q_TILE_BITS | detected | Log2 of Multi2q tile amplitudes (13 to 18; 14 at 256 KB) |
PRISM_MULTI_2Q_LOW_BITS | 6 | Log2 of contiguous low run in Multi2q tile (6 to tile bits minus 1) |
PRISM_NO_AVX2_KRAUS | unset | Flag: disable AVX2 and AVX-512 dense two-qubit Kraus kernels |
PRISM_NO_REORDER | unset | Flag: disable Fused2q reordering for Multi2q tiles |
PRISM_NO_QFT_BLOCK | unset | Flag: expand QftBlock and skip textbook QFT recognition |
Benchmarking
Run benchmarks with --features parallel, one process at a time.
Benchmark Methodology has the targets, the A/B gate and the
comparison controls, and Performance the current numbers.