Progress for Script Commands

One thing the current script interface doesn’t allow is some sort of progress indicator. Initially, script commands were intended to be fast … but frankly anything that doesn’t finish in more than ~0.5 second makes me wonder “did that actually work?”

It’s fairly easy to add an “indeterminant progress” dialog to pop up.

But I’d like to add something for scripts that can reliably estimate their status (e.g., computed 2 out of 500 MD steps).

Right now, the idea is that scripts output JSON on the standard output.

I think I want to add an option in the script (e.g., "progress": true) that tells Avogadro to look on the standard error for progress values in percentages:

Progress: 1%
Progress: 12%
Progress: 25%
Progress: 65%
Progress: 72%
Progress: 100%
# standard output occurs

If this happens, Avogadro will read these for 1-100 progress status. Otherwise, it’ll just pop up a general progress dialog.

Comments? Concerns? Feedback? For example, @matterhorn103 - do you think this would be helpful for some of the longer-running tasks?

That would definitely be nice, or at least something along those lines, as running an MD simulation or conformer search with the xtb plugin at the moment just has an indefinitely scrolling bar. While the movement at least tells the user that something is happening, it doesn’t give them any indication how much longer it’s going to take.

Not really sure. But certainly in the case of xtb, estimating a percentage completion would not be especially easy, as it is not done by the program.

I think the simplest thing would be if some sort of live progress feed could be displayed and the script could cause that text to be refreshed with a simple print() statement or even by printing a json with a field like {"update": str}.

My preferred implementation would of course be where I don’t have to do any sort of interpretation of xtb’s output but can just pipe it straight through to the user.

What currently happens if a script prints multiple json objects? Does the Python process get shut down after the first is received?

An alternative idea – would it be possible for scripts to optionally add "shell": True to userOptions and cause a shell/terminal to pop up when the script is run?

That way, anything printed by the script with print() would be seen by the user, and the same strategies for reporting progress could be implemented as would be done for any command line program.

That’s a bad idea.

I’d rather separate “progress” (to standard error) and “output” streams because it’s cleaner for scripts and for Avogadro itself.

But it could be useful to say something like:

"progress": "percent"  .. or "string"

In the case of “string”, it would update the status line in the dialog (e.g., current energy, gradients, whatever) rather than the % of the progress bar.

Fair enough. I just wondered if the stderr stream might one day want to be used for error messages and it would be a bad idea to preclude that. As an inexperienced programmer I also wondered how normal it is to send things that aren’t actual error messages to stderr.

Certainly it would be a useful feature, it’s a good suggestion, and the flexibility to pass either a percentage or a string would be great for reducing a script’s development burden. :slight_smile: