pyrevs.runner.worker

A set of functions used by pyREVS workers.

Functions

get_coredb(trajdb_path) → pyrevs.core.CoreDB

Return a handle to the SQL database of trajectories.

update_trajectory_in_sql(traj[, trajdb, db_path]) → None

Wrapper for update SQL trajectory info.

traj_advance_with_exception(traj, ...[, trajdb, db_path]) → pyrevs.trajectory.Trajectory

Advance a trajectory with exception handling.

pool_worker(traj, termination_criteria, end_date[, ...]) → pyrevs.trajectory.Trajectory

A worker to generate each initial trajectory.

ms_worker(from_traj, rst_traj, min_val, new_weight, ...) → pyrevs.trajectory.Trajectory

A worker to restart trajectories.

worker_async(queue, res_queue, executor) → None

An async worker for the asyncio taskrunner.

Module Contents

get_coredb(trajdb_path: str) → pyrevs.core.CoreDB[source]

Return a handle to the SQL database of trajectories.

Opening the database is costly compared to the work done by a worker on small models: the handle is cached in worker (child) processes, which only live for the duration of a runner. It is not cached in the main process, which might run several samplers on the same path, nor on Windows where open handles might lock the database file.

Parameters:

trajdb_path – the path to the SQL database

update_trajectory_in_sql(traj: pyrevs.trajectory.Trajectory, trajdb: pyrevs.core.CoreDB | None = None, db_path: str | None = None) → None[source]

Wrapper for update SQL trajectory info.

Parameters:
  • trajdb – the SQL database to update

  • traj – the traj to get the information from

  • db_path – an optional pyREVS database path

traj_advance_with_exception(traj: pyrevs.trajectory.Trajectory, termination_criteria: list[pyrevs.strategies.base.TerminationCriterion], walltime: float, trajdb: pyrevs.core.CoreDB | None = None, db_path: str | None = None) → pyrevs.trajectory.Trajectory[source]

Advance a trajectory with exception handling.

Parameters:
  • traj – a trajectory

  • termination_criteria – a list of termination criterion for the advance call

  • walltime – the time limit to advance the trajectory

  • trajdb – a handle to the SQL database

  • db_path – an optional path to the run database

Returns:

The updated trajectory

pool_worker(traj: pyrevs.trajectory.Trajectory, termination_criteria: list[pyrevs.strategies.base.TerminationCriterion], end_date: datetime.date, trajdb_path: str | None = None, db_path: str | None = None) → pyrevs.trajectory.Trajectory[source]

A worker to generate each initial trajectory.

Parameters:
  • traj – a trajectory

  • termination_criteria – a list of termination criterion for the advance call

  • end_date – the time limit to advance the trajectory

  • trajdb_path – an optional path to the SQL database

  • db_path – an optional path to the run database

Returns:

The updated trajectory

ms_worker(from_traj: pyrevs.trajectory.Trajectory, rst_traj: pyrevs.trajectory.Trajectory, min_val: float, new_weight: float, termination_criteria: list[pyrevs.strategies.base.TerminationCriterion], end_date: datetime.date, trajdb_path: str | None = None, db_path: str | None = None) → pyrevs.trajectory.Trajectory[source]

A worker to restart trajectories.

Parameters:
  • from_traj – a trajectory to restart from

  • rst_traj – the trajectory being restarted

  • min_val – the value of the score function to restart from

  • new_weight – the weight of the new child trajectory

  • termination_criteria – a list of termination criterion for the advance call

  • end_date – the time limit to advance the trajectory

  • trajdb_path – a path to the SQL database

  • db_path – an optional path to the run database

async worker_async(queue: asyncio.Queue[tuple[collections.abc.Callable[..., Any], pyrevs.trajectory.Trajectory, float, bool, str]], res_queue: asyncio.Queue[asyncio.Future[pyrevs.trajectory.Trajectory]], executor: concurrent.futures.Executor) → None[source]

An async worker for the asyncio taskrunner.

It wraps the call to one of the above worker functions with access to the queue.

Parameters:
  • queue – a queue from which to get tasks

  • res_queue – a queue to put the results in

  • executor – an executor to launch the work in