odatse.algorithm.exchange module
- class odatse.algorithm.exchange.Algorithm(info: Info, runner: Runner = None, run_mode: str = 'initial')[source]
Bases:
AlgorithmBase
Replica Exchange Monte Carlo (REMC) Algorithm Implementation.
This class implements the Replica Exchange Monte Carlo algorithm, also known as Parallel Tempering. The algorithm runs multiple replicas of the system at different temperatures and periodically attempts to swap configurations between adjacent temperature levels.
- x
Current configuration state for all walkers.
- Type:
np.ndarray
- xmin
Minimum allowed values for parameters.
- Type:
np.ndarray
- xmax
Maximum allowed values for parameters.
- Type:
np.ndarray
- xstep
Step sizes for parameter updates.
- Type:
np.ndarray
- numsteps
Total number of Monte Carlo steps to perform.
- Type:
int
- numsteps_exchange
Number of steps between exchange attempts.
- Type:
int
- fx
Current energy/objective function values.
- Type:
np.ndarray
- istep
Current step number.
- Type:
int
- nreplica
Total number of replicas across all processes.
- Type:
int
- Tindex
Temperature indices for current replicas.
- Type:
np.ndarray
- rep2T
Mapping from replica index to temperature index.
- Type:
np.ndarray
- T2rep
Mapping from temperature index to replica index.
- Type:
np.ndarray
- exchange_direction
Direction for attempting exchanges (alternates between True/False).
- Type:
bool
Initialize the Algorithm class.
- Parameters:
info (odatse.Info) – Information object containing algorithm parameters.
runner (odatse.Runner, optional) – Runner object for executing the algorithm.
run_mode (str, optional) – Mode to run the algorithm in, by default “initial”.
- __exchange_multi_walker(direction: bool) None
Handle temperature exchanges for multiple walkers per process case.
This method implements the exchange logic when each process has multiple walkers, requiring collective MPI operations to coordinate exchanges across all processes.
- Parameters:
direction (bool) – If True, attempt exchanges between even-odd pairs. If False, attempt exchanges between odd-even pairs.
- __exchange_single_walker(direction: bool) None
Handle temperature exchanges for single walker per process case.
This method implements the exchange logic when each process has only one walker, requiring MPI communication to coordinate exchanges between processes.
- Parameters:
direction (bool) – If True, attempt exchanges between even-odd pairs. If False, attempt exchanges between odd-even pairs.
- __init__(info: Info, runner: Runner = None, run_mode: str = 'initial') None [source]
Initialize the Algorithm class.
- Parameters:
info (odatse.Info) – Information object containing algorithm parameters.
runner (odatse.Runner, optional) – Runner object for executing the algorithm.
run_mode (str, optional) – Mode to run the algorithm in, by default “initial”.
- _exchange(direction: bool) None [source]
Attempt temperature exchanges between replicas.
This method implements the core replica exchange logic, attempting to swap temperatures between adjacent replicas based on the Metropolis criterion: P(accept) = min(1, exp((β_j - β_i)(E_i - E_j)))
- Parameters:
direction (bool) – If True, attempt exchanges between even-odd pairs. If False, attempt exchanges between odd-even pairs.
- _load_state(filename, mode='resume', restore_rng=True)[source]
Load algorithm state from a checkpoint file.
Restores all necessary data to resume a previous simulation run.
- Parameters:
filename (str) – Path to the checkpoint file to read.
mode (str, optional) – Loading mode - either “resume” or “continue”, by default “resume”.
restore_rng (bool, optional) – Whether to restore the random number generator state, by default True. Set to False to use a fresh RNG state.
- Raises:
AssertionError – If loaded state doesn’t match current MPI configuration.
- _save_state(filename) None [source]
Save the current algorithm state to a checkpoint file.
- Saves all necessary data to resume the simulation later, including:
MPI configuration
Random number generator state
Timer information
Current configurations and energies
Best solutions found
Replica exchange state information
- Parameters:
filename (str) – Path to the checkpoint file to write.