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:
- 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:
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)