jaxrens.sampling.mwg¶
Metropolis-within-Gibbs (MWG) sampler factory.
Assembles multiple move types into a single step function that dispatches via lax.switch. The MCState class is built dynamically from the move descriptors — only fields needed by the active moves are included.
Usage:
backend = HarmonicBackend(k=1.0)
init_fn, step_fn, per_move_fns = build_mwg(backend, [
MoveKernel("random_walk", random_walk.build_kernel, weight=7),
MoveKernel("volume", volume.build_kernel,
kernel_kwargs={"n_atoms": 64}, weight=2),
MoveKernel("galilean", galilean.build_kernel,
kernel_kwargs={"n_reflect": 5}, weight=1,
extra_state_fields={"direction": (jnp.ndarray,
lambda pos, types: jnp.zeros_like(pos))}),
])
state = init_fn(positions, types, energy, cell)
state, info = step_fn(rng_key, state, likelihood_constraint, move_key)
# move_key must be unbatched under vmap (see step_fn)
# per_move_fns[i](state, key, constraint) runs move i directly
Functions
Build a Metropolis-within-Gibbs sampler from move descriptors. |