-
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
Attmpt to decouple this_code setup #5664
Attmpt to decouple this_code setup #5664
Conversation
@@ -11,6 +11,7 @@ | |||
from __future__ import annotations | |||
|
|||
import abc | |||
import cmd |
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.
this is not used I think
import cmd |
@@ -97,7 +97,7 @@ def get_executable(self) -> str: | |||
|
|||
:return: The executable to be called in the submission script. | |||
""" | |||
return self.filepath_executable | |||
return str(self.filepath_executable) |
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.
Although this change is technically correct, I wonder whether we should change the type hint instead. I think we should prefer using pathlib.Path
over str
wherever possible.
So I would suggest to revert this change and make get_executable
return a pathlib.Path
. Then you just update the callers (currently two places) to cast to str
if they need to.
@@ -90,7 +90,7 @@ def get_executable(self) -> str: | |||
|
|||
:return: The executable to be called in the submission script. | |||
""" | |||
return self.filepath_executable | |||
return str(self.filepath_executable) |
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.
See other comment
@@ -76,6 +77,14 @@ def get_executable(self) -> str: | |||
:return: The executable to be called in the submission script. | |||
""" | |||
|
|||
def get_executable_cmdline_params(self, cmdline_params: list = None) -> list: |
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.
Let's try to be as specific as possible with the type hinting. Note the following notation requires to add from __future__ import annotations
at the top of the file (just below the module docstring).
def get_executable_cmdline_params(self, cmdline_params: list = None) -> list: | |
def get_executable_cmdline_params(self, cmdline_params: list[str] | None = None) -> list[str]: |
"""Return the list of executable with its cmdline_params""" | ||
return [self.get_executable()] + (cmdline_params or []) | ||
|
||
def get_prepend_cmdline_params(self, mpi_args=None, extra_mpirun_params=None) -> list: |
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.
def get_prepend_cmdline_params(self, mpi_args=None, extra_mpirun_params=None) -> list: | |
def get_prepend_cmdline_params(self, mpi_args: list[str] | None =None, extra_mpirun_params: list[str] | None = None) -> list[str]: |
a39827e
to
9ac98f9
Compare
Hi @sphuber, I accept all the suggestions, should be fine now. |
As we discussed offline, I did not implement to also remove the explicitly calling of |
fd20dd9
to
3b7ada9
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 @unkcpz . If this works for the containerized PR, this is good to go. Just some suggestions for the docstrings. And I think there is still a call to Code.get_executable
in the code that needs to cast to str
:
aiida-core/aiida/orm/utils/builders/code.py
Line 114 in d666332
spec['remote_abs_path'] = code.get_executable() |
|
||
cmdline_params = [str(this_code.get_executable())] + (code_info.cmdline_params or []) | ||
cmdline_params = this_code.get_executable_cmdline_params(cmdline_params=code_info.cmdline_params) |
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.
cmdline_params = this_code.get_executable_cmdline_params(cmdline_params=code_info.cmdline_params) | |
cmdline_params = this_code.get_executable_cmdline_params(code_info.cmdline_params) |
"""Return the list of executable with its cmdline_params | ||
|
||
:return: list of executable with its cmdline parameters.""" |
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.
"""Return the list of executable with its cmdline_params | |
:return: list of executable with its cmdline parameters.""" | |
"""Return the list of executable with its command line parameters. | |
:param cmdline_params: List of command line parameters provided by the ``CalcJob`` plugin. | |
:return: List of the executable followed by its command line parameters. | |
""" |
"""Return the list of prepend cmdline params for mpi seeting | ||
|
||
:return: list of prepend cmdline parameters.""" |
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.
"""Return the list of prepend cmdline params for mpi seeting | |
:return: list of prepend cmdline parameters.""" | |
"""Return List of command line parameters to be prepended to the executable in submission line. | |
These command line parameters are typically parameters related to MPI invocations. | |
:param mpi_args: List of MPI parameters provided by the ``Computer.get_mpirun_command`` method. | |
:param extra_mpiruns_params: List of MPI parameters provided by the ``metadata.options.extra_mpirun_params`` input of the ``CalcJob``. | |
:return: List of command line parameters to be prepended to the executable in submission line. | |
""" |
for more information, see https://pre-commit.ci
@sphuber thanks a lot! All changed.
True, and also change the type hint for the legacy code class and |
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.
All good, if you can just update the branch (I have merged the other PR) and fix the minor comments on the docstrings
Co-authored-by: Sebastiaan Huber <mail@sphuber.net>
for more information, see https://pre-commit.ci
Hi @sphuber, this is an attempt to move the code script generate for
prepend_cmdline_params
adcmdline_params
as the parameters intoAbstractCode
class which is required by the containerized code implementation if the code type check needs to be removed frompresubmmit
ofcalcjob.py
.I add two helper function into
AbstractCode
to generateprepend_cmdline_params
andcmdline_params
with parameters. This is the pre-requisites of the containerized code implementation.Please have a look and let me know if it is in the right direction. Thanks!