Pauli observables
Applicable version · ArcQML 0.1.0
On this page
PauliString
PauliString represents a tensor product of PauliOp values, storing only non-I terms in qubit-index order. Construction checks qubit ranges and duplicate qubit s. identity, single, x, y, and z provide shortcuts. Two PauliString objects commute when the number of positions with different, non-I Paulis on the same qubit is even.
For two qubits, X(0) corresponds to I ⊗ X, mapping |00⟩ to |01⟩. multiply(rhs) returns (complex phase, resulting PauliString). This supports Pauli algebra; public SparsePauliOp coefficients are restricted to finite real values, so observable expectations are real.
SparsePauliOp and compilation caching
SparsePauliOp is a collection of PauliTerm objects, each term containing a finite real coefficient and a PauliString. Hamiltonian, PauliSum, and PauliObservable are aliases. Construction requires nonzero num_qubits and consistent qubit counts across terms. scale and simplify also reject nonfinite factors or invalid tolerance values.
At the first state-vector evaluation, the public Rust layer prepares a reusable execution representation of SparsePauliOp: diagonal term s can be merged, while off-diagonal Pauli strings become bit masks for expectation and H|ψ⟩ evaluation in the public observable implementation. Adding a term invalidates the cache. clone copies the observable definition but not its execution cache. Reusing one Hamiltonian during training therefore avoids preparing the same execution information each iteration.
let mut h = SparsePauliOp::single(2, 0usize, Pauli::Z, 0.5)?;
h.add_pauli_string(-1.0, PauliString::x(2, 1usize)?)?;
// H = 0.5 Z(0) − 1.0 X(1)
Expectation semantics
For the current pure state, single-state expectation_observable returns an F64 scalar Tensor. The batch version returns a Tensor with shape equal to [B] and dtype F64, one value per initial-state row. The expectation is:
The differentiable path created by run is reused for adjoint backpropagation, avoiding reconstruction of the same observable-action result.