quantax.sampler.SiteFlip#
- class quantax.sampler.SiteFlip(state: State, nsamples: int, reweight: float = 2.0, thermal_steps: int | None = None, sweep_steps: int | None = None, initial_spins: Array | None = None)#
Bases:
MetropolisGenerate Monte Carlo samples by flipping spins of spinful fermions locally.
Warning
This sampler conserves the number of fermions on each site.
- __init__(state: State, nsamples: int, reweight: float = 2.0, thermal_steps: int | None = None, sweep_steps: int | None = None, initial_spins: Array | None = None)#
- Parameters:
state β The state used for computing the wave function and probability.
nsamples β Number of samples generated per iteration. It should be a multiple of the total number of machines to allow samples to be equally distributed on different machines.
reweight β The reweight factor n defining the sample probability \(|\psi|^n\), default to 2.0.
thermal_steps β The number of thermalization steps in the beginning of each Markov chain, default to be 20 * fock state length.
sweep_steps β The number of steps for generating new samples, default to be 2 * fock state length.
initial_spins β The initial spins for every Markov chain before the thermalization steps, default to be random.
- property particle_type: tuple[PARTICLE_TYPE, ...]#
The particle types of the systems that this sampler can be applied to.
- reset(nsweeps: int | None = None, initial_spins: Array | None = None) None#
Reset all Markov chains and thermalize them.
- Parameters:
nsweeps β Number of sweeps for thermalizing the new samples, default to be
self._thermal_stepsinitial_spins β The initial spins for every Markov chain before the thermalization steps, default to be random.
- sweep(nsweeps: int | None = None) Samples#
Generate new samples by Metropolis sweeps.
Every Markov chain takes exactly
nsweepsMetropolis steps. A proposal that leaves the configuration unchanged is accepted for free without evaluating the wave function, so the number of batched evaluations is usually smaller thannsweeps. ForVariationalstates the whole sweep runs on the device in one jitted call; other states are swept by a host loop that dispatches one round at a time. The Metropolis-Hastings test accepts on \(|\psi(s')/\psi(s)|^n\) in float64.prob\(= |\psi|^n\) is computed at the end of the sweep as aLogArray, which doesnβt overflow, with \(\psi\) below single precision promoted to float32.- Parameters:
nsweeps β Number of sweeps, default to be
self._sweep_steps.- Returns:
The new samples carrying
spinsandprob, and alsopsiandrif the wave function of the sweep matches the forward pass of the state, i.e. unless the state uses local updates, or low precision is used with a forward chunk larger than the number of samples per device. Otherwise they are filled in later, e.g. byOloc.psiis never returned fornsweeps <= 0, as the state may have changed since the last sweep.