pyrevs.strategies

Set of sampling strategies for pyREVS.

Submodules

Classes

AMS

A strategy class implementing (T)AMS.

MonteCarlo

A strategy class implementing MonteCarlo.

Package Contents

class AMS(fmodel_t: Any, runtime_cfg: pyrevs.core.RuntimeConfig, runner_cfg: pyrevs.runner.RunnerConfig, strategy_cfg: pyrevs.strategies.ams.config.AMSConfig, deterministic: bool)[source]

Bases: pyrevs.strategies.base.BaseSamplingStrategy

A strategy class implementing (T)AMS.

The interface to (T)AMS, implementing the main steps of the algorithm.

Initialization of the (T)AMS class requires a forward model type which encapsulate all the model-specific code, and an optional list of options.

The algorithm is roughly divided in two steps: 1. Initialization of the trajectory ensemble 2. Splitting iterations

Separate control of the parallelism is provided for both steps.

All the algorithm data are contained in the (T)AMS database. For control purposes, a walltime limit is also provided. It is passed to working and lead to the termination of the algorithm in a state that can be saved to disk and restarted at a later stage.

Variables:
  • _fmodel_t – the forward model type

  • _config – the config object

  • _wallTime – the walltime limit

  • _init_ensemble_only – whether or not to stop after initializing the trajectory ensemble

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

Schedule the generation of an ensemble of stochastic trajectories.

Loop over all the trajectories in the database and schedule advancing them to either end time or convergence with the runner.

The runner will use the number of workers specified in the input file under the runner section.

Parameters:

tdb – the AMS database

Raises:

Error if the runner fails

check_exit_splitting_loop(tdb: pyrevs.database.Database, k: int) tuple[bool, numpy.typing.NDArray[numpy.number]][source]

Check for exit criterion of the splitting loop.

Parameters:
  • tdb – the AMS database

  • k – loop counter

Returns:

bool to trigger splitting loop break array of maximas across all trajectories

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

Check and finish unfinished splitting iterations.

If the run was interrupted during a splitting iteration, the branched trajectories might not have terminated yet. In that case, a list of trajectories to finish is listed in the database.

get_restart_at_random(tdb: pyrevs.database.Database, min_idx_list: list[int]) list[int][source]

Get a list of trajectory index to restart from at random.

Select trajectories to restart from among the ones not in min_idx_list.

Parameters:
  • tdb – the AMS database

  • min_idx_list – list of trajectory index to restart from

Returns:

list of trajectory index to restart from

do_multilevel_splitting(tdb: pyrevs.database.Database, plot_diags: bool) None[source]

Schedule splitting of the initial ensemble of stochastic trajectories.

Perform the multi-level splitting iterations, possibly restarting multiple trajectories at each iterations. All the trajectories in an iterations are advanced together, such that each iteration takes the maximum duration among the branched trajectories.

If the walltime is exceeded, the splitting loop is stopped and ongoing trajectories are flagged in the database in order to finish them upon restart.

The runner will use the number of workers specified in the input file under the runner section.

Parameters:
  • tdb – the AMS database

  • plot_diags – whether or not to plot diagnostics

Raises:

Error if the runner fails

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

Compute the probability using AMS.

Parameters:
  • tdb – the AMS database

  • plot_diags – whether or not to plot diagnostics

Returns:

the rare-event probability

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

Initialize database core state.

class MonteCarlo(fmodel_t: Any, runtime_cfg: pyrevs.core.RuntimeConfig, runner_cfg: pyrevs.runner.RunnerConfig, strategy_cfg: pyrevs.strategies.montecarlo.config.MCConfig, deterministic: bool)[source]

Bases: pyrevs.strategies.base.BaseSamplingStrategy

A strategy class implementing MonteCarlo.

Monte-Carlo or Direct Numerical Simulation (DNS) is not per-se a sampling strategy tailored for rare events but it provides a baseline for comparison with other sampling strategies.

An ensemble of size n_traj is constructed and the rare-event probability is simply computed as the ratio of the number of converged trajectories to the total number of trajectories in the ensemble n_traj.

In practice, this is the first step of a TAMS or AMS run (depending on the termination condition), such that this class is a lightweight version of these other strategies.

Notes

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

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

Schedule the generation of an ensemble of stochastic trajectories.

Loop over all the trajectories in the database and schedule advancing them to either end time or convergence with the runner.

The runner will use the number of workers specified in the input file under the runner section.

Raises:

Error if the runner fails

compute_probability(tdb: pyrevs.database.Database) float[source]

Compute the rare-event probability using MonteCarlo.

Returns:

the rare-event probability

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

Initialize database core state.