Skip to content

Commit dd460f4

Browse files
Merge pull request #1714 from linsword13/fix-warn
Fix the multi-node mpi warning
2 parents eda7195 + 2d8feb8 commit dd460f4

2 files changed

Lines changed: 42 additions & 2 deletions

File tree

lib/ramble/ramble/test/application.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,3 +738,40 @@ def test_non_reserved_variables(self):
738738
self.assertNotIn("application::name::version", non_reserved)
739739
self.assertNotIn("modifier_version", non_reserved)
740740
self.assertEqual(len(non_reserved), 1)
741+
742+
743+
@pytest.mark.parametrize(
744+
"n_nodes,mpi_cmd,expect_warning",
745+
[
746+
("2", "", True),
747+
("1", "", False),
748+
("2", "mpirun -n {n_ranks}", False),
749+
],
750+
)
751+
def test_multi_node_mpi_command_warning(
752+
make_workspace_from_config, mutable_mock_apps_repo, n_nodes, mpi_cmd, expect_warning
753+
):
754+
workspace = ramble.main.RambleCommand("workspace")
755+
756+
test_config = f"""
757+
ramble:
758+
variables:
759+
mpi_command: '{mpi_cmd}'
760+
batch_submit: '{{execute_experiment}}'
761+
processes_per_node: 1
762+
n_nodes: {n_nodes}
763+
applications:
764+
basic:
765+
workloads:
766+
test_wl2:
767+
experiments:
768+
test_exp: {{}}
769+
"""
770+
ws, _ = make_workspace_from_config(test_config)
771+
out = workspace("setup", "--dry-run", global_args=["-D", ws.root])
772+
773+
expected_msg = (
774+
"Command bar requires a non-empty `mpi_command` variable in a multi-node experiment"
775+
)
776+
warning_present = expected_msg in out
777+
assert warning_present == expect_warning

var/ramble/repos/builtin/base_classes/application-base/base_class.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2224,8 +2224,11 @@ def _define_commands(self, exec_graph=None, success_list=None):
22242224
n_nodes = self.expander.expand_var_name(
22252225
self.keywords.n_nodes
22262226
)
2227-
n_nodes = 1 if "{n_nodes}" else n_nodes
2228-
n_nodes = 1 if not n_nodes else int(n_nodes)
2227+
n_nodes = (
2228+
1
2229+
if n_nodes in ("{n_nodes}", None, "")
2230+
else int(n_nodes)
2231+
)
22292232
if not raw_mpi_cmd and n_nodes > 1:
22302233
logger.warn(
22312234
f"Command {cmd_conf.name} requires a non-empty `mpi_command` "

0 commit comments

Comments
 (0)