odatse.algorithm.exchange module#
- class odatse.algorithm.exchange.Algorithm(info: Info, runner: Runner = None, run_mode: str = 'initial')[source]#
Bases:
AlgorithmBaseReplica 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.
- numsteps#
Total number of Monte Carlo steps to perform.
- Type:
int
- numsteps_exchange#
Number of steps between exchange attempts.
- Type:
int
- numsteps_thermalization#
Number of steps to discard for thermalization.
- 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”.
- _apply_state(data: dict, mode: str = 'resume', restore_rng: bool = True) None[source]#
Restore algorithm state from a checkpoint snapshot.
Delegates MPI validation, RNG restore, and MC-layer fields to the base class, validates the replica count, then applies exchange-specific fields and propagates the restored RNG to the state space.
REMC does not distinguish between resume and continue modes;
modeis accepted for API consistency with PAMC and forwarded to super().- Parameters:
data (dict) – Snapshot previously produced by
__getstate__.mode (str) –
"resume"or"continue"; forwarded to the base class.restore_rng (bool) – When True (default) the RNG state is restored from data; when False a fresh RNG state is kept (
--reset_randmode).
- _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.