netket.sampler.rules.ExchangeRule#

class netket.sampler.rules.ExchangeRule[source]#

Bases: MetropolisRule

A Rule exchanging the state on a random couple of sites, chosen from a list of possible couples (clusters).

This rule acts on two local degree of freedom \(s_i\) and \(s_j\), and proposes a new state: \(s_1 \dots s^\prime_i \dots s^\prime_j \dots s_N\), where in general \(s^\prime_i \neq s_i\) and \(s^\prime_j \neq s_j\). The sites \(i\) and \(j\) are also chosen to be within a maximum graph distance of \(d_{\mathrm{max}}\).

The transition probability associated to this sampler can be decomposed into two steps:

  1. A pair of indices \(i,j = 1\dots N\), and such that \(\mathrm{dist}(i,j) \leq d_{\mathrm{max}}\), is chosen with uniform probability.

  2. The sites are exchanged, i.e. \(s^\prime_i = s_j\) and \(s^\prime_j = s_i\).

Notice that this sampling method generates random permutations of the quantum numbers, thus global quantities such as the sum of the local quantum numbers are conserved during the sampling. This scheme should be used then only when sampling in a region where \(\sum_i s_i = \mathrm{constant}\) is needed, otherwise the sampling would be strongly not ergodic.

Inheritance
Inheritance diagram of netket.sampler.rules.ExchangeRule
__init__(*, clusters=None, graph=None, d_max=1)[source]#

Constructs the Exchange Rule.

You can pass either a list of clusters or a netket graph object to determine the clusters to exchange.

Parameters:
  • clusters (Optional[list[tuple[int, int]]]) – The list of clusters that can be exchanged. This should be a list of 2-tuples containing two integers. Every tuple is an edge, or cluster of sites to be exchanged.

  • graph (Optional[AbstractGraph]) – A graph, from which the edges determine the clusters that can be exchanged.

  • d_max (int) – Only valid if a graph is passed in. The maximum distance between two sites

Attributes
clusters: Array#

2-Dimensional tensor \(T_{i,j}\) of shape \(N_\text{clusters}\times 2\) where the first dimension runs over the list of 2-site clusters and the second dimension runs over the 2 sites of those clusters.

The Exchange rule will swap the two sites of a random row of this matrix at every Metropolis step.

Methods
init_state(sampler, machine, params, key)#

Initialises the optional internal state of the Metropolis sampler transition rule.

The provided key is unique and does not need to be split.

It should return an immutable data structure.

Parameters:
  • sampler (MetropolisSampler) – The Metropolis sampler.

  • machine (Module) – A Flax module with the forward pass of the log-pdf.

  • params (Any) – The PyTree of parameters of the model.

  • key (Any) – A Jax PRNGKey.

Return type:

Optional[Any]

Returns:

An optional state.

random_state(sampler, machine, params, sampler_state, key)#

Generates a random state compatible with this rule.

By default this calls netket.hilbert.random.random_state().

Parameters:
  • sampler (MetropolisSampler) – The Metropolis sampler.

  • machine (Module) – A Flax module with the forward pass of the log-pdf.

  • params (Any) – The PyTree of parameters of the model.

  • sampler_state (SamplerState) – The current state of the sampler. Should not modify it.

  • key (Any) – The PRNGKey to use to generate the random state.

replace(**kwargs)#

Replace the values of the fields of the object with the values of the keyword arguments. If the object is a dataclass, dataclasses.replace will be used. Otherwise, a new object will be created with the same type as the original object.

Return type:

TypeVar(P, bound= Pytree)

Parameters:
  • self (P) –

  • kwargs (Any) –

reset(sampler, machine, params, sampler_state)#

Resets the internal state of the Metropolis Sampler Transition Rule.

The default implementation returns the current rule_state without modifying it.

Parameters:
  • sampler (MetropolisSampler) – The Metropolis sampler.

  • machine (Module) – A Flax module with the forward pass of the log-pdf.

  • params (Any) – The PyTree of parameters of the model.

  • sampler_state (SamplerState) – The current state of the sampler. Should not modify it.

Return type:

Optional[Any]

Returns:

A reset state of the rule. This returns the same type of rule_state() and might be None.

transition(sampler, machine, parameters, state, key, σ)[source]#

Proposes a new configuration set of configurations $sigma’$ starting from the current chain configurations \(\sigma\).

The new configurations \(\sigma'\) should be a matrix with the same dimension as \(\sigma\).

This function should return a tuple. where the first element are the new configurations $sigma’$ and the second element is either None or an array of length σ.shape[0] containing an optional log-correction factor. The correction factor should be non-zero when the transition rule is non-symmetrical.

Parameters:
  • sampler – The Metropolis sampler.

  • machine – A Flax module with the forward pass of the log-pdf.

  • params – The PyTree of parameters of the model.

  • sampler_state – The current state of the sampler. Should not modify it.

  • key – A Jax PRNGKey to use to generate new random configurations.

  • σ – The current configurations stored in a 2D matrix.

Returns:

A tuple containing the new configurations \(\sigma'\) and the optional vector of log corrections to the transition probability.