Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Performance and SIMD

Internals are in Fusion Pipeline and Threading, SIMD, and Memory Layout.

Fusion, tiling and SIMD

  1. 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.

  2. 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).

    MultiFused runs 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. Multi2q and MultiPauliRot gather contiguous 64-amplitude low runs plus up to eight high qubits into a 2^14 tile (MultiPauliRot counts only X/Y qubits, since external Z bits fix one sign per tile). Override with PRISM_TILE_KB, PRISM_MULTI_2Q_TILE_BITS, and PRISM_MULTI_2Q_LOW_BITS; budgets above 256 KB are derived rather than measured.

  3. 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.

Control the thread pool

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 fieldVariableDefaultEffect
max_statevector_qubitsPRISM_MAX_SV_QUBITSdetectedStatevector qubit cap; see Backends
max_density_matrix_qubitsPRISM_MAX_DM_QUBITSfloor(cap_sv / 2)Density-matrix qubit cap, bounded by the statevector cap
max_probability_qubitsPRISM_MAX_PROB_QUBITSdetectedDense probability output cap
max_export_qubitsPRISM_MAX_EXPORT_QUBITSdetectedDense statevector export cap
max_sparse_qubitsPRISM_MAX_SPARSE_QUBITSdetectedSparse amplitude map cap (2^q entries)
max_factored_merge_qubitsPRISM_MAX_FACTORED_MERGE_QUBITSdetectedFactored merged block width
max_mps_workspace_qubitsPRISM_MAX_MPS_WORKSPACE_QUBITSdetectedMPS contraction workspace (2^q amplitudes)
max_tn_peak_qubitsPRISM_MAX_TN_PEAK_QUBITSdetectedLargest planned tensor-network intermediate (2^q elements)
max_tn_slicesPRISM_MAX_TN_SLICES1024Max tensor-network slices to fit the peak cap (1 disables slicing)
max_stabilizer_cluster_qubitsPRISM_MAX_STABILIZER_CLUSTER_QUBITSdetectedFactored stabilizer merged cluster width
max_qec_reference_qubitsPRISM_MAX_QEC_REFERENCE_QUBITS20Widest EXP_VAL program sent to the reference runner (not a memory cap)

Tuning (environment only)

VariableDefaultEffect
PRISM_MAX_DENSE_OUTCOME_BITSdetectedMeasured bit cap for dense terminal sampling
PRISM_QFT_TWIDDLE_CACHE_LIMIT_MB256Soft cap on cached QFT twiddle tables (0 disables caching)
PRISM_AVX512unset1 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_QUBITS14Auto GPU crossover qubit count (gpu feature)
PRISM_STABILIZER_GPU_MIN_QUBITS1000Stabilizer GPU crossover qubit count
PRISM_GPU_BTS_MIN_SHOTS131072Shot threshold for compiled BTS sampling on device
PRISM_GPU_BTS_MIN_RANK4Compiled sampler rank threshold for device BTS sampling (min 1)
PRISM_GPU_BTS_MIN_WEIGHT_FACTOR2Parity weight factor for device BTS route (min 1)
PRISM_DIST_MIN_LOCAL_QUBITS10Minimum local qubits per rank before distribution (min 1)
PRISM_DIST_EXCHANGE_CHUNK536870912 (2^29)Amplitudes per rank exchange message (min 1)
PRISM_DIST_RELABEL10/false disables qubit relabeling in distributed backend
RAYON_NUM_THREADSall coresRayon thread count, read by Rayon
PRISM_NO_AVX2_2QunsetFlag: force the 128-bit FMA two-qubit kernel
PRISM_MIN_TILES_PER_CPU1Minimum tiles per hardware thread (0 keeps budget tile)
PRISM_TILE_KBdetectedTile budget in KB (power of two, 128 to 2048; 256 on 256 KB L2)
PRISM_MULTI_2Q_TILE_BITSdetectedLog2 of Multi2q tile amplitudes (13 to 18; 14 at 256 KB)
PRISM_MULTI_2Q_LOW_BITS6Log2 of contiguous low run in Multi2q tile (6 to tile bits minus 1)
PRISM_NO_AVX2_KRAUSunsetFlag: disable AVX2 and AVX-512 dense two-qubit Kraus kernels
PRISM_NO_REORDERunsetFlag: disable Fused2q reordering for Multi2q tiles
PRISM_NO_QFT_BLOCKunsetFlag: 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.