odatse.algorithm.montecarlo module
- class odatse.algorithm.montecarlo.AlgorithmBase(info: Info, runner: Runner = None, domain=None, nwalkers: int = 1, run_mode: str = 'initial')[source]
Bases:
AlgorithmBase
Base of Monte Carlo
- nwalkers
the number of walkers (per one process)
- Type:
int
- x
current configurations (NxD array, N is the number of walkers and D is the dimension)
- Type:
np.ndarray
- fx
current “Energy”s
- Type:
np.ndarray
- istep
current step (or, the number of calculated energies)
- Type:
int
- best_x
best configuration
- Type:
np.ndarray
- best_fx
best “Energy”
- Type:
float
- best_istep
index of best configuration (step)
- Type:
int
- best_iwalker
index of best configuration (walker)
- Type:
int
- comm
MPI communicator
- Type:
MPI.comm
- rank
MPI rank
- Type:
int
- Ts
List of temperatures
- Type:
np.ndarray
- Tindex
Temperature index
- Type:
np.ndarray
Initialize the AlgorithmBase class.
- Parameters:
info (odatse.Info) – Information object containing algorithm parameters.
runner (odatse.Runner, optional) – Runner object for executing the algorithm (default is None).
domain (optional) – Domain object defining the problem space (default is None).
nwalkers (int, optional) – Number of walkers (default is 1).
run_mode (str, optional) – Mode of the run, e.g., “initial” (default is “initial”).
- __init__(info: Info, runner: Runner = None, domain=None, nwalkers: int = 1, run_mode: str = 'initial') None [source]
Initialize the AlgorithmBase class.
- Parameters:
info (odatse.Info) – Information object containing algorithm parameters.
runner (odatse.Runner, optional) – Runner object for executing the algorithm (default is None).
domain (optional) – Domain object defining the problem space (default is None).
nwalkers (int, optional) – Number of walkers (default is 1).
run_mode (str, optional) – Mode of the run, e.g., “initial” (default is “initial”).
- _evaluate(in_range: ndarray = None) ndarray [source]
Evaluate the current “Energy”s.
This method overwrites self.fx with the result.
- Parameters:
in_range (np.ndarray, optional) – Array indicating whether each walker is within the valid range (default is None).
- Returns:
Array of evaluated energies for the current configurations.
- Return type:
np.ndarray
- _initialize()[source]
Initialize the algorithm state.
This method sets up the initial state of the algorithm, including the positions and energies of the walkers, and resets the counters for accepted and trial steps.
- _setup_neighbour(info_param)[source]
Set up the neighbor list for the discrete problem.
- Parameters:
info_param (dict) – Dictionary containing algorithm parameters, including the path to the neighbor list file.
- Raises:
ValueError – If the neighbor list path is not specified in the parameters.
RuntimeError – If the transition graph made from the neighbor list is not connected or not bidirectional.
- _write_result(fp, extra_info_to_write: List | Tuple = None) None [source]
Write the result of the current step to the file.
- Parameters:
fp (TextIO) – File pointer to the result file.
extra_info_to_write (Union[List, Tuple], optional) – Additional information to write for each walker (default is None).
- _write_result_header(fp, extra_names=None) None [source]
Write the header for the result file.
- Parameters:
fp (TextIO) – File pointer to the result file.
extra_names (list of str, optional) – Additional column names to include in the header.
- local_update(beta: float | ndarray, file_trial: TextIO, file_result: TextIO, extra_info_to_write: List | Tuple = None)[source]
one step of Monte Carlo
- Parameters:
beta (np.ndarray) – inverse temperature for each walker
file_trial (TextIO) – log file for all trial points
file_result (TextIO) – log file for all generated samples
extra_info_to_write (List of np.ndarray or tuple of np.ndarray) – extra information to write
- odatse.algorithm.montecarlo.read_Ts(info: dict, numT: int = None) Tuple[bool, ndarray] [source]
Read temperature or inverse-temperature values from the provided info dictionary.
- Parameters:
info (dict) – Dictionary containing temperature or inverse-temperature parameters.
numT (int, optional) – Number of temperature or inverse-temperature values to generate (default is None).
- Returns:
as_beta (bool) – True if using inverse-temperature, False if using temperature.
betas (np.ndarray) – Sequence of inverse-temperature values.
- Raises:
ValueError – If numT is not specified, or if both Tmin/Tmax and bmin/bmax are defined, or if neither are defined, or if bmin/bmax or Tmin/Tmax values are invalid.
RuntimeError – If the mode is unknown (neither set_T nor set_b).