Closed superstar54 closed 3 weeks ago
Attention: Patch coverage is 83.73016%
with 41 lines
in your changes missing coverage. Please review.
Project coverage is 79.59%. Comparing base (
5937b88
) to head (b9a77b4
). Report is 36 commits behind head on main.
Files | Patch % | Lines |
---|---|---|
aiida_workgraph/engine/workgraph.py | 65.88% | 29 Missing :warning: |
aiida_workgraph/decorator.py | 65.00% | 7 Missing :warning: |
aiida_workgraph/executors/monitors.py | 84.37% | 5 Missing :warning: |
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
@edan-bainglass , thanks for for the comment!
The Calcjob
monitor and the WorkGraph
monitor are different in terms of the scope of monitoring.
The Monitor
in AiiDA currently works on the Calcjob
. It is called within the CalcJob's process, so it can modify its output. This is intra-process monitoring.
The Monitor
in WorkGraph is a task. The monitor task can monitor any events (e.g. time, file changes, etc.) as long as there is a API. Of course, it can also monitor the AiiDA processes using AiiDA API. It can fetch the state of other AiiDA processes, and it can kill/pause/play the process, but it can not modify the data (outputs) of the process. This is inter-process monitoring.
One interesting future (current?) task for a monitor would be to trigger other jobs if some condition is met.
This is exactly what the monitor
task does.
The trick is how we should keep track of these actions in the provenance.
The provenance is not tracked as the monitor task is not a aiida process, and it can not be a process, otherwise it will store too much unuseful data. I believe we need to create a special data type for the monitor task to store the provenance, because AiiDA provenance requires AiiDA data,
The monitor
task is actually implemented using the awatiable
feature similar to the awaitable
decorator, but we hide the asyncio
from the user. The user only needs to write the monitor task as a normal function, and the WorkGraph
will take care of the rest.
@superstar54 thanks for clarifying the various parts. Let's discuss next week the submission of other jobs via a monitor. This is quite interesting.
As for the PR, good to merge when you're ready.
This PR introduces an
monitor
task decorator, which can be particularly useful for tasks that need to poll some state (e.g., the presence of a file, the state of another WorkGraph) at given intervals until a success criterion is met.Possible use cases:
Note: while polling the state, the task will sleep for a given interval (default 1.0 second, can be changed by user), and relinquish control to the WorkGraph engine, so that it can run other tasks.
Example Usage:
Time monitor
A task wati until a given time.
File monitor
Start a task until a file exits.
Builtin tasks
I created some builtin Tasks:
TaskMonitor
,TimeMonitor
andFileMonitor
task monitor
time monitor
file monitor
General awaitable task
I also created an
awaitable
decorator to allow the user to take full control of theasyncio
function.About the the asyncio
The awaitable task will let the WorkGraph go to the
Waiting
state. the task will relinquish control to the asyncio event loop, thus the WorkGraph can run other tasks. However, if there is a long-running calcfunction, the available task will wait for the calcfunction to finish before it can get the control to run the next next step.TODO