-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add monitor
task decorator to create tasks that to poll some state
#235
Conversation
awaitable
task decoratorAwaitable
task decorator
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #235 +/- ##
==========================================
+ Coverage 75.75% 79.59% +3.83%
==========================================
Files 70 65 -5
Lines 4615 4802 +187
==========================================
+ Hits 3496 3822 +326
+ Misses 1119 980 -139
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Awaitable
task decoratormonitor
task decorator to create tasks that to poll some state
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extensive! Great to have the monitor. I take it this supports monitoring in the AiiDA sense? So currently in AiiDA, a monitor function can be assigned to a CalcJob (see docs). Though initially intended to terminate the job if some condition is met, the monitor function can in principle do more.
Is this PR's feature meant to replicate this via aiida-workgraph methodology? Could you please comment a bit on what it can('t) do? For example, can it kill the job or attach (tracked) outputs to the job? These are currently supported. One interesting future (current?) task for a monitor would be to trigger other jobs if some condition is met. This is a feature request from the W&C community. The trick is how we should keep track of these actions in the provenance.
As for awaitable decorator (maybe should be in a separate PR?), no comments there. I don't play with async all that much. However, good to support it, as concurrency is a powerful tool in general!
@edan-bainglass , thanks for for the comment! The The The
This is exactly what the
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 |
@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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR, looks good to me. Only minor suggestions.
loop=self.loop, | ||
) | ||
awaitable = self.construct_awaitable_function(name, awaitable_target) | ||
self.set_task_state_info(name, "state", "RUNNING") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we report the finished state should we not also log somewhere the running state?
self.set_task_state_info(name, "state", "RUNNING") | |
self.set_task_state_info(name, "state", "RUNNING") | |
self.report(f"Task: {name} is running.", ) |
Maybe on a different log level like debug, but for that I think one needs to write a new function, but the report function is fairly easy to implement. https://github.com/aiidateam/aiida-core/blob/fb3686271fcdeb5506838a5a3069955546b05460/src/aiida/engine/processes/process.py#L589-L600
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At the top of the run_tasks
function, it reports that to run the task and also shows the type of the task. Thus I prefer not to report the running
state.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks looks good!
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