pytams.tams

The main TAMS class.

Attributes

Classes

TAMS

A class implementing TAMS.

Functions

parse_cl_args(→ argparse.Namespace)

Parse provided list or default CL argv.

Module Contents

STALL_TOL = 1e-10[source]
parse_cl_args(a_args: list[str] | None = None) argparse.Namespace[source]

Parse provided list or default CL argv.

Parameters:

a_args – optional list of options

class TAMS(fmodel_t: Any, a_args: list[str] | None = None)[source]

A class implementing TAMS.

The interface to TAMS, implementing the main steps of the algorithm.

Initialization of the TAMS 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 pool 2. Splitting iterations

Separate control of the parallelism is provided for both steps.

All the algorithm data are contained in the TAMS 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

  • _parameters – the dictionary of parameters

  • _wallTime – the walltime limit

  • _startDate – the date the algorithm started

  • _plot_diags – whether or not to plot diagnostics during splitting iterations

  • _init_pool_only – whether or not to stop after initializing the trajectory pool

  • _tdb – the trajectory database (containing all trajectories)

n_traj() int[source]

Return the number of trajectory used for TAMS.

Note that this is the requested number of trajectory, not the current length of the trajectory pool.

Returns:

number of trajectory

elapsed_time() float[source]

Return the elapsed wallclock time.

Since the initialization of the TAMS object [seconds].

Returns:

TAMS elapse time.

Raises:

ValueError – if the start date is not set

remaining_walltime() float[source]

Return the remaining wallclock time.

[seconds]

Returns:

TAMS remaining wall time.

out_of_time() bool[source]

Return true if insufficient walltime remains.

Allows for 5% slack to allows time for workers to finish their work (especially with Dask+Slurm backend).

Returns:

boolean indicating wall time availability.

generate_trajectory_pool() None[source]

Schedule the generation of a pool 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

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

Check for exit criterion of the splitting loop.

Parameters:

k – loop counter

Returns:

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

finish_ongoing_splitting() None[source]

Check and finish unfinished splitting iterations.

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

get_restart_at_random(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:

min_idx_list – list of trajectory index to restart from

Returns:

list of trajectory index to restart from

do_multilevel_splitting() None[source]

Schedule splitting of the initial pool 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 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.

Raises:

Error if the runner fails

compute_probability() float[source]

Compute the probability using TAMS.

Returns:

the transition probability