swap_monte_carlo

torch_sim.monte_carlo.swap_monte_carlo(*, model, kT, seed=None)[source]

Initialize a swap Monte Carlo simulation for atomic structure optimization.

Creates and returns functions for initializing the Monte Carlo state and performing Monte Carlo steps. The simulation uses the Metropolis criterion to accept or reject proposed swaps based on energy differences.

Make sure that if the trajectory is being reported, the TorchSimTrajectory.write_state method is called with variable_masses=True.

Parameters:
  • model (Module) – Energy model that takes a SimState and returns a dict containing ‘energy’ as a key

  • kT (float) – Temperature of the system in energy units

  • seed (int | None, optional) – Seed for the random number generator. Defaults to None.

Returns:

A tuple containing:
  • init_function (Callable): Function to initialize a SwapMCState from a SimState

  • step_function (Callable): Function to perform a single Monte Carlo step

Return type:

tuple

Examples

>>> init_fn, step_fn = swap_monte_carlo(model=energy_model, kT=0.1, seed=42)
>>> mc_state = init_fn(initial_state)
>>> for _ in range(100):
>>>     mc_state = step_fn(mc_state)