pytams.database

A database class for TAMS.

Exceptions

DatabaseError

Exception class for TAMS Database.

Classes

Database

A database class for TAMS.

Module Contents

exception DatabaseError[source]

Bases: Exception

Exception class for TAMS Database.

class Database(fmodel_t: type[pytams.fmodel.ForwardModelBaseClass], params: dict[Any, Any], ntraj: int | None = None, nsplititer: int | None = None)[source]

A database class for TAMS.

The database class for TAMS is a container for all the trajectory and splitting data. When the user provides a path to store the database, a local folder is created holding a number of readable files, any output from the model and an SQL file used to lock/release trajectories as the TAMS algorithm proceeds.

The readable files are currently in an XML format.

A database can be loaded independently from the TAMS algorithm and used for post-processing.

Variables:
  • _fmodel_t – the forward model type

  • _save_to_disk – boolean to trigger saving the database to disk

  • _path – a path to an existing database to restore or a new path

  • _restart – a bool to override an existing database

  • _parameters – the dictionary of parameters

  • _trajs_db – the list of trajectories

  • _ksplit – the current splitting iteration

  • _l_bias – the list of bias

  • _weights – the list of weights

  • _ongoing – the list of ongoing branches if unfinished splitting iteration.

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

n_split_iter() int[source]

Return the number of splitting iteration used for TAMS.

Note that this is the requested number of splitting iteration, not the current splitting iteration.

Returns:

number of splitting iteration

path() str | None[source]

Return the path to the database.

classmethod load(a_path: pathlib.Path) Database[source]

Instanciate a TAMS database from disk.

Parameters:

a_path – the path to the database

Returns:

a TAMS database object

init_pool() None[source]

Initialize the requested number of trajectories.

save_trajectory(traj: pytams.trajectory.Trajectory) None[source]

Save a trajectory to disk in the database.

Parameters:

traj – the trajectory to save

save_splitting_data(ongoing_trajs: list[int] | None = None) None[source]

Write splitting data to the database.

Parameters:

ongoing_trajs – an optional list of ongoing trajectories

load_data(load_archived_trajectories: bool = False) None[source]

Load data stored into the database.

The initialization of the database only populate the metadata but not the full trajectories data.

Parameters:

load_archived_trajectories – whether to load archived trajectories

name() str[source]

Accessor to DB name.

Returns:

DB name

append_traj(a_traj: pytams.trajectory.Trajectory, update_db: bool) None[source]

Append a Trajectory to the internal list.

Parameters:
  • a_traj – the trajectory

  • update_db – True to update the SQL DB content

traj_list() list[pytams.trajectory.Trajectory][source]

Access to the trajectory list.

Returns:

Trajectory list

get_traj(idx: int) pytams.trajectory.Trajectory[source]

Access to a given trajectory.

Parameters:

idx – the index

Returns:

Trajectory

Raises:

ValueError if idx is out of range

overwrite_traj(idx: int, traj: pytams.trajectory.Trajectory) None[source]

Deep copy a trajectory into internal list.

Parameters:
  • idx – the index of the trajectory to override

  • traj – the new trajectory

Raises:

ValueError if idx is out of range

header_file() str[source]

Helper returning the DB header file.

Returns:

Header file

pool_file() str[source]

Helper returning the DB trajectory pool file.

Returns:

Pool file

is_empty() bool[source]

Check if list of trajectories is empty.

Returns:

True if the list of trajectories is empty

traj_list_len() int[source]

Length of the trajectory list.

Returns:

Trajectory list length

archived_traj_list_len() int[source]

Length of the archived trajectory list.

Returns:

Trajectory list length

update_traj_list(a_traj_list: list[pytams.trajectory.Trajectory]) None[source]

Overwrite the trajectory list.

Parameters:

a_traj_list – the new trajectory list

archive_trajectory(traj: pytams.trajectory.Trajectory) None[source]

Archive a trajectory about to be discarded.

Parameters:

traj – the trajectory to archive

lock_trajectory(tid: int, allow_completed_lock: bool = False) bool[source]

Lock a trajectory in the SQL DB.

Parameters:
  • tid – the trajectory id

  • allow_completed_lock – True if the trajectory can be locked even if it is completed

Returns:

True if no disk DB and the trajectory was locked

Raises:

SQLAlchemyError if the DB could not be accessed

unlock_trajectory(tid: int, has_ended: bool) None[source]

Unlock a trajectory in the SQL DB.

Parameters:
  • tid – the trajectory id

  • has_ended – True if the trajectory has ended

Raises:

SQLAlchemyError if the DB could not be accessed

update_trajectory_file(traj_id: int, checkfile: pathlib.Path) None[source]

Update a trajectory file in the DB.

Parameters:
  • traj_id – The trajectory id

  • checkfile – The new checkfile of that trajectory

Raises:

SQLAlchemyError if the DB could not be accessed

weights() list[float][source]

Splitting iterations weights.

append_weight(weight: float) None[source]

Append a weight to internal list.

biases() list[int][source]

Splitting iterations biases.

append_bias(bias: int) None[source]

Append a bias to internal list.

append_minmax(ksplit: int, minofmaxes: numpy.number, maxofmaxes: numpy.number) None[source]

Append min/max of maxes to internal list.

k_split() int[source]

Splitting iteration counter.

done_with_splitting() bool[source]

Check if we are done with splitting.

reset_ongoing() None[source]

Reset the list of trajectories undergoing branching.

get_ongoing() list[int] | None[source]

Return the list of trajectories undergoing branching or None.

set_k_split(ksplit: int) None[source]

Set splitting iteration counter.

count_ended_traj() int[source]

Return the number of trajectories that ended.

count_converged_traj() int[source]

Return the number of trajectories that converged.

get_transition_probability() float[source]

Return the transition probability.

info() None[source]

Print database info to screen.

plot_score_functions(fname: str | None = None, plot_archived: bool = False) None[source]

Plot the score as function of time for all trajectories.