State analysis and sampling
Applicable version · ArcQML 0.1.0
On this page
Exact and marginal probabilities
analysis::probabilities reads current amplitudes and computes square(abs(amplitudes)). It returns a differentiable F64 Tensor with shape [d]; entry index corresponds to the same computational basis index, whose least significant bit is q0.
marginal_probabilities validates that the selection is nonempty, unique, and in range, then sorts selected qubit s in descending order. For each full basis index, selected bits form an output segment id, and segment_sum aggregates their probabilities. Selecting [0, 2] gives q2q0 order: 00, 01, 10, 11, regardless of the input selection order.
Pure-state fidelity and Bloch vectors
fidelity(lhs, rhs) first checks equal simulator qubit counts, then computes the squared modulus of the state inner product:
The result is not clamped, preserving agreement between forward expressions and backward rules. Identical normalized pure states theoretically give 1 and orthogonal states 0, but floating-point rounding may produce tiny out-of-range deviations.
bloch_vector computes coherence terms for each pair of zero-branch and one-branch amplitudes of the specified qubit, accumulating three components as follows:
It returns an ordinary BlochVector {x, y, z}, not a differentiable Tensor in the current implementation.
Exact behavior of sample_counts
sample_counts is available only on the single-state simulator. It requires positive integer shots, reads the current normalized C64 state, uses amplitude norm_sqr values as a discrete distribution, initializes StdRng from the supplied seed or a fresh random seed, and draws that many independent samples. It does not execute a Circuit, write back to state, cause measurement collapse, or create a differentiable node.
let mut sim = StateVectorSimulator::new(2)?;
sim.apply_circuit(&bell)?;
let counts = sim.sample_counts(1_000, Some(42))?;
// Display keys in q1q0 order, such as "00" and "11".