Skip to main content

Module sparse

Module sparse 

Source
Expand description

Sparse state-vector representation for low-occupancy circuits.

Many circuits of interest keep the state supported on only a small subset of the 2^n computational-basis kets at any time: a permutation circuit (X / CNOT / Toffoli) keeps it a single basis state; an oracle / arithmetic circuit touches only a polynomial number of branches; the early layers of a sparse ansatz stay near |0…0⟩. Storing the full dense 2^n amplitude array is then wasteful.

SparseStateVector stores only the nonzero amplitudes in a hash map keyed by the basis index. Single-qubit and CNOT/Toffoli gate application operate directly on the populated entries, allocating new keys only when an amplitude actually becomes nonzero, so the time and memory cost scales with the occupancy (number of nonzero amplitudes) rather than with 2^n. Near-zero amplitudes are pruned after each operation to keep the representation tight.

Structs§

SparseStateVector
A sparse pure state: only nonzero basis amplitudes are stored.