quantax.sampler.Metropolis#

class quantax.sampler.Metropolis#

Bases: Sampler

Abstract class for metropolis samplers. The samples are equally distributed on different machines.

__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.

property update_mode: dict[str, Any]#

The update mode of local updates generated in the sampler.

property use_ref: bool#

Whether to use reference implementation for local updates.

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_steps

  • initial_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

Parameters:

nsweeps – Number of sweeps for generating the new samples, default to be self._sweep_steps

propose(key: Key, old_spins: Array) Array | tuple[Array, Array]#

Propose new configurations.

Returns:

Either a tuple of (new_spins, propose_ratio) or new_spins only, where new_spins is the proposed configurations, and propose_ratio is the ratio of proposal rate \(P(s|s') / P(s'|s)\). propose_ratio is set to 1 if not returned.

property Nmodes: int#

Number of modes (fock state length)

property Nsites: int#

Number of sites

property nsamples: int#

Number of samples generated per iteration

property reweight: float#

The reweight factor n defining the sample probability \(|\psi|^n\)

property state: State#

The state used for computing the wave function and probability