quantax.sampler.MixSampler#

class quantax.sampler.MixSampler(samplers: Sequence[Metropolis], thermal_steps: int | None = None, sweep_steps: int | None = None, initial_spins: Array | None = None)#

Bases: Metropolis

A mixture of several metropolis samplers. Every proposal is generated by a randomly chosen component sampler.

__init__(samplers: Sequence[Metropolis], thermal_steps: int | None = None, sweep_steps: int | None = None, initial_spins: Array | None = None)#
Parameters:
  • samplers – The component metropolis samplers to be mixed. For every proposal, one of them is randomly chosen to propose new configurations, with probability proportional to its nsamples. All component samplers must share the same state and reweight factor, otherwise a ValueError is raised. The number of samples generated per iteration is the sum of the nsamples of all component samplers.

  • 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. By default, the first run inherits the already-thermalized spins of the component samplers; otherwise the spins are random.

property particle_type: tuple[PARTICLE_TYPE, ...]#

The particle types of the systems that this sampler can be applied to.

property Nmodes: int#

Number of modes (fock state length)

property Nsites: int#

Number of sites

property nsamples: int#

Number of samples generated per iteration

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 reweight: Array#

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

property state: State#

The state used for computing the wave function and probability

sweep(nsweeps: int | None = None) → Samples#

Generate new samples by Metropolis sweeps.

Every Markov chain takes exactly nsweeps Metropolis 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 than nsweeps. For Variational states 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 a LogArray, 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 spins and prob, and also psi and r if 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. by Oloc. psi is never returned for nsweeps <= 0, as the state may have changed since the last sweep.

property update_mode: dict[str, Any]#

The update mode of local updates generated in the sampler. The modes shared by all component samplers are kept, with integer modes merged into their upper bounds over the components.

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.