Skip to content

Boundary Energy#

Edge classification and incremental energy delta computation. These functions support the energy caching optimization in NRPT, avoiding full energy recomputation after each Gibbs sweep.

hamon.EdgePartition #

Pre-computed classification of edges relative to a block partition.

For each block b, edges are classified as: - incident: at least one endpoint in b (needed for ΔE after updating b) - boundary: exactly one endpoint in b, one outside - interior: both endpoints in b (only possible for non-independent-set blocks) - external: neither endpoint in b (ΔE = 0, skip entirely)

All arrays are numpy (used at Python level for BlockSpec construction, not inside JIT).

__dict__ class-attribute #

Read-only proxy of a mapping.

__doc__ class-attribute #

str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str

Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to 'utf-8'. errors defaults to 'strict'.

__firstlineno__ class-attribute #

int([x]) -> integer int(x, base=10) -> integer

Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.int(). For floating-point numbers, this truncates towards zero.

If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by '+' or '-' and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer literal.

int('0b100', base=0) 4

__module__ class-attribute #

str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str

Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to 'utf-8'. errors defaults to 'strict'.

__static_attributes__ class-attribute #

Built-in immutable sequence.

If no argument is given, the constructor returns an empty tuple. If iterable is specified the tuple is initialized from iterable's items.

If the argument is a tuple, the return value is the same object.

__weakref__ property #

list of weak references to the object

boundary_ratio property #

Fraction of incident edges that are boundary (vs interior).

For independent-set blocks (checkerboard), this is always 1.0. For rectangular blocks, this decreases as block size grows.

__init__(edges: list[tuple[AbstractNode, AbstractNode]], blocks: list[list[AbstractNode]]) #
savings_factor(block_idx: int) -> float #

FLOPS ratio: incident_edges / total_edges for block b.

< 1.0 means boundary-only delta is cheaper than full recomputation.

hamon.make_rectangular_blocks(L: int, block_size: int, nodes_2d: list[list[AbstractNode]]) -> tuple[list[list[AbstractNode]], list[list[int]]] #

Partition an L×L grid into rectangular blocks with 4-coloring.

Returns (blocks, color_classes) where: - blocks: list of node lists, one per rectangular block - color_classes: 4 lists of block indices that can update simultaneously

For m×m blocks in an L×L grid: - n_blocks = ceil(L/m)² per axis - 4 color classes (checkerboard of blocks) - boundary/total edge ratio ≈ 4m/(2m²) = 2/m

Parameters:

Name Type Description Default
L int

grid side length

required
block_size int

m, the side length of each rectangular block

required
nodes_2d list[list[AbstractNode]]

L×L array of nodes, nodes_2d[i][j] is node at row i, col j

required

hamon.make_ising_delta_fn(nodes: list[AbstractNode], edges: list[tuple[AbstractNode, AbstractNode]], free_blocks, biases: jax.Array, weights: jax.Array) #

Build a vmapped base-energy delta function for use with nrpt().

Returns delta_fn(old_stacked_states, new_stacked_states) -> (n_chains,), where delta_fn[c] = E_base(new_c) - E_base(old_c).

Pass the result as the energy_delta_fn keyword argument to nrpt():

delta_fn = make_ising_delta_fn(ebm.nodes, ebm.edges,
                               free_blocks, ebm.biases, ebm.weights)
nrpt(..., energy_delta_fn=delta_fn)
FLOPS note

For checkerboard (2-block) partitions every edge is incident to at least one block, so incident_mask = all-ones — same arithmetic as a full recompute but without the equinox dispatch overhead. The strict FLOPS savings appear with rectangular blocks (4-coloring) where the incident fraction is O(1/m) for m×m blocks.

Parameters:

Name Type Description Default
nodes list[AbstractNode]

all nodes in global order (IsingEBM.nodes)

required
edges list[tuple[AbstractNode, AbstractNode]]

all edges (IsingEBM.edges)

required
free_blocks

the free blocks used in the sampling program; any iterable of node-iterables (Block objects work directly)

required
biases Array

(n_nodes,) bias array (IsingEBM.biases)

required
weights Array

(n_edges,) weight array (IsingEBM.weights)

required