pytams.database¶
A database class for TAMS.
Exceptions¶
Exception class for TAMS Database. |
Classes¶
A database class for TAMS. |
Module Contents¶
- 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
- 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
- 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
- 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 –
- is_empty() bool [source]¶
Check if list of trajectories is empty.
- Returns:
True if the list of trajectories is empty
- 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 –
- append_minmax(ksplit: int, minofmaxes: numpy.number, maxofmaxes: numpy.number) None [source]¶
Append min/max of maxes to internal list.