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:

F ⁣(ψ,ϕ)=ψϕ2.F\!\left(\lvert\psi\rangle,\lvert\phi\rangle\right) =\left\lvert\langle\psi\vert\phi\rangle\right\rvert^2.

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:

rx=2Re ⁣(a0a1),ry=2Im ⁣(a0a1),rz=(a02a12).\begin{aligned} r_x&=2\operatorname{Re}\!\left(\sum a_0^*a_1\right),\\ r_y&=2\operatorname{Im}\!\left(\sum a_0^*a_1\right),\\ r_z&=\sum\left(\lvert a_0\rvert^2-\lvert a_1\rvert^2\right). \end{aligned}

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.

rust
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".