# netket.sampler.ExactSampler¶

class netket.sampler.ExactSampler(*args, __precompute_cached_properties=False, __skip_preprocess=False, **kwargs)

This sampler generates i.i.d. samples from $$|\Psi(\sigma)|^2$$.

In order to perform exact sampling, $$|\Psi(\sigma)|^2$$ is precomputed an all the possible values of the quantum numbers $$\sigma$$. This sampler has thus an exponential cost with the number of degrees of freedom, and cannot be used for large systems, where Metropolis-based sampling are instead a viable option.

Inheritance
Attributes
is_exact
machine_pow: int = 2
n_batches

The batch size of the configuration $sigma$ used by this sampler.

In general, it is equivalent to n_chains.

Return type

int

n_chains

The total number of chains across all MPI ranks.

If you are not using MPI, this is equal to n_chains_per_rank

Return type

int

n_chains_per_rank: int = None
Methods
init_state(machine, parameters, seed=None)

Creates the structure holding the state of the sampler.

If you want reproducible samples, you should specify seed, otherwise the state will be initialised randomly.

If running across several MPI processes, all sampler_states are guaranteed to be in a different (but deterministic) state. This is achieved by first reducing (summing) the seed provided to every MPI rank, then generating n_rank seeds starting from the reduced one, and every rank is initialized with one of those seeds.

The resulting state is guaranteed to be a frozen python dataclass (in particular, a flax’s dataclass), and it can be serialized using Flax serialization methods.

Parameters
Return type

SamplerState

Returns

The structure holding the state of the sampler. In general you should not expect it to be in a valid state, and should reset it before use.

log_pdf(model)

Returns a closure with the log_pdf function encoded by this sampler.

Note: the result is returned as an HashablePartial so that the closure does not trigger recompilation.

Parameters

model (Union[Callable, Module]) – The machine, or apply_fun

Return type

Callable

Returns

the log probability density function

replace(**updates)

Returns a new object replacing the specified fields with new values.

reset(machine, parameters, state=None)

Resets the state of the sampler. To be used every time the parameters are changed.

Parameters
Return type

SamplerState

Returns

A valid sampler state.

sample(machine, parameters, *, state=None, chain_length=1)

Samples chain_length elements along the chains.

Parameters
Returns

The next batch of samples. state: The new state of the sampler

Return type

σ

sample_next(machine, parameters, state=None)

Samples the next state in the markov chain.

Parameters
Returns

The new state of the sampler σ: The next batch of samples.

Return type

state