radical.asyncflow.workflow_manager¶
WorkflowEngine ¶
WorkflowEngine(backend: Any = None, dry_run: bool = False, implicit_data: bool = True, uid: Optional[str] = None, work_dir: Optional[str] = None)
An asynchronous workflow manager that uses asyncio event loops and coroutines to manage and execute workflow components (blocks and/or tasks) within Directed Acyclic Graph (DAG) or Chain Graph (CG) structures.
This class provides async/await operations and handles task dependencies, input/output data staging, and execution.
Attributes:
| Name | Type | Description |
|---|---|---|
loop | AbstractEventLoop | The asyncio event loop (current running loop). |
backend | The execution backend used for task execution. | |
dry_run | bool | Indicates whether the engine is in dry-run mode. |
log | Logger | Logger instance for logging workflow events. |
prof | Profiler | Profiler instance for profiling workflow execution. |
Initialize the WorkflowEngine (sync part only).
Note: This is a private constructor. Use WorkflowEngine.create() instead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend | Any | Execution backend (required, pre-validated) | None |
dry_run | bool | Whether to run in dry-run mode | False |
implicit_data | bool | Whether to enable implicit data dependency linking | True |
uid | Optional[str] | Optional unique identifier for this engine. Defaults to | None |
work_dir | Optional[str] | Working directory for output files (default: cwd) | None |
Source code in doc_env/lib/python3.14/site-packages/radical/asyncflow/workflow_manager.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | |
start_telemetry async ¶
start_telemetry(resource_poll_interval: float = 5.0, checkpoint_interval: float | None = None, checkpoint_path: str | None = None, span_processors: list | None = None, metric_readers: list | None = None, resource: object | None = None) -> Any
Create and start a RHAPSODY TelemetryManager for this workflow engine.
Mirrors Session.start_telemetry(): creates the manager, wires all registered backends (silently skipping LocalExecutionBackend and NoopExecutionBackend which have no adapter), starts the async dispatch loop, and returns the manager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resource_poll_interval | float | Seconds between resource metric polls (default: 5.0). | 5.0 |
checkpoint_interval | float | None | Seconds between periodic metric+span flushes to disk. None = no periodic flush (file still written at stop). | None |
checkpoint_path | str | None | Directory for the JSONL checkpoint file. None = no file output. | None |
span_processors | list | None | Optional list of OTel SpanProcessor instances added to RHAPSODY's TracerProvider alongside the internal SpanBuffer. Callers own exporter construction. | None |
metric_readers | list | None | Optional list of OTel MetricReader instances added to RHAPSODY's MeterProvider alongside InMemoryMetricReader. | None |
resource | object | None | Optional | None |
Returns:
| Type | Description |
|---|---|
Any | The active TelemetryManager instance. |
Source code in doc_env/lib/python3.14/site-packages/radical/asyncflow/workflow_manager.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 | |
workflow_scope async ¶
workflow_scope(workflow_id: str | None = None) -> AsyncIterator[str]
Tag all tasks registered inside this scope with a shared workflow_id.
Also creates an OTel workflow span (when telemetry is active) so that task spans registered inside become structural children in the trace hierarchy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workflow_id | str | None | Explicit id for this workflow instance. If omitted, a short UUID is generated automatically. | None |
Yields:
| Type | Description |
|---|---|
AsyncIterator[str] | The workflow_id string in use. |
Source code in doc_env/lib/python3.14/site-packages/radical/asyncflow/workflow_manager.py
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 | |
create async classmethod ¶
create(backend: Any = None, dry_run: bool = False, implicit_data: bool = True, uid: Optional[str] = None, work_dir: Optional[str] = None) -> 'WorkflowEngine'
Factory method to create and initialize a WorkflowEngine.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend | Any | Execution backend. If None and dry_run=True, uses NoopExecutionBackend | None |
dry_run | bool | Whether to run in dry-run mode | False |
implicit_data | bool | Whether to enable implicit data dependency linking | True |
uid | Optional[str] | Optional unique identifier for this engine. Defaults to | None |
work_dir | Optional[str] | Working directory for output files (default: cwd) | None |
Returns:
| Name | Type | Description |
|---|---|---|
WorkflowEngine | 'WorkflowEngine' | Fully initialized workflow engine |
Example
engine = await WorkflowEngine.create(dry_run=True)
Source code in doc_env/lib/python3.14/site-packages/radical/asyncflow/workflow_manager.py
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 | |
run async ¶
run()
Manages asynchronous execution of workflow components.
Continuously monitors and manages workflow components, handling their dependencies and execution states. Performs dependency resolution and prepares components for execution when their dependencies are satisfied.
Workflow Process
- Monitors unresolved components
- Checks dependency resolution status
- Prepares resolved components for execution
- Handles data staging between components
- Submits ready components to execution
Raises:
| Type | Description |
|---|---|
CancelledError | If the coroutine is cancelled during execution |
State Management
- unresolved (set): Component UIDs with pending dependencies
- resolved (set): Component UIDs with satisfied dependencies
- running (list): Currently executing component UIDs
- dependencies (dict): Maps component UIDs to dependency info
- components (dict): Maps UIDs to component descriptions and futures
- queue (asyncio.Queue): Execution queue for ready components
Note
- Runs indefinitely until cancelled or shutdown is signaled
- Uses sleep intervals to prevent busy-waiting
- Handles both implicit and explicit data dependencies
- Trigger internal shutdown on loop failure
Source code in doc_env/lib/python3.14/site-packages/radical/asyncflow/workflow_manager.py
1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 | |
submit async ¶
submit(objects: list) -> None
Manages asynchronous submission of tasks/blocks to the execution backend.
Retrieves and submit ready tasks and blocks for execution. Separates incoming objects into tasks and blocks based on their UID pattern, and dispatches each to the appropriate backend method.
Submission Process
- Receive batch of objects
- Filters objects into tasks and blocks
- Submits tasks via
backend.submit_tasks - Submits blocks via
_submit_blocksasynchronously
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
objects | list | Tasks and blocks are identified by | required |
Returns:
| Type | Description |
|---|---|
None | None |
Raises:
| Type | Description |
|---|---|
Exception | If an unexpected error occurs during submission |
Source code in doc_env/lib/python3.14/site-packages/radical/asyncflow/workflow_manager.py
1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 | |
execute_block async ¶
execute_block(block_fut: Future, func: Callable, *args: Any, **kwargs: Any) -> None
Executes a block function and sets its result on the associated future.
Calls the given function with provided args, awaiting it if it's a coroutine, or running it in the executor otherwise. On completion, updates the block_fut with the result or exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
block_fut | Future | Future to store the result or exception. | required |
func | Callable | Function or coroutine function to execute. | required |
*args | Any | Positional arguments to pass to the function. | () |
**kwargs | Any | Keyword arguments to pass to the function. | {} |
Returns:
| Type | Description |
|---|---|
None | None |
Source code in doc_env/lib/python3.14/site-packages/radical/asyncflow/workflow_manager.py
1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 | |
handle_component_success ¶
handle_component_success(component: dict, component_fut: Future) -> None
Handles successful completion of a component (task or block).
Sets the result of the component's future: the function's return value for function tasks and blocks, or stdout for executable and prompt tasks. Logs a warning if the future is already resolved.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
component | dict | Completed component descriptor containing - 'uid' (str): Unique component identifier - 'return_value' / 'stdout': Result of the execution | required |
component_fut | Future | Future to set the result on. | required |
Source code in doc_env/lib/python3.14/site-packages/radical/asyncflow/workflow_manager.py
1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 | |
handle_component_failure ¶
handle_component_failure(component: dict, component_fut: Future, override_error_message: Union[str, Exception] = None) -> None
Handles failure of a component (task or block) and sets the exception.
Marks the component's future as failed by setting an exception derived from either a provided override error or the component's own recorded error/stderr. Logs a warning if the future is already resolved.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
component | dict | Dictionary with component details, including: - 'uid' (str): Unique component identifier - 'exception' or 'stderr': Error information from execution | required |
component_fut | Future | Future to mark as failed. | required |
override_error_message | Union[str, Exception] | Custom error message or exception to set instead of the recorded error. | None |
Returns:
| Type | Description |
|---|---|
None | None |
Source code in doc_env/lib/python3.14/site-packages/radical/asyncflow/workflow_manager.py
1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 | |
handle_component_cancellation ¶
handle_component_cancellation(component: dict, component_fut: Future)
Handle cancellation of a component (task or block).
Source code in doc_env/lib/python3.14/site-packages/radical/asyncflow/workflow_manager.py
1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 | |
task_callbacks ¶
task_callbacks(task: Any, state: str, service_callback: Optional[Callable] = None) -> None
Processes task state changes and invokes appropriate handlers.
Handles state transitions for tasks, updates their futures, and triggers relevant state-specific handlers. Supports optional service-specific callbacks for extended functionality.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task | Union[dict, object] | Task object or dictionary containing task state information. | required |
state | str | New state of the task. | required |
service_callback | Optional[Callable] | Callback function for service tasks. Must be daemon-threaded to avoid blocking. Defaults to None. | None |
Returns:
| Type | Description |
|---|---|
None | None |
State Transitions
- DONE: Calls handle_component_success
- RUNNING: Marks future as running
- CANCELED: Cancels the future
- FAILED: Calls handle_component_failure
Logging
- Debug: Non-relevant state received
- Info: Task state changes
- Warning: Unknown task received
Example
::
1 2 3 4 5 6 7 8 | |
Source code in doc_env/lib/python3.14/site-packages/radical/asyncflow/workflow_manager.py
1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 | |
shutdown async ¶
shutdown(skip_execution_backend: bool = False) -> None
Internal implementation of asynchronous shutdown for the workflow manager.
This method performs the following steps
- Sets the shutdown event to signal components to exit
- Cancels background tasks responsible for running and submitting workflows.
- Waits for the cancellation and completion of these tasks, with a timeout of 5 seconds.
- Cancel workflow tasks.
- Logs a warning if the tasks do not complete within the timeout period.
- Shuts down the backend using an executor to avoid blocking the event loop.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
skip_execution_backend | bool | If True, skips the shutdown of the execution backend. | False |
Returns:
| Type | Description |
|---|---|
None | None |
Raises:
| Type | Description |
|---|---|
TimeoutError | If the background tasks do not complete within the timeout period. |
CancelledError | If the shutdown is cancelled before completion. |
Source code in doc_env/lib/python3.14/site-packages/radical/asyncflow/workflow_manager.py
1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 | |