Skip to content

Commit 8d4a139

Browse files
committed
docs: add numpy docstrings
1 parent e79a8dd commit 8d4a139

File tree

2 files changed

+102
-3
lines changed

2 files changed

+102
-3
lines changed

src/openfe/orchestration/__init__.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Task orchestration utilities backed by Exorcist and a warehouse."""
2+
13
from dataclasses import dataclass
24
from pathlib import Path
35

@@ -21,10 +23,29 @@
2123

2224
@dataclass
2325
class Worker:
26+
"""Execute protocol units from an Exorcist task database.
27+
28+
Parameters
29+
----------
30+
warehouse : FileSystemWarehouse
31+
Warehouse used to load queued tasks and store execution results.
32+
task_db_path : pathlib.Path, default=Path("./warehouse/tasks.db")
33+
Path to the Exorcist SQLite task database.
34+
"""
35+
2436
warehouse: FileSystemWarehouse
2537
task_db_path: Path = Path("./warehouse/tasks.db")
2638

2739
def _checkout_task(self) -> tuple[str, ProtocolUnit] | None:
40+
"""Check out one available task and load its protocol unit.
41+
42+
Returns
43+
-------
44+
tuple[str, ProtocolUnit] or None
45+
The checked-out task ID and corresponding protocol unit, or
46+
``None`` if no task is currently available.
47+
"""
48+
2849
db: TaskStatusDB = TaskStatusDB.from_filename(self.task_db_path)
2950
# The format for the taskid is "Transformation-<HASH>:ProtocolUnit-<HASH>"
3051
taskid = db.check_out_task()
@@ -36,13 +57,46 @@ def _checkout_task(self) -> tuple[str, ProtocolUnit] | None:
3657
return taskid, unit
3758

3859
def _get_task(self) -> ProtocolUnit:
60+
"""Return the next available protocol unit.
61+
62+
Returns
63+
-------
64+
ProtocolUnit
65+
A protocol unit loaded from the warehouse.
66+
67+
Raises
68+
------
69+
RuntimeError
70+
Raised when no task is available in the task database.
71+
"""
72+
3973
task = self._checkout_task()
4074
if task is None:
4175
raise RuntimeError("No AVAILABLE tasks found in the task database.")
4276
_, unit = task
4377
return unit
4478

4579
def execute_unit(self, scratch: Path) -> tuple[str, ProtocolUnitResult] | None:
80+
"""Execute one checked-out protocol unit and persist its result.
81+
82+
Parameters
83+
----------
84+
scratch : pathlib.Path
85+
Scratch directory passed to the protocol execution context.
86+
87+
Returns
88+
-------
89+
tuple[str, ProtocolUnitResult] or None
90+
The task ID and execution result for the processed task, or
91+
``None`` if no task is currently available.
92+
93+
Raises
94+
------
95+
Exception
96+
Re-raises any exception thrown during protocol unit execution after
97+
marking the task as failed.
98+
"""
99+
46100
# 1. Get task/unit
47101
task = self._checkout_task()
48102
if task is None:

src/openfe/orchestration/exorcist_utils.py

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
"""Utilities for building Exorcist task graphs and task databases."""
1+
"""Utilities for building Exorcist task graphs and task databases.
2+
3+
This module translates an :class:`gufe.AlchemicalNetwork` into Exorcist task
4+
structures and can initialize an Exorcist task database from that graph.
5+
"""
26

37
from pathlib import Path
48

@@ -12,7 +16,28 @@
1216
def alchemical_network_to_task_graph(
1317
alchemical_network: AlchemicalNetwork, warehouse: WarehouseBaseClass
1418
) -> nx.DiGraph:
15-
"""Build a global task DAG from an AlchemicalNetwork."""
19+
"""Build a global task DAG from an alchemical network.
20+
21+
Parameters
22+
----------
23+
alchemical_network : AlchemicalNetwork
24+
Network containing transformations to execute.
25+
warehouse : WarehouseBaseClass
26+
Warehouse used to persist protocol units as tasks while the graph is
27+
constructed.
28+
29+
Returns
30+
-------
31+
nx.DiGraph
32+
A directed acyclic graph where each node is a task ID in the form
33+
``"<transformation_key>:<protocol_unit_key>"`` and edges encode
34+
protocol-unit dependencies.
35+
36+
Raises
37+
------
38+
ValueError
39+
Raised if the assembled task graph is not acyclic.
40+
"""
1641

1742
global_dag = nx.DiGraph()
1843
for transformation in alchemical_network.edges:
@@ -40,7 +65,27 @@ def build_task_db_from_alchemical_network(
4065
db_path: Path | None = None,
4166
max_tries: int = 1,
4267
) -> exorcist.TaskStatusDB:
43-
"""Create an Exorcist TaskStatusDB from an AlchemicalNetwork."""
68+
"""Create and populate a task database from an alchemical network.
69+
70+
Parameters
71+
----------
72+
alchemical_network : AlchemicalNetwork
73+
Network containing transformations to convert into task records.
74+
warehouse : WarehouseBaseClass
75+
Warehouse used to persist protocol units while building the task DAG.
76+
db_path : pathlib.Path or None, optional
77+
Location of the SQLite-backed Exorcist database. If ``None``, defaults
78+
to ``Path("tasks.db")`` in the current working directory.
79+
max_tries : int, default=1
80+
Maximum number of retries for each task before Exorcist marks it as
81+
``TOO_MANY_RETRIES``.
82+
83+
Returns
84+
-------
85+
exorcist.TaskStatusDB
86+
Initialized task database populated with graph nodes and dependency
87+
edges derived from ``alchemical_network``.
88+
"""
4489
if db_path is None:
4590
db_path = Path("tasks.db")
4691

0 commit comments

Comments
 (0)