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

Attmpt to decouple this_code setup #5664

Merged
merged 9 commits into from
Sep 27, 2022

Conversation

unkcpz
Copy link
Member

@unkcpz unkcpz commented Sep 26, 2022

Hi @sphuber, this is an attempt to move the code script generate for prepend_cmdline_params ad cmdline_params as the parameters into AbstractCode class which is required by the containerized code implementation if the code type check needs to be removed from presubmmit of calcjob.py.

I add two helper function into AbstractCode to generate prepend_cmdline_params and cmdline_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!

@unkcpz unkcpz requested a review from sphuber September 26, 2022 11:08
@@ -11,6 +11,7 @@
from __future__ import annotations

import abc
import cmd
Copy link
Contributor

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

Suggested change
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)
Copy link
Contributor

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)
Copy link
Contributor

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:
Copy link
Contributor

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).

Suggested change
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:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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]:

@unkcpz unkcpz force-pushed the refact/calcjob-code-info-setup branch from a39827e to 9ac98f9 Compare September 26, 2022 13:12
@unkcpz
Copy link
Member Author

unkcpz commented Sep 26, 2022

Hi @sphuber, I accept all the suggestions, should be fine now.

@unkcpz unkcpz requested a review from sphuber September 26, 2022 13:14
@unkcpz
Copy link
Member Author

unkcpz commented Sep 26, 2022

As we discussed offline, I did not implement to also remove the explicitly calling of PortableCode from presubmit, but for sure it needs to be removed and it is very confusing at presubmit that the code object from inputs.all_nodes and this_code from calc_info appears mixed in the function. I'll try to clarify it in another PR.

@unkcpz
Copy link
Member Author

unkcpz commented Sep 26, 2022

This PR is updated, rebased and tested in #5667, sufficient for that implementation. Could you have a look @sphuber ?

Copy link
Contributor

@sphuber sphuber left a 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:

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)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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)

Comment on lines 81 to 83
"""Return the list of executable with its cmdline_params

:return: list of executable with its cmdline parameters."""
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"""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.
"""

Comment on lines 91 to 93
"""Return the list of prepend cmdline params for mpi seeting

:return: list of prepend cmdline parameters."""
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"""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.
"""

@unkcpz
Copy link
Member Author

unkcpz commented Sep 26, 2022

@sphuber thanks a lot! All changed.

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.

True, and also change the type hint for the legacy code class and MockCode class for the test.

@unkcpz unkcpz requested a review from sphuber September 26, 2022 22:27
Copy link
Contributor

@sphuber sphuber left a 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

aiida/orm/nodes/data/code/abstract.py Outdated Show resolved Hide resolved
aiida/orm/nodes/data/code/abstract.py Outdated Show resolved Hide resolved
aiida/orm/nodes/data/code/abstract.py Outdated Show resolved Hide resolved
@unkcpz unkcpz requested a review from sphuber September 27, 2022 09:22
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.

2 participants