netket.vqs.mc.kernels_packed.local_value_kernel_jax_packed

netket.vqs.mc.kernels_packed.local_value_kernel_jax_packed#

netket.vqs.mc.kernels_packed.local_value_kernel_jax_packed(logpsi, pars, σ, O, *, chunk_size=None, min_chunk_size=None, conn_chunk_size=None)[source]#

local_value kernel for MCState and jax-compatible operators that evaluates \(\log\psi\) only on the connected configurations \(x' \neq x\).

Warning

This function is experimental: it is public, but it can change in a minor release of NetKet, with a note in the changelog.

MCState uses it in expect and expect_and_grad if the experimental flag NETKET_EXPERIMENTAL_PACKED_KERNEL is set (off by default), for instance with nk.config.netket_experimental_packed_kernel = True. It can also be called explicitly, with the same arguments as local_value_kernel_jax(), for example

>>> import netket as nk
>>> from netket.vqs.mc.kernels_packed import local_value_kernel_jax_packed
>>> hi = nk.hilbert.Spin(0.5, 8)
>>> H = nk.operator.IsingJax(hi, nk.graph.Chain(8), h=1.0)
>>> sampler = nk.sampler.MetropolisLocal(hi)
>>> vstate = nk.vqs.MCState(sampler, nk.models.RBM(), n_samples=64)
>>> σ = vstate.samples.reshape(-1, hi.size)
>>> eloc = local_value_kernel_jax_packed(
...     vstate._apply_fun, vstate.variables, σ, H, chunk_size=4096
... )
>>> eloc.shape
(64,)

local_value_kernel_jax() evaluates the network on all the configurations returned by get_conn_padded(), including the diagonal \(x' = x\) and the padding. This kernel skips them, and evaluates the other ones with netket.jax.apply_packed(), which never recompiles when their number changes. This is faster for operators with many zero matrix elements, such as the Heisenberg and Hubbard models. The result agrees with local_value_kernel_jax() up to rounding, and is deterministic.

The kernel is differentiable.

Parameters:
  • logpsi (Callable) – the log-amplitude function.

  • pars (Any) – the variables of the model.

  • σ (Union[ndarray, Array]) – the samples, of shape (n_samples, hilbert.size).

  • O (DiscreteJaxOperator) – the operator.

  • chunk_size (int | None) – the number of configurations on which the network is evaluated at once: every call of logpsi has this batch, except the smaller chunks of the remainder (n_local_samples × max_conn_size / 16 if None). MCState passes its chunk_size, whereas the padded kernel local_value_kernel_jax_chunked() evaluates the max_conn_size connected configurations of chunk_size // max_conn_size samples at once.

  • min_chunk_size (int | None) – the size of the smallest chunk (chunk_size // 8 if None).

  • conn_chunk_size (int | None) – the number of connected configurations computed at once (as many as take 256 MiB if None), or the max_conn_size padded connected configurations of a single sample if they are more.

Returns:

The local values, of shape (n_samples,).