-
Notifications
You must be signed in to change notification settings - Fork 200
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
AbstractCode
: Add the with_mpi
attribute
#5922
AbstractCode
: Add the with_mpi
attribute
#5922
Conversation
8d27368
to
6a876cb
Compare
@ltalirz I have added the docs now and updated the logic to consider the value of the |
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 a lot @sphuber !
the implementation and logic looks good to me, just minor points
(leave it up to you whether you want a follow-up review or not)
@@ -59,6 +61,7 @@ def __init__( | |||
:param append_text: The text that should be appended to the run line in the job script. | |||
:param prepend_text: The text that should be prepended to the run line in the job script. | |||
:param use_double_quotes: Whether the command line invocation of this code should be escaped with double quotes. | |||
:param with_mpi: Whether the command should be run with the MPI run command in front. |
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.
:param with_mpi: Whether the command should be run with the MPI run command in front. | |
:param with_mpi: Whether the code is known to be a MPI program. |
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.
I am fine with changing it to "MPI program" but I think the language should include that it forces something. Your suggested phrasing seems to suggest it is just a label but it is not clear whether it will change behavior. How about "Whether the code should be run as an MPI program."
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.
Sounds good!
~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
Finally, the MPI setting can be controlled on a per-instance basis, using the ``withmpi`` :ref:`metadata option<topics:calculations:usage:calcjobs:options>`. | ||
If MPI should be enabled or disabled, explicitly set this option to ``True`` or ``False``, respectively. |
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.
If MPI should be enabled or disabled, explicitly set this option to ``True`` or ``False``, respectively. |
# Here are the three values that will override the base value _if_ they are not ``None``. If any of them are | ||
# explicitly defined but are not equivalent, an exception is raised. We use the ``self._raw_inputs`` to | ||
# determine the actual value passed for ``metadata.options.withmpi`` and distinghuish it from the default. |
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.
# Here are the three values that will override the base value _if_ they are not ``None``. If any of them are | |
# explicitly defined but are not equivalent, an exception is raised. We use the ``self._raw_inputs`` to | |
# determine the actual value passed for ``metadata.options.withmpi`` and distinghuish it from the default. | |
# Any of these three values will determine MPI behavior _if_ they are not ``None``. If any of them are | |
# explicitly defined but are not equivalent, an exception is raised. We use the ``self._raw_inputs`` to | |
# determine the actual value passed to ``metadata.options.withmpi`` (to distinguish it from the default value). |
* The ``CalcJob`` implementation | ||
* The ``metadata.options.withmpi`` input | ||
|
||
MPI is enabled or disabled if any of these values is explicitly set to ``True`` or ``False``, respectively. |
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.
MPI is enabled or disabled if any of these values is explicitly set to ``True`` or ``False``, respectively. |
|
||
|
||
@pytest.mark.parametrize( | ||
'code_key, with_mpi_code, with_mpi_option, expected', ( |
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 pointing out that you don't seem to be testing the ('...',None,None)
case (not sure whether there is a reason for it)
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.
Reason was given the fact that CalcJob
defines False
as default. But I realized that that can of course change later. So I added the tests.
6a876cb
to
558c512
Compare
Thanks for the review @ltalirz I have added a single commit with the addressed changes. I have adopted most of your suggestions but not everything, so maybe you want to have a quick final look, but not necessary if you don't have time |
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 to me!
The `with_mpi` attribute serves to indicate whether a code instance needs to be run with the MPI run command in front of the executable. The attribute is exposed through the `with_mpi` property getter and setter. The attribute can be set through the `verdi code create` command using the `--with-mpi/--no-with-mpi` flags. The attribute is set to `None` by default. This means that the code doesn't enforce MPI being used or not whatsoever and it is left up to the `CalcJob` plugin and the `metadata.options.withmpi` input. The `CalcJob.presubmit` logic is updated to take the `with_mpi` setting of the input codes into account. The default value whether to run with or without MPI is defined by the `metadata.options.withmpi` input. This can then be overridden by either the plugin, code input or through the `metadata.options.withmpi` input, but if multiple are explicitly specified, they have to agree or a `RuntimeError` is raised.
558c512
to
2b73765
Compare
The plugin was setting `CodeInfo.withmpi` based on the inputs from `metadata.options.withmpi`. This is not necessary as the metadata option is already handled by the `CalcJob` base class. The plugin implementation should only set `CodeInfo.withmpi` if it wants to _force_ the code to be run with MPI enabled or disabled. The `CalcJob` base implementation used to not distinguish between the two, but in aiidateam/aiida-core#5922 the handling of MPI was improved. A `Code` can now define whether it should be run with MPI or not and so the `CalcJob` class now has to raise if the MPI setting of the code and the plugin clash. The `withmpi` option, if explicitly set by the user, is also checked. Since the plugin doesn't intend to enforce MPI or not, the setting on the `CodeInfo` is removed.
The plugin was setting `CodeInfo.withmpi` based on the inputs from `metadata.options.withmpi`. This is not necessary as the metadata option is already handled by the `CalcJob` base class. The plugin implementation should only set `CodeInfo.withmpi` if it wants to _force_ the code to be run with MPI enabled or disabled. The `CalcJob` base implementation used to not distinguish between the two, but in aiidateam/aiida-core#5922 the handling of MPI was improved. A `Code` can now define whether it should be run with MPI or not and so the `CalcJob` class now has to raise if the MPI setting of the code and the plugin clash. The `withmpi` option, if explicitly set by the user, is also checked. Since the plugin doesn't intend to enforce MPI or not, the setting on the `CodeInfo` is removed.
The plugin was setting `CodeInfo.withmpi` based on the inputs from `metadata.options.withmpi`. This is not necessary as the metadata option is already handled by the `CalcJob` base class. The plugin implementation should only set `CodeInfo.withmpi` if it wants to _force_ the code to be run with MPI enabled or disabled. The `CalcJob` base implementation used to not distinguish between the two, but in aiidateam/aiida-core#5922 the handling of MPI was improved. A `Code` can now define whether it should be run with MPI or not and so the `CalcJob` class now has to raise if the MPI setting of the code and the plugin clash. The `withmpi` option, if explicitly set by the user, is also checked. Since the plugin doesn't intend to enforce MPI or not, the setting on the `CodeInfo` is removed.
Fixes #3236
The
with_mpi
attribute serves to indicate whether a code instanceneeds to be run with the MPI run command in front of the executable.
The attribute is exposed through the
with_mpi
property getter andsetter. The attribute can be set through the
verdi code create
commandusing the
--with-mpi/--no-with-mpi
flags.The attribute is set to
None
by default. This means that the codedoesn't enforce MPI being used or not whatsoever and it is left up to
the
CalcJob
plugin and themetadata.options.withmpi
input.The
CalcJob.presubmit
logic is updated to take thewith_mpi
settingof the input codes into account. The default value whether to run with
or without MPI is defined by the
metadata.options.withmpi
input. Thiscan then be overridden by either the plugin or the code input, but if
both are explicitly specified, they have to agree or a
RuntimeError
israised.