-
Notifications
You must be signed in to change notification settings - Fork 192
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
Engine: Add the wait
argument to submit
#6155
Conversation
aec0384
to
3352c94
Compare
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 @sphuber! Looks good, just a few small comments and it's ready to go.
For demos and tutorials, often in interactive notebooks, it is often preferred to use `run` instead of `submit` because in this way the cell will block until the process is done. The cell blocking will signal to the user that the process is still running and as soon as it returns it is immediately clear that the results are ready. With `submit` the cell returns immediately, but the user will now have to resort to manually checking when the process is done. Solutions are to instruct the user to call `verdi process list` manually (which they will have to do repeatedly) or implement some automated loop that checks for the process to terminate. However, using `run` has downsides as well, most notably that the process will be lost if the notebook gets disconnected. For processes that are expected to run longer, this can be really problematic, and so `submit` will have to be used regardless. Here, the `wait` argument is added to `submit`. Set to `False` by default to keep current behavior, when set to `True`, the function will mimic the behavior of `run` and only return when the process has terminated at which point the node is returned. A `REPORT` log message is emitted each time the state of the process is checked in intervals of `wait_interval`.
3352c94
to
406d103
Compare
406d103
to
b6f7e2d
Compare
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.
Looks all perfect to me.
I'll let @mbercx approve it.
The recent addition of the `wait` argument to the `submit` function allows a user to submit process the daemon, while still have the function block until the process is terminated, as a call to `run` would do. This can be useful in interactive tutorials and demos where the code should not avance until the process is done, but one still wants to benefits of having the daemon run the process. The downside of this approach is that it only allows to submit and wait for a single process at a time. Here the `await_processes` function is added. It takes a list of process nodes and will wait in a loop for all of them reach a terminal state. The time between iterations can be controlled by the `wait_interval` argument.
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.
Just one final fix needed for the Restructured text, it seems. ^^ I'll already approve, thanks again @sphuber!
One could of course also use ``run`` (see below), but then the process would be lost if the interpreter gets accidentally shut down. | ||
By using ``submit``, the process is run by the daemon which takes care of saving checkpoints so it can always be restarted in case of problems. | ||
If you need to launch multiple processes in parallel and want to wait for all of them to be finished, simply use ``submit`` with the default ``wait=False`` and collect the returned nodes in a list. | ||
You can then pass them to :func:`aiida.engine.launch.await_processes` which will return once all processes have terminated:: |
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.
You can then pass them to :func:`aiida.engine.launch.await_processes` which will return once all processes have terminated:: | |
You can then pass them to :func:`aiida.engine.launch.await_processes` which will return once all processes have terminated: |
I think the extra colon is still causing trouble here.
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 catching that. I tested the docs locally and it passed, but didn't bother to look at the actual output. Funnily enough, with just a single colon VSCode actually has incorrect syntax highlighting and lights up the whole phrase starting from :func:
onwards. This was fixed by the double colon, but clearly that is not what restructured text wants.
I also noted that I forgot to update sleep_interval
to wait_interval
which I corrected now
b6f7e2d
to
f91aa09
Compare
For demos and tutorials, often in interactive notebooks, it is often preferred to use
run
instead ofsubmit
because in this way the cell will block until the process is done. The cell blocking will signal to the user that the process is still running and as soon as it returns it is immediately clear that the results are ready. Withsubmit
the cell returns immediately, but the user will now have to resort to manually checking when the process is done. Solutions are to instruct the user to callverdi process list
manually (which they will have to do repeatedly) or implement some automated loop that checks for the process to terminate.However, using
run
has downsides as well, most notably that the process will be lost if the notebook gets disconnected. For processes that are expected to run longer, this can be really problematic, and sosubmit
will have to be used regardless.Here, the
wait
argument is added tosubmit
. Set toFalse
by default to keep current behavior, when set toTrue
, the function will mimic the behavior ofrun
and only return when the process has terminated at which point the node is returned. AREPORT
log message is emitted each time the state of the process is checked in intervals ofwait_interval
.