pyrevs.strategies.gktl

Submodules

Classes

GKTLConfig

GKTL strategy configuration.

GKTLDatabaseExtension

An extension class for the GKTL strategy.

GKTL

A strategy class implementing GKTL.

Functions

load_database_extension(tdb) → extension.GKTLDatabaseExtension

A factory function to instanciate the extension from the database.

Package Contents

class GKTLConfig[source]

GKTL strategy configuration.

ntrajectories: int = -1
end_time: float = -1.0
resampling_interval: float = -1.0
k: float = 0.01
bias_observable: str = 'integral'
use_custom_termination: bool = False
target_score: float | None = None
validate() → None[source]

Validate GKTL configuration.

class GKTLDatabaseExtension[source]

Bases: pyrevs.database.StrategyDatabaseExtension

An extension class for the GKTL strategy.

An extension of the database to store GKTL-specific data. To be able to checkpoint a sampling run with GKTL, and to compute unbiased estimates from the biased ensemble, one need to store/read the following attributes.

At each resampling step n, the clone weights are W_i = exp(k * dA_i) and the normalization factor is R_n = mean(W_i). The (unbiased) estimate of the expectation of an observable O of the trajectories is then:

E[O] = 1/N sum_i O_i exp(-log_tilt_i) prod_n R_n

where log_tilt_i = k * sum_n dA_i,n along the ancestry of clone i.

Variables:
  • _iteration_count – number of completed resampling steps

  • _cur_time – time of the last resampling step

  • _k – the bias amplitude

  • _log_norm – log of the normalization factor R_n of each resampling step

  • _log_tilt – accumulated log-tilt of each clone along its ancestry

  • _window_start – start time of the current resampling interval for each clone

  • _ancestors – parent index of each clone, for each resampling step

  • _times – time of each resampling step

initialize(tdb: pyrevs.database.Database, k: float) → None[source]

Initialize the GKTL database extension.

If an on-disk database with GKTL metadata already exists, the extension state is read from disk to enable restarts.

Parameters:
  • tdb – the core trajectory database

  • k – the bias amplitude

initialize_from_database(tdb: pyrevs.database.Database) → None[source]

Initialize the GKTL database extension from an existing database.

Parameters:

tdb – the core trajectory database

serialize() → None[source]

Serialize the extension.

deserialize() → None[source]

Deserialize the extension.

iteration_count() → int[source]

Return the number of completed resampling steps.

current_time() → float[source]

Return the time of the last resampling step.

window_start() → list[float][source]

Return the start time of the current resampling interval for each clone.

ancestors() → list[list[int]][source]

Return the parent index of each clone, for each resampling step.

log_normalization() → list[float][source]

Return the log of the normalization factor of each resampling step.

record_resampling(delta_a: numpy.typing.NDArray[numpy.number], parents: list[int], window_start: list[float], time: float) → None[source]

Record a resampling step and update the clones tilt.

Parameters:
  • delta_a – the observable increment of each clone over the interval (before resampling)

  • parents – the parent index of each clone after resampling

  • window_start – the start time of the next interval for each clone

  • time – the time of the resampling step

clone_weights() → numpy.typing.NDArray[numpy.number][source]

Return the estimator weight of each clone in the current ensemble.

The weights sum to one in expectation (exactly for k = 0).

get_exceedance_probability(threshold: float) → float[source]

Return the probability that the score maximum exceeds a threshold.

Parameters:

threshold – the score threshold

Returns:

the unbiased estimate of P(max score >= threshold)

get_event_probability() → float[source]

Return the event probability.

The event is the convergence of the trajectory (i.e. reaching the target score) within the sampling end time. Without a target score, trajectories never converge and the probability is zero.

class GKTL(fmodel_t: Any, runtime_cfg: pyrevs.core.RuntimeConfig, runner_cfg: pyrevs.runner.RunnerConfig, strategy_cfg: pyrevs.strategies.gktl.config.GKTLConfig, deterministic: bool)[source]

Bases: pyrevs.strategies.base.BaseSamplingStrategy

A strategy class implementing GKTL.

The Giardina-Kurchan-Lecomte-Tailleur algorithm evolves an ensemble of trajectories and, at fixed resampling intervals, kills or clones each of them according to a weight exp(k * dA), where dA is an observable increment over the interval. This biases the ensemble toward large values of the observable. The bias is accounted for when computing estimates (see GKTLDatabaseExtension).

If a target score is set, trajectories that converge (reach the target score) before the end time are frozen: their observable increment is zero over later intervals. Without a target score, trajectories never converge.

Notes

This strategy relies on time management provided by BaseSamplingStrategy (e.g. self._end_date, elapsed_time()).

run_gktl(database: pyrevs.database.Database, plot_diags: bool) → bool[source]

Run the GKTL resampling loop.

Advance the ensemble of trajectories interval by interval, resampling the ensemble at the end of each interval (except the last one). The loop resumes from the last completed resampling step when restarting from an existing database.

Parameters:
  • database – the sampling database

  • plot_diags – whether to plot diagnostics

Returns:

True if the end time was reached (or all trajectories terminated)

Raises:

RuntimeError if the runner fails –

compute_probability(database: pyrevs.database.Database, plot_diags: bool) → float[source]

Compute the rare-event probability using GKTL.

Parameters:
  • database – the trajectory database

  • plot_diags – whether to plot diagnostics

Returns:

the rare-event probability, or -1.0 if the run did not complete

initialize_database_schema(database: pyrevs.database.Database, diag_configs: dict[str, pyrevs.core.Config] | None) → None[source]

Initialize database core state.

load_database_extension(tdb: pyrevs.database.Database) → extension.GKTLDatabaseExtension[source]

A factory function to instanciate the extension from the database.