quantax.sampler.Samples#
- class quantax.sampler.Samples#
The samples generated by the sampler, with 5 attributes. Only
spinsis positional, the other attributes are keyword-only, e.g.Samples(spins, psi=psi, prob=prob).This class is mutable and not a PyTree, so it canβt be passed to jitted functions. The attributes missing in the samples are filled in place by the functions computing them, e.g.
Oloc.Warning
A filled
psibelongs to the state it was evaluated by. To reuse the samples with another state, or after the parameters of the state are updated, setpsitoNoneor to the new wave function first.- spins:
The spin configurations \(s\).
- psi:
The wave function \(\psi(s)\) of the spin configurations.
Noneif not evaluated yet, e.g. when the wave function evaluated by the sampler is not consistent with the forward pass of the state, seesweep.- prob:
The probability \(q_s\) from which the samples are drawn, up to a normalization constant. It is the probability actually used by the sampler, e.g. \(|\psi(s)|^n\) with the reweight factor n and \(\psi\) evaluated by the sampling forward pass.
Nonedefaults to \(q_s = |\psi(s)|^2\).- state_internal:
The internal status of samples for the forward pass with reference. See
RefModelfor details.- r:
The reweighting factor. According to
\[\left< x \right>_p = \frac{\sum_s p_s x_s}{\sum_s p_s} = \frac{\sum_s q_s x_s p_s/q_s}{\sum_s q_s p_s/q_s} = \frac{\left< x p/q \right>_q}{\left< p/q \right>_q},\]the expectation value with probability distribution p can be computed from samples with a different probability distribution q.
The reweighting factor is defined as
\[r_s = \frac{p_s/q_s}{\left< p/q \right>_q},\]so that \(\left< x \right>_p = \left< r x \right>_q\).
Usually, \(p_s = |\psi(s)|^2\) is the target probability, and \(q_s\) can be chosen as \(|\psi(s)|^n\) or computed from a helper neural network. In the former case, \(r_s = \frac{|\psi_s|^{2-n}}{\left< |\psi|^{2-n} \right>}\).
Nonestands for the trivial factor \(r_s = 1\). Ifprobis given,ris computed frompsiandprobbyupdate_r.
- __init__(spins: Array, *, psi: NDArray | Array | LogArray | None = None, prob: NDArray | Array | LogArray | None = None, state_internal: PyTree = None, r: Array | None = None) None#
- __getitem__(idx) Samples#
Index every array leaf along the leading (sample) axis, e.g.
samples[:10].
- update_r() None#
Update the reweighting factor
rin place from the wave function and probability of the samples as\[r_s = \frac{p_s/q_s}{\left< p/q \right>_q}, \quad p_s = |\psi(s)|^2, \quad q_s = \text{prob}_s.\]Nothing is changed if
probisNone, which keeps a givenr.- Raises:
ValueError β If
probis given butpsiisNone.
- block_until_ready() Samples#
Wait until all arrays of the samples are computed, also called by
jax.block_until_ready.