netket.sampler.rules.LocalRule#

class netket.sampler.rules.LocalRule#

Bases: netket.sampler.rules.MetropolisRule

A transition rule acting on the local degree of freedom.

This transition acts locally only on one local degree of freedom \(s_i\), and proposes a new state: \(s_1 \dots s^\prime_i \dots s_N\), where \(s^\prime_i \neq s_i\).

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

1. One of the site indices \(i = 1\dots N\) is chosen with uniform probability. 2. Among all the possible (\(m\)) values that \(s_i\) can take, one of them is chosen with uniform probability.

Inheritance
Inheritance diagram of netket.sampler.rules.LocalRule
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 splitted.

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(**updates)#

β€œReturns a new object replacing the specified fields with new values.

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 modofying 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 resetted, 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.