Skip to content
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

CLI: Add the -M/--most-recent-node option to verdi process commands #6283

Merged

Conversation

sphuber
Copy link
Contributor

@sphuber sphuber commented Feb 9, 2024

The -M/--most-recent-node option is added to the status, show and
report subcommands of verdi process. When specified, these commands
don't need specific process node identifiers but the most recent will
automatically be selected. This is a useful feature when users are
actively running processes one by one during testing and they usually
want to look at the last created process node.

@sphuber sphuber force-pushed the feature/cli-process-most-recent-node branch from 6673252 to 558fd8c Compare February 9, 2024 09:20
@sphuber sphuber changed the title CLI: Add the -M/--most-recent-node option to verdi process commands CLI: Add the -M/--most-recent-node option to verdi process commands Feb 9, 2024
@sphuber sphuber requested a review from mbercx February 9, 2024 10:37
@sphuber
Copy link
Contributor Author

sphuber commented Feb 9, 2024

@khsrali and @GeigerJ2 this is a small PR that might be interesting to have a look at. Not saying you should review it (although if you do have comments/questions, they are always welcome), but since it is nice and compact, it may be a nice entry point to familiarize yourself a bit with this part of the code.

@sphuber
Copy link
Contributor Author

sphuber commented Feb 9, 2024

@ljbeal I took your branch and finalized your PR #6171 . I had to create a new PR since I cannot push to your fork, but I kept your first commit, so it will be attributed to you. Hope you don't mind.

@danielhollas
Copy link
Collaborator

I am a little uncertain about the semantics here: what happens for more complex workchains that launch multiple processes in parallel?

src/aiida/cmdline/commands/cmd_process.py Outdated Show resolved Hide resolved
"""Show the log report for one or multiple processes."""
from aiida.cmdline.utils.common import get_calcjob_report, get_process_function_report, get_workchain_report
from aiida.orm import CalcFunctionNode, CalcJobNode, WorkChainNode, WorkFunctionNode

if most_recent_node:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am surprised that there was no check here that the user provided at least one process.
Right now, running verdi process report just silently does nothing. Same comment for other subcommands.

Compare with verdi process play

$ verdi process play
Report: no active processes selected.

The log message however comes from engine/processes/control.py
(should this be an Error instead of Report?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree this choice could be debated. Guess the logic was that since it takes a list, if an empty list is provided it behaves as any other for-loop in Python over an empty list, it is essentially a no-op. Definitely open to changing this and making it a warning or even error, but that is probably another PR.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. To be clear, I am less worried about the API of the functions in control.py and more about the CLI experience.

To me this is a really surprising behaviour (especially because the command is taking some time even with empty argument, but then it doesn't print anything).

I would still propose a change in this PR. If the most recent node was requested, we should error out if the user provided the process(es) argument at the same time.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@sphuber
Copy link
Contributor Author

sphuber commented Feb 9, 2024

I am a little uncertain about the semantics here: what happens for more complex workchains that launch multiple processes in parallel?

There the option won't be very useful. But when you are developing/testing simpler workflows or individual workchains, this shortcut may still be useful I think. Since it is an optional extra and doesn't require to be used, it made sense to me to add it.

@GeigerJ2
Copy link
Contributor

GeigerJ2 commented Feb 9, 2024

Hi @sphuber, thanks for the pointer! @khsrali and I just went through it. Everything is clear and makes sense. We agree, for the purposes of debugging individual workchains, the option seems very useful. The silent behavior of the verdi process commands is something one could indeed discuss, though we also think this does not belong in this PR. And, possible typo in your initial command, should be report, not repair, no?

MOST_RECENT_NODE = OverridableOption(
'-M',
'--most-recent-node',
is_flag=True,
Copy link
Contributor

@GeigerJ2 GeigerJ2 Feb 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default=False here not required?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For boolean flags without an off-switch, this is not necessary: https://click.palletsprojects.com/en/8.1.x/options/#boolean-flags

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, makes a lot of sense. We just got a bit confused as for example in the --all option below the default is given, but I guess this is redundant?

@sphuber
Copy link
Contributor Author

sphuber commented Feb 9, 2024

Thanks for going over it @GeigerJ2 and @khsrali !

And, possible typo in your initial command, should be report, not repair, no?

Well spotted, I have corrected the PR message.

'-M',
'--most-recent-node',
is_flag=True,
help='Select the most recently created node.',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a plan to use this elsewhere for non-process nodes? If not, this help message could be more concrete. But I don't feel strongly, it's fine as is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left it intentionally generic indeed. Maybe it could be used for verdi calcjob commands as well, like verdi calcjob report and verdi calcjob gotocomputer

@sphuber sphuber force-pushed the feature/cli-process-most-recent-node branch from cd4a99e to 69a7eda Compare February 9, 2024 16:11
The `-M/--most-recent-node` option is added to the `status`, `show` and
`report` subcommands of `verdi process`. When specified, these commands
don't need specific process node identifiers but the most recent will
automatically be selected. This is a useful feature when users are
actively running processes one by one during testing and they usually
want to look at the last created process node.

Co-Authored-By: Sebastiaan Huber <[email protected]>
@sphuber sphuber force-pushed the feature/cli-process-most-recent-node branch from 69a7eda to 5aae874 Compare February 9, 2024 16:27
Copy link

codecov bot commented Feb 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (4f9774a) 77.70% compared to head (5aae874) 77.78%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6283      +/-   ##
==========================================
+ Coverage   77.70%   77.78%   +0.08%     
==========================================
  Files         548      548              
  Lines       40243    40264      +21     
==========================================
+ Hits        31267    31315      +48     
+ Misses       8976     8949      -27     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@sphuber sphuber merged commit 5aae874 into aiidateam:main Feb 9, 2024
47 checks passed
@sphuber sphuber deleted the feature/cli-process-most-recent-node branch February 13, 2024 07:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants