gflownet.proxy.ising

Classes

Ising

Ising energy model.

Module Contents

class gflownet.proxy.ising.Ising(n_dim=None, length=None, J_nn=1.0, periodic=True, J=None, h=0.0, **kwargs)[source]

Bases: gflownet.proxy.base.Proxy

Ising energy model.

Implements an Ising Hamiltonian of the form

\[E(s) = -\frac{1}{2} s^T J s - h \cdot s\]

where s is a spin configuration, J is the coupling matrix, and h is an external magnetic field.

The factor 1/2 ensures that each pairwise interaction is counted once.

Parameters:
  • n_dim (int) – Number of spatial dimensions of the lattice. Not needed if J is provided.

  • length (int) – Number of sites along each dimension. Not needed if J is provided.

  • J_nn (float, default=1.0) – Nearest-neighbor coupling strength.

  • periodic (bool, default=True) – Whether to use periodic boundary conditions.

  • J (Optional[torch.Tensor]) – Optional full coupling matrix. Overrides Nearest-neighbor coupling matrix construction.

  • h (Union[float, torch.Tensor]) – External magnetic field (scalar or site-dependent tensor).

n_dim = None[source]
length = None[source]
J_nn = 1.0[source]
periodic = True[source]
h[source]
nn_adjacency()[source]

Build the nearest-neighbor adjacency matrix for a hypercubic lattice.

Constructs a coupling matrix J for an n_dim-dimensional hypercubic lattice of linear size length (total number of sites length**n_dim), where each site is coupled to its nearest neighbors with strength J_nn.

Returns:

  • A tensor of shape (N, N), where N = length**n_dim, representing the

  • nearest-neighbor coupling matrix.

Return type:

torch.Tensor

__call__(states)[source]

Compute the Ising energy for a batch of spin configurations.

  • Flattens input to shape (batch, state_dim).

  • Computes the quadratic interaction term:

    -0.5 * sum( (s @ J) * s)

  • Computes the field term:

    -h * sum(s) (if h is scalar)

    or -sum(h * s) (if h is per-site)

Parameters:

states (list or tensor) – Batch of spin configurations.

Returns:

Tensor of shape (batch,) containing energies.

Return type:

torchtyping.TensorType[batch]