# netket.sampler.MetropolisHamiltonian#

netket.sampler.MetropolisHamiltonian(hilbert, hamiltonian, **kwargs)#

Sampling based on the off-diagonal elements of a Hamiltonian (or a generic Operator). In this case, the transition matrix is taken to be:

$T( \mathbf{s} \rightarrow \mathbf{s}^\prime) = \frac{1}{\mathcal{N}(\mathbf{s})}\theta(|H_{\mathbf{s},\mathbf{s}^\prime}|),$

where $$\theta(x)$$ is the Heaviside step function, and $$\mathcal{N}(\mathbf{s})$$ is a state-dependent normalization. The effect of this transition probability is then to connect (with uniform probability) a given state $$\mathbf{s}$$ to all those states $$\mathbf{s}^\prime$$ for which the Hamiltonian has finite matrix elements. Notice that this sampler preserves by construction all the symmetries of the Hamiltonian. This is in generally not true for the local samplers instead.

This sampler only works on the CPU. To use the Hamiltonian sampler with GPUs, you should use netket.sampler.MetropolisHamiltonianNumpy

Parameters
• hilbert – The Hilbert space to sample.

• hamiltonian – The operator used to perform off-diagonal transition.

• n_chains – The total number of independent Markov chains across all MPI ranks. Either specify this or n_chains_per_rank.

• n_chains_per_rank – Number of independent chains on every MPI rank (default = 16).

• n_sweeps – Number of sweeps for each step along the chain. Defaults to the number of sites in the Hilbert space. This is equivalent to subsampling the Markov chain.

• reset_chains – If True, resets the chain state when reset is called on every new sampling (default = False).

• machine_pow – The power to which the machine should be exponentiated to generate the pdf (default = 2).

• dtype – The dtype of the states sampled (default = np.float64).

Return type

netket.sampler.MetropolisSampler

Examples

Sampling from a RBM machine in a 1D lattice of spin 1/2

>>> import netket as nk
>>>
>>> g=nk.graph.Hypercube(length=10,n_dim=2,pbc=True)
>>> hi=nk.hilbert.Spin(s=0.5, N=g.n_nodes)
>>>
>>> # Transverse-field Ising Hamiltonian
>>> ha = nk.operator.Ising(hilbert=hi, h=1.0, graph=g)
>>>
>>> # Construct a MetropolisHamiltonian Sampler
>>> sa = nk.sampler.MetropolisHamiltonian(hi, hamiltonian=ha)
>>> print(sa)
MetropolisSampler(rule = HamiltonianRule(Ising(J=1.0, h=1.0; dim=100)), n_chains = 16, n_sweeps = 100, reset_chains = False, machine_power = 2, dtype = <class 'numpy.float64'>)

Return type

MetropolisSampler