netket.sampler.rules.FermionHopRule#
- class netket.sampler.rules.FermionHopRule[source]#
Bases:
ExchangeRule
Hopping rule for particles on a lattice.
Works similarly to
netket.sampler.rules.ExchangeRule
, but takes into account that only occupied orbitals can be exchanged with unoccupied ones.This sampler conserves the number of particles.
- Inheritance
- __init__(hilbert, *, clusters=None, graph=None, d_max=1, spin_symmetric=True)[source]#
Constructs the FermionHopRule.
Particles are only exchanged between modes where the particle number is different. For fermions, only occupied orbitals can be exchanged with unoccupied ones.
You can pass either a list of clusters or a netket graph object to determine the clusters to exchange.
- Parameters:
hilbert – The hilbert space to be sampled.
clusters (
list
[tuple
[int
,int
]] |None
) – 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 (
AbstractGraph
|None
) – 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 sitesspin_symmetric (
bool
) – (default True) If spin_symmetric, the graph must encode the connectivity between the first N physical sites having same spin, and it is replicated usingnetket.graph.disjoint_union()
other every spin subsector. This option conserves the number of fermions per spin subsector. If the graph does not have a number of sites equal to the number of orbitals in the hilbert space, this flag has no effect.
- Attributes
- clusters: jax.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)[source]#
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:
- Returns:
An optional state.
- random_state(sampler, machine, params, sampler_state, key)[source]#
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)[source]#
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.
- reset(sampler, machine, params, sampler_state)[source]#
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:
- 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.