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

Choosing a Backend

By default PRISM-Q inspects the circuit and picks a backend. Name one when you know something the dispatcher cannot infer, or to benchmark a specific representation.

Let it choose

#![allow(unused)]
fn main() {
use prism_q::simulate;

let result = simulate(&circuit).seed(42).run().unwrap();   // BackendKind::Auto
}

Auto reads the circuit's structure and the statevector memory cap. A circuit with no entangling gates runs as a product state and a Clifford circuit on a stabilizer tableau. Past the memory cap, a circuit that keeps few basis states goes to the sparse backend and the rest to MPS at bond 256. Below it, a circuit with partly independent registers runs factored and everything else on the dense statevector. The decision tree draws these steps with their thresholds.

Some routes sit outside the tree:

  • A Clifford circuit of 16 or more qubits that splits into independent blocks goes to FactoredStabilizer.
  • Shots on a Clifford circuit go to the CompiledStabilizer sampler, which compiles the measurement record once and draws every shot from it.
  • On a Clifford+T circuit with few T gates, shots can take the stabilizer-rank sampler, and marginals at 12 qubits and above take deterministic Pauli propagation.
  • Expectation and marginal queries go to the tensor network when its planned contraction stays inside the peak bound.

Probabilities always come from the tree. The memory cap is half of physical memory, about 29 qubits on a 16 GiB host, unless PRISM_MAX_SV_QUBITS sets it.

Choose explicitly

#![allow(unused)]
fn main() {
use prism_q::{simulate, BackendKind};

let result = simulate(&circuit)
    .backend(BackendKind::Stabilizer)
    .seed(42)
    .run()
    .unwrap();
}

From Python, pass a BackendKind constructor such as BackendKind.stabilizer() to .backend(...).

Symptom to backend

If your circuit...UseWhy
Is Clifford only (H, S, CX, CZ, ...)StabilizerO(n²), scales to thousands of qubits
Is Clifford only and splits into independent blocksFactoredStabilizerOne tableau per block
Has no entangling gatesProductStateO(n), one state per qubit
Is dense and fits the memory capStatevectorExact, fastest for the general case
Stays concentrated in few basis statesSparseO(k) in nonzero amplitudes
Has low entanglement but many qubitsMps { max_bond_dim }Polynomial memory in bond dimension
Splits into independent registersFactoredSimulates blocks separately, merges lazily
Has low treewidth and you need an expectation or marginalTensorNetworkContracts only what the query reads
Needs exact noisy probabilities or expectationsDensityMatrixEvolves the mixed state once, 4ⁿ entries
Is Clifford + a few T gatesSee Clifford+TBeats a dense statevector

ProductState rejects entanglement

ProductState errors on any entangling gate. Auto selects it only for circuits that have none; choose it explicitly only for a circuit that stays a product state throughout.

Scaling

BackendMemoryCeiling
StatevectorThe memory cap: half of physical memory, about 29 qubits on 16 GiB
StabilizerThousands of qubits
Factored Stabilizer per clusterThousands of qubits
Sparse nonzeroLarge , small
MPSLarge , bounded
ProductUnbounded
Tensor NetworkSet by contraction orderPeak intermediate under PRISM_MAX_TN_PEAK_QUBITS; dense readout under PRISM_MAX_PROB_QUBITS
Factored worst caseLargest merged block
Density MatrixHalf the statevector cap, about 14 qubits on 16 GiB

Every cap derives from one detected memory budget. The distributed feature adds an exact statevector sharded across MPI ranks (Distributed Statevector and MPI). The Capability and Support Matrix has CPU and GPU support per backend, and the architecture reference has the internals.

Next: work through a task end to end in the Tutorials.