Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions src/aiida/orm/nodes/data/code/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,10 @@ class Model(Data.Model, defer_build=True):
description='Whether the executable and arguments of the code in the submission script should be escaped '
'with single or double quotes.',
)
with_mpi: t.Optional[bool] = MetadataField(
None,
with_mpi: bool = MetadataField(
False,
title='Run with MPI',
description='Whether the executable should be run as an MPI program. This option can be left unspecified '
'in which case `None` will be set and it is left up to the calculation job plugin or inputs '
'whether to run with MPI.',
description='Whether the executable should be run as an MPI program.',
)
prepend_text: str = MetadataField(
'',
Expand Down Expand Up @@ -108,11 +106,12 @@ def __init__(
append_text: str = '',
prepend_text: str = '',
use_double_quotes: bool = False,
with_mpi: bool | None = None,
with_mpi: bool = False,
is_hidden: bool = False,
wrap_cmdline_params: bool = False,
**kwargs,
):

"""Construct a new instance.

:param default_calc_job_plugin: The entry point name of the default ``CalcJob`` plugin to use.
Expand Down Expand Up @@ -286,23 +285,24 @@ def use_double_quotes(self, value: bool) -> None:
self.base.attributes.set(self._KEY_ATTRIBUTE_USE_DOUBLE_QUOTES, value)

@property
def with_mpi(self) -> bool | None:
def with_mpi(self) -> bool:
"""Return whether the command should be run as an MPI program.

:return: ``True`` if the code should be run as an MPI program, ``False`` if it shouldn't, ``None`` if unknown.
:return: ``True`` if the code should be run as an MPI program, ``False`` otherwise.
"""
return self.base.attributes.get(self._KEY_ATTRIBUTE_WITH_MPI, None)
return self.base.attributes.get(self._KEY_ATTRIBUTE_WITH_MPI, False)


@with_mpi.setter
def with_mpi(self, value: bool | None) -> None:
def with_mpi(self, value: bool) -> None:
"""Set whether the command should be run as an MPI program.

:param value: ``True`` if the code should be run as an MPI program, ``False`` if it shouldn't, ``None`` if
unknown.
:param value: ``True`` if the code should be run as an MPI program, ``False`` otherwise.
"""
type_check(value, bool, allow_none=True)
type_check(value, bool)
self.base.attributes.set(self._KEY_ATTRIBUTE_WITH_MPI, value)


@property
def wrap_cmdline_params(self) -> bool:
"""Return whether all command line parameters should be wrapped with double quotes to form a single argument.
Expand Down
8 changes: 6 additions & 2 deletions tests/orm/data/code/test_abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,15 @@ def test_set_label():
def test_with_mpi():
"""Test the :meth:`aiida.orm.nodes.data.code.abstract.AbstractCode.with_mpi` property setter."""
code = MockCode()
assert code.with_mpi is None
assert code.with_mpi is False

for value in (True, False, None):
for value in (True, False):
code.with_mpi = value
assert code.with_mpi is value

# None is no longer allowed
with pytest.raises(TypeError):
code.with_mpi = None

with pytest.raises(TypeError):
code.with_mpi = 'False'
Expand Down