Skip to content

Commit 58c464a

Browse files
Add support for arbitrary commands in formatted executables
This commit allows formatted_executable definitions to have a `commands` attribute, which can define the lines that should be in the formatted output. The default is to format all of the commands for the experiment, but this can be override to format arbitrary strings / variables. Item in the `commands` list will be expanded as a variable definition, and then split over new-lines before formatting based on the formatted executable definition.
1 parent bca398e commit 58c464a

File tree

8 files changed

+39
-4
lines changed

8 files changed

+39
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
formatted_executables:
22
command:
33
join_separator: '\n'
4+
commands:
5+
- '{unformatted_command}'

lib/ramble/ramble/application.py

+18-4
Original file line numberDiff line numberDiff line change
@@ -1138,6 +1138,14 @@ def _define_formatted_executables(self):
11381138
based on the formatting requested.
11391139
"""
11401140

1141+
unformatted_str = ""
1142+
for cmd in self._command_list:
1143+
if unformatted_str:
1144+
unformatted_str += "\n"
1145+
unformatted_str += cmd
1146+
1147+
self.variables[self.keywords.unformatted_command] = unformatted_str
1148+
11411149
for var_name, formatted_conf in self._formatted_executables.items():
11421150
if var_name in self.variables:
11431151
raise FormattedExecutableError(
@@ -1160,10 +1168,16 @@ def _define_formatted_executables(self):
11601168
indentation = " " * n_indentation
11611169

11621170
formatted_str = ""
1163-
for cmd in self._command_list:
1164-
if formatted_str:
1165-
formatted_str += join_separator
1166-
formatted_str += indentation + prefix + cmd
1171+
commands_to_format = self._command_list
1172+
if "commands" in formatted_conf:
1173+
commands_to_format = formatted_conf[namespace.commands].copy()
1174+
1175+
for command in commands_to_format:
1176+
expanded = self.expander.expand_var(command)
1177+
for out_line in expanded.split("\n"):
1178+
if formatted_str:
1179+
formatted_str += join_separator
1180+
formatted_str += indentation + prefix + out_line
11671181

11681182
self.variables[var_name] = formatted_str
11691183

lib/ramble/ramble/experiment_set.py

+1
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ def _prepare_experiment(self, exp_template_name, variables, context, repeats):
290290
app_inst.set_chained_experiments(context.chained_experiments)
291291
app_inst.set_modifiers(context.modifiers)
292292
app_inst.set_tags(context.tags)
293+
logger.all_msg(f" Context formatted execs: {context.formatted_executables}")
293294
app_inst.set_formatted_executables(context.formatted_executables)
294295

295296
final_wl_name = expander.expand_var_name(

lib/ramble/ramble/keywords.py

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"batch_submit": {"type": key_type.required, "level": output_level.variable},
4848
"mpi_command": {"type": key_type.required, "level": output_level.variable},
4949
"experiment_template_name": {"type": key_type.reserved, "level": output_level.key},
50+
"unformatted_command": {"type": key_type.reserved, "level": output_level.variable},
5051
}
5152

5253

lib/ramble/ramble/namespace.py

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class namespace:
5959
indentation = "indentation"
6060
prefix = "prefix"
6161
join_separator = "join_separator"
62+
commands = "commands"
6263

6364
# For variants
6465
package_manager = "package_manager"

lib/ramble/ramble/schema/formatted_executables.py

+7
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@
2626
"prefix": {"type": "string", "default": ""},
2727
"indentation": {"type": "number", "default": 0},
2828
"join_separator": {"type": "string", "default": "\n"},
29+
"commands": {
30+
"type": "array",
31+
"default": ["{unformatted_command}"],
32+
"items": {
33+
"type": "string",
34+
},
35+
},
2936
},
3037
},
3138
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
formatted_executables:
22
command:
33
join_separator: '\n'
4+
commands:
5+
- '{unformatted_command}'

lib/ramble/ramble/test/end_to_end/formatted_executables.py

+7
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ def test_formatted_executables(mutable_config, mutable_mock_workspace_path, mock
3636
prefix: 'from_ws '
3737
indentation: 9
3838
join_separator: ';'
39+
ws_test_def:
40+
prefix: 'test_from_ws '
41+
indentation: 2
42+
commands:
43+
- '{mpi_command} test'
3944
applications:
4045
basic:
4146
formatted_executables:
@@ -74,6 +79,7 @@ def test_formatted_executables(mutable_config, mutable_mock_workspace_path, mock
7479
f.write("{app_exec_def}\n")
7580
f.write("{wl_exec_def}\n")
7681
f.write("{exp_exec_def}\n")
82+
f.write("{ws_test_def}\n")
7783
ws._re_read()
7884

7985
workspace("setup", "--dry-run", global_args=["-w", workspace_name])
@@ -88,6 +94,7 @@ def test_formatted_executables(mutable_config, mutable_mock_workspace_path, mock
8894
assert ";" + " " * 9 + "from_ws echo" in data
8995
assert "\n" + " " * 11 + "from_wl echo" in data
9096
assert "\n" + " " * 10 + "from_exp echo" in data
97+
assert "\n" + " " * 2 + "test_from_ws mpirun -n 16 -ppn 16 test" in data
9198

9299

93100
def test_redefined_executable_errors(

0 commit comments

Comments
 (0)