gflownet.proxy.ising
Classes
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.ProxyIsing energy model.
Implements an Ising Hamiltonian of the form
\[E(s) = -\frac{1}{2} s^T J s - h \cdot s\]where
sis a spin configuration,Jis the coupling matrix, andhis an external magnetic field.The factor
1/2ensures 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).
- nn_adjacency()[source]
Build the nearest-neighbor adjacency matrix for a hypercubic lattice.
Constructs a coupling matrix
Jfor ann_dim-dimensional hypercubic lattice of linear sizelength(total number of siteslength**n_dim), where each site is coupled to its nearest neighbors with strengthJ_nn.- Returns:
A tensor of shape
(N, N), whereN = length**n_dim, representing thenearest-neighbor coupling matrix.
- Return type:
- __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]