Expand description
Lightweight exact state-vector simulator for QML circuits.
QML primitives (variational classifiers, reinforcement-learning value/policy
circuits, NLP models) build sequences of GateOp objects and need their
real output statistics (measurement probabilities, Pauli-Z expectations)
to compute losses and parameter-shift gradients. This module provides a
small, dependency-free, exact simulator that applies arbitrary one- and
two-qubit gates (via their dense matrix()) to a full 2^n amplitude
vector.
§Qubit convention
Qubit q corresponds to bit q of the basis-state index (little-endian),
i.e. amplitude index i has qubit q in state (i >> q) & 1. This matches
the convention used by the per-gate applicators in
crate::qml::advanced_algorithms and the gate matrix() definitions in
crate::gate::functions.
Functions§
- apply_
gate - Apply a single one- or two-qubit gate to
statein place. - expectation_
z - Expectation value of the Pauli-Z operator on qubit
target,⟨Z⟩ = P(|0⟩) − P(|1⟩) ∈ [−1, 1]. - probabilities
- Full probability distribution over all
2^ncomputational basis states. - probability_
one - Probability of measuring qubit
targetin state|1⟩. - simulate
- Apply a sequence of gates to a fresh
|0…0⟩state and return the final amplitude vector. - zero_
state - Allocate the
|0…0⟩computational-basis state fornum_qubitsqubits.