pytams.sqldb

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

Attributes

Classes

Base

A base class for the tables.

Trajectory

A table storing the trajectories.

ArchivedTrajectory

A table storing the archived trajectories.

SQLFile

An SQL file.

Module Contents

class Base[source]

Bases: sqlalchemy.orm.DeclarativeBase

A base class for the tables.

class Trajectory[source]

Bases: Base

A table storing the trajectories.

id: sqlalchemy.orm.Mapped[int][source]
traj_file: sqlalchemy.orm.Mapped[str][source]
status: sqlalchemy.orm.Mapped[str][source]
class ArchivedTrajectory[source]

Bases: Base

A table storing the archived trajectories.

id: sqlalchemy.orm.Mapped[int][source]
traj_file: sqlalchemy.orm.Mapped[str][source]
valid_statuses = ['locked', 'idle', 'completed'][source]
class SQLFile(file_name: str)[source]

An SQL file.

Allows atomic access to an SQL database from all the workers.

Note: TAMS works with Python indexing starting at 0, while SQL indexing starts at 1. Trajectory ID is updated accordingly when accessing/updating the DB.

Variables:

_file_name – The file name

add_trajectory(traj_file: str) None[source]

Add a new trajectory to the DB.

Parameters:

traj_file – The trajectory file of that trajectory

Raises:

SQLAlchemyError if the DB could not be accessed

update_trajectory_file(traj_id: int, traj_file: str) None[source]

Update a trajectory file in the DB.

Parameters:
  • traj_id – The trajectory id

  • traj_file – The new trajectory file of that trajectory

Raises:

SQLAlchemyError if the DB could not be accessed

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

Set the status of a trajectory to “locked” if possible.

Parameters:
  • traj_id – The trajectory id

  • allow_completed_lock – Allow to lock a “completed” trajectory

Returns:

True if the trajectory was successfully locked, False otherwise

Raises:
  • ValueError if the trajectory with the given id does not exist

  • SQLAlchemyError if the DB could not be accessed

mark_trajectory_as_completed(traj_id: int) None[source]

Set the status of a trajectory to “completed” if possible.

Parameters:

traj_id – The trajectory id

Raises:
  • ValueError if the trajectory with the given id does not exist

  • SQLAlchemyError if the DB could not be accessed

release_trajectory(traj_id: int) None[source]

Set the status of a trajectory to “idle” if possible.

Parameters:

traj_id – The trajectory id

Raises:

ValueError if the trajectory with the given id does not exist

get_trajectory_count() int[source]

Get the number of trajectories in the DB.

Returns:

The number of trajectories

fetch_trajectory(traj_id: int) str[source]

Get the trajectory file of a trajectory.

Parameters:

traj_id – The trajectory id

Returns:

The trajectory file

Raises:

ValueError if the trajectory with the given id does not exist

release_all_trajectories() None[source]

Release all trajectories in the DB.

archive_trajectory(traj_file: str) None[source]

Add a new trajectory to the archive container.

Parameters:

traj_file – The trajectory file of that trajectory

fetch_archived_trajectory(traj_id: int) str[source]

Get the trajectory file of a trajectory in the archive.

Parameters:

traj_id – The trajectory id

Returns:

The trajectory file

Raises:

ValueError if the trajectory with the given id does not exist

get_archived_trajectory_count() int[source]

Get the number of trajectories in the archive.

Returns:

The number of trajectories

dump_file_json() None[source]

Dump the content of the trajectory table to a json file.