pyrevs.strategies.montecarlo

Submodules

Classes

MCConfig

MC strategy configuration.

MCDatabaseExtension

An extension class for the MonteCarlo strategy.

MonteCarlo

A strategy class implementing MonteCarlo.

Functions

load_database_extension(→ extension.MCDatabaseExtension)

A factory function to instanciate the extension from the database.

Package Contents

class MCConfig[source]

MC strategy configuration.

ntrajectories: int = -1
end_time: float | None = None
validate() None[source]

Validate MC configuration.

class MCDatabaseExtension[source]

Bases: pyrevs.database.StrategyDatabaseExtension

An extension class for the MonteCarlo strategy.

The Monte-Carlo strategy has minimal extension requirements. It mostly provides a concrete implementation of the event probability computation method.

It only holds a reference to the core trajectory database.

Variables:

_tdb – the core trajectory database

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

Initialize the AMS database extension.

Parameters:

tdb – the core trajectory database

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

Initialize the AMS database extension.

Parameters:

tdb – the core trajectory database

serialize() None[source]

Serialize the extension.

deserialize() None[source]

Serialize the extension.

get_event_probability() float[source]

Return the event probability.

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.

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

A factory function to instanciate the extension from the database.