odatse.algorithm.pamc module

class odatse.algorithm.pamc.Algorithm(info: Info, runner: Runner = None, run_mode: str = 'initial')[source]

Bases: AlgorithmBase

Population annealing Monte Carlo

x

current configuration

Type:

np.ndarray

fx

current “Energy”

Type:

np.ndarray

logweights

current logarithm of weights (Neal-Jarzynski factor)

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

Type:

int

comm

MPI communicator

Type:

MPI.comm

nreplica

The number of replicas (= the number of procs)

Type:

int

rank

MPI rank

Type:

int

betas

List of inverse temperatures

Type:

list

Tindex

Temperature index

Type:

int

Initialize the Algorithm class.

Parameters:
  • info (odatse.Info) – Information object containing algorithm parameters.

  • runner (odatse.Runner, optional) – Runner object for executing the algorithm, by default None.

  • run_mode (str, optional) – Mode in which to run the algorithm, by default “initial”.

__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, by default None.

  • run_mode (str, optional) – Mode in which to run the algorithm, by default “initial”.

_find_scheduling(info_pamc) int[source]

Determine the scheduling for the algorithm based on the provided parameters.

Parameters:

info_pamc (dict) – Dictionary containing the parameters for the PAMC algorithm.

Returns:

The number of temperature steps (numT) determined from the input parameters.

Return type:

int

_gather_information(numT: int = None) Dict[str, ndarray][source]

Gather status information of each process

Parameters:

numT (int) – size of dataset

Returns:

res – key-value corresponding is the following

  • fxs
    • objective function of each walker over all processes

  • logweights
    • log of weights

  • ns
    • number of walkers in each process

  • ancestors
    • ancestor (origin) of each walker

  • acceptance ratio
    • acceptance_ratio for each temperature

Return type:

Dict[str, np.ndarray]

_initialize() None[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.

_load_state(filename, mode='resume', restore_rng=True)[source]

Load the saved state of the algorithm from a file.

Parameters:
  • filename (str) – The name of the file from which the state will be loaded.

  • mode (str, optional) – The mode in which to load the state. Can be “resume” or “continue”, by default “resume”.

  • restore_rng (bool, optional) – Whether to restore the random number generator state, by default True.

_post() None[source]

Post-processing after the algorithm execution.

This method consolidates the results from different temperature steps into single files for ‘result’ and ‘trial’. It also gathers the best results from all processes and writes them to ‘best_result.txt’.

_prepare() None[source]

Prepare the algorithm for execution.

This method initializes the timers for the ‘submit’ and ‘resampling’ phases of the algorithm run.

_resample() None[source]

Perform the resampling of walkers.

This method gathers information, saves statistical data, and performs resampling using either fixed or varied weights. The method ensures that the algorithm maintains a balanced set of walkers across different temperature steps.

_resample_fixed(weights: ndarray) None[source]

Perform resampling with fixed weights.

This method resamples the walkers based on the provided weights and updates the state of the algorithm accordingly.

Parameters:

weights (np.ndarray) – Array of weights for resampling.

_resample_varied(weights: ndarray, offset: int) None[source]

Perform resampling with varied weights.

This method resamples the walkers based on the provided weights and updates the state of the algorithm accordingly.

Parameters:
  • weights (np.ndarray) – Array of weights for resampling.

  • offset (int) – Offset for the weights array.

_run() None[source]

Abstract method to be implemented by subclasses for running steps.

_save_state(filename) None[source]

Save the current state of the algorithm to a file.

Parameters:

filename (str) – The name of the file where the state will be saved.

_save_stats(info: Dict[str, ndarray]) None[source]

Save statistical information from the algorithm run.

Parameters:

info (Dict[str, np.ndarray]) – Dictionary containing the following keys: - fxs: Objective function of each walker over all processes. - logweights: Logarithm of weights. - ns: Number of walkers in each process. - ancestors: Ancestor (origin) of each walker. - acceptance ratio: Acceptance ratio for each temperature.