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

CalcJob: Remove default of withmpi input and make it optional #6020

Merged
merged 1 commit into from
May 16, 2023

Conversation

sphuber
Copy link
Contributor

@sphuber sphuber commented May 16, 2023

The metadata.options.withmpi specified False as the default. This can pose a problem for CalcJob implementations that can run with and without MPI.

Since the recent changes in the handling of MPI for CalcJob runs, see cdb3eed, there are now three ways that it is controlled:

  • metadata.options.withmpi input
  • CodeInfo.withmpi returned by the CalcJob implementation
  • AbstractCode.with_mpi attribute

The engine will check each of these, and when any of them are explicitly set to conflicting values, an error is raised. The problem is that the CalcJob base class, set a default for the metadata.options.withmpi input, and set it to False.

This forces all CalcJob plugins to manually unset it if they can in principle run with or without MPI, as it would except if a Code would be passed in the inputs that set with_mpi to True. The code to do it is non-trivial though:

options['withmpi'].default = None
options['withmpi'].required = False
options['withmpi'].valid_type = (bool, type(None))

This is not user-friendly for users wanting to implement CalcJob plugins and it is better to remove the default on the base class.

This change should be fully-backwards compatible since the logic in CalcJob.presubmit will check the case where none of the three methods explicitly set a value. In this case, the logic used to fall back on the value of the option set on the node. This branch would actually never be hit, because in this case, the default of metadata.options.withmpi would always be set to False. This fallback keeps False as default, but hardcodes it instead of taking it from the option input.

The `metadata.options.withmpi` specified `False` as the default. This
can pose a problem for `CalcJob` implementations that can run with and
without MPI.

Since the recent changes in the handling of MPI for `CalcJob` runs, see
cdb3eed, there are now three ways that
it is controlled:

 * `metadata.options.withmpi` input
 * `CodeInfo.withmpi` returned by the `CalcJob` implementation
 * `AbstractCode.with_mpi` attribute

The engine will check each of these, and when any of them are explicitly
set to conflicting values, an error is raised. The problem is that the
`CalcJob` base class, set a default for the `metadata.options.withmpi`
input, and set it to `False`.

This forces all `CalcJob` plugins to manually unset it if they can in
principle run with or without MPI, as it would except if a `Code` would
be passed in the inputs that set `with_mpi` to `True`. The code to do it
is non-trivial though:

    options['withmpi'].default = None
    options['withmpi'].required = False
    options['withmpi'].valid_type = (bool, type(None))

This is not user-friendly for users wanting to implement `CalcJob`
plugins and it is better to remove the default on the base class.

This change should be fully-backwards compatible since the logic in
`CalcJob.presubmit` will check the case where none of the three methods
explicitly set a value. In this case, the logic used to fall back on the
value of the option set on the node. This branch would actually never be
hit, because in this case, the default of `metadata.options.withmpi`
would always be set to `False`. This fallback keeps `False` as default,
but hardcodes it instead of taking it from the option input.
@sphuber sphuber requested a review from ltalirz May 16, 2023 11:41
Copy link
Member

@ltalirz ltalirz left a comment

Choose a reason for hiding this comment

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

thanks @sphuber , this looks good to me

@sphuber sphuber merged commit 6a88cb3 into aiidateam:main May 16, 2023
@sphuber sphuber deleted the fix/calcjob-withmpi-default branch May 16, 2023 13:38
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