pytams.diagdb

A class for the TAMS data as an SQL database using SQLAlchemy.

Classes

DiagBase

A base class for the tables.

DiagnosticEntry

Table for recording model data at specific score levels.

DiagDB

A database to keep track of the diagnostics data.

Module Contents

class DiagBase[source]

Bases: sqlalchemy.orm.DeclarativeBase

A base class for the tables.

class DiagnosticEntry[source]

Bases: DiagBase

Table for recording model data at specific score levels.

id: sqlalchemy.orm.Mapped[int][source]
traj_id: sqlalchemy.orm.Mapped[int][source]
level_crossed: sqlalchemy.orm.Mapped[float][source]
time: sqlalchemy.orm.Mapped[float][source]
weight: sqlalchemy.orm.Mapped[float][source]
model_data: sqlalchemy.orm.Mapped[bytes][source]
active: sqlalchemy.orm.Mapped[bool][source]
diaglabel: sqlalchemy.orm.Mapped[str][source]
class DiagDB(file_name: str, in_memory: bool = False, ro_mode: bool = False)[source]

Bases: pytams.sqlmanager.BaseSQLManager

A 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).

dump_to_json(json_path: str) None[source]

Export the entire diagnostic database to a JSON file.

Note that the content of the data stored in the database is omitted. Only the metadata of each stored data is dumpe for debuggin purposes.

close() None[source]

Dispose of the engine and clear connections.