pytams.diagdb¶
A class for the TAMS data as an SQL database using SQLAlchemy.
Classes¶
A base class for the tables. |
|
Table for recording model data at specific score levels. |
|
A database to keep track of the diagnostics data. |
Module Contents¶
- class DiagnosticEntry[source]¶
Bases:
DiagBaseTable for recording model data at specific score levels.
- class DiagDB(file_name: str, in_memory: bool = False, ro_mode: bool = False)[source]¶
Bases:
pytams.sqlmanager.BaseSQLManagerA database to keep track of the diagnostics data.
Diagnostic entries are agregated in single table. Each entry is associated to a trajectory and its weight in the ensemble.
- add_diagnostic_entry(diaglabel: str, traj_id: int, level: float, time: float, weight: float, ldata: bytes) None[source]¶
Atomic insert of a diagnostic snapshot.
The data schema assumes that any new addition to the database is made on an active trajectory.
- Parameters:
diaglabel – the label of the diagnostic inserting the entry
traj_id – the ID of the traj adding the entry
level – the score level of the entry
time – the trajectory time at which the diagnostic was triggered
weight – the weight of the trajectory
ldata – the actual model data stored in the database
- get_highest_recorded_level(traj_id: int, label: str) float[source]¶
Return the maximum level already recorded for this traj/label.
- Parameters:
traj_id – the ID of a trajectory
label – the label of the diagnostic targeter
- Returns:
the highest value of level_crossed
- duplicate_diagnostic_history(ancestor_id: int, discarded_id: int, new_id: int, new_weight: float, threshold: float) int[source]¶
Copy diagnostic entries from an ancestor to a descendant.
Copies all entries where level_crossed <= threshold. Returns the number of entries duplicated.
The entries belonging to the discarded trajectory are set to inactive.
- Parameters:
ancestor_id – the ID of the ancestor to copy data from
discarded_id – the ID of the discarded trajectory (during TAMS iterations)
new_id – the ID of the new child trajectory
new_weight – the weight of the new child trajectory
threshold – the score threshold up to which copy must be performed
- update_all_active_weights(new_weight: float) int[source]¶
Update all the active trajectories weight.
- Parameters:
new_weight – the updated weight
- Returns:
the number of trajectory updated
- get_diagnostic_data(label: str) dict[float, list[tuple[Any, float]]][source]¶
Retrieve all diagnostic snapshots for a specific label.
- Parameters:
label – the label of the diagnostic of interest
- Returns:
A dictionary mapping each iso-level (float) to a list of tuples. Each tuple contains (unpickled_data, trajectory_weight).