Skip to content

Commit e10f070

Browse files
Update existing modifier definitions
1 parent 3cf9622 commit e10f070

File tree

8 files changed

+69
-94
lines changed

8 files changed

+69
-94
lines changed

var/ramble/repos/builtin/modifiers/env-var-aggregator/modifier.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,6 @@ class EnvVarAggregator(BasicModifier):
7878
modes=["explicit"],
7979
)
8080

81-
def __init__(self, file_path):
82-
super().__init__(file_path)
83-
self._applied_aggregation = False
84-
8581
def _aggregate_all_env_vars(self, shell):
8682
script_lines = []
8783

@@ -133,17 +129,14 @@ def _aggregate_explicit_env_vars(self, shell):
133129

134130
return script_lines
135131

136-
executable_modifier("inject_env_aggregation_script")
132+
executable_modifier("inject_env_aggregation_script", usage_filter="once")
137133

138134
def inject_env_aggregation_script(
139135
self, executable_name, executable, app_inst=None
140136
):
141137
pre_cmds = []
142138
post_cmds = []
143139

144-
if self._applied_aggregation or not app_inst:
145-
return pre_cmds, post_cmds
146-
147140
item_prefix = app_inst.expander.expand_var_name(
148141
"aggregated_env_var_item_prefix"
149142
)
@@ -175,6 +168,4 @@ def inject_env_aggregation_script(
175168
)
176169
pre_cmds.append(cmd_exec)
177170

178-
self._applied_aggregation = True
179-
180171
return pre_cmds, post_cmds

var/ramble/repos/builtin/modifiers/execution-date/modifier.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,18 @@ class ExecutionDate(BasicModifier):
1818

1919
mode("standard", description="Standard execution mode")
2020

21-
executable_modifier("get_startend_date")
22-
2321
modifier_variable(
2422
"date_format",
2523
default="",
2624
description="Date args to format output",
2725
mode="standard",
2826
)
2927

28+
executable_modifier("get_startend_date", usage_filter="once")
29+
3030
def get_startend_date(self, executable_name, executable, app_inst=None):
3131
from ramble.util.executable import CommandExecutable
3232

33-
if hasattr(self, "_already_applied"):
34-
return [], []
35-
36-
self._already_applied = True
37-
3833
pre_cmds = []
3934
post_cmds = []
4035

var/ramble/repos/builtin/modifiers/gcp-metadata/modifier.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,11 @@ class GcpMetadata(BasicModifier):
6565
description="Optional suffix for {metadata_parallel_prefix}",
6666
)
6767

68-
executable_modifier("gcp_metadata_exec")
68+
executable_modifier("gcp_metadata_exec", usage_filter="once")
6969

7070
def gcp_metadata_exec(self, executable_name, executable, app_inst=None):
7171
from ramble.util.executable import CommandExecutable
7272

73-
if hasattr(self, "_already_applied"):
74-
return [], []
75-
76-
self._already_applied = True
77-
7873
post_cmds = []
7974
pre_cmds = []
8075

var/ramble/repos/builtin/modifiers/install-ramble/modifier.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class InstallRamble(BasicModifier):
111111
modes=["standard", "quiet"],
112112
)
113113

114-
executable_modifier("source_installed_ramble")
114+
executable_modifier("source_installed_ramble", usage_filter="once")
115115

116116
def source_installed_ramble(
117117
self, executable_name, executable, app_inst=None
@@ -124,15 +124,13 @@ def source_installed_ramble(
124124
if self._usage_mode == "quiet":
125125
return pre_exec, post_exec
126126

127-
if not hasattr(self, "_already_applied"):
128-
pre_exec.append(
129-
CommandExecutable(
130-
"source-installed-ramble",
131-
template=[
132-
"{source_ramble}",
133-
],
134-
)
127+
pre_exec.append(
128+
CommandExecutable(
129+
"source-installed-ramble",
130+
template=[
131+
"{source_ramble}",
132+
],
135133
)
134+
)
136135

137-
self._already_applied = True
138136
return pre_exec, post_exec

var/ramble/repos/builtin/modifiers/install-spack/modifier.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class InstallSpack(BasicModifier):
8787
modes=["standard", "quiet"],
8888
)
8989

90-
executable_modifier("source_installed_spack")
90+
executable_modifier("source_installed_spack", usage_filter="once")
9191

9292
def source_installed_spack(
9393
self, executable_name, executable, app_inst=None
@@ -100,15 +100,13 @@ def source_installed_spack(
100100
if self._usage_mode == "quiet":
101101
return pre_exec, post_exec
102102

103-
if not hasattr(self, "_already_applied"):
104-
pre_exec.append(
105-
CommandExecutable(
106-
"source-installed-spack",
107-
template=[
108-
"{source_spack}",
109-
],
110-
)
103+
pre_exec.append(
104+
CommandExecutable(
105+
"source-installed-spack",
106+
template=[
107+
"{source_spack}",
108+
],
111109
)
110+
)
112111

113-
self._already_applied = True
114112
return pre_exec, post_exec

var/ramble/repos/builtin/modifiers/nccl-env/modifier.py

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -666,10 +666,6 @@ class NcclEnv(BasicModifier):
666666
modes=["standard"],
667667
)
668668

669-
def __init__(self, file_path):
670-
super().__init__(file_path)
671-
self._applied = False
672-
673669
def generate_env_var_dict(self, app_inst):
674670
env_var_set = {}
675671
set_env_vars = {}
@@ -684,39 +680,42 @@ def generate_env_var_dict(self, app_inst):
684680

685681
return env_var_set
686682

687-
executable_modifier("define_nccl_env_vars")
683+
@ModifierBase.executable_modifier_usage_filter("first_workload_exec")
684+
def filter_first_workload_executable(self, exec_mod, executable):
685+
# Apply before the first executable from the workload
686+
app_inst = self._get_app_inst()
687+
workload = app_inst.get_workload()
688+
return executable.name == workload.executables[
689+
0
690+
] and not self.executable_modifier_applied(exec_mod)
691+
692+
executable_modifier(
693+
"define_nccl_env_vars", usage_filter="first_workload_exec"
694+
)
688695

689696
def define_nccl_env_vars(self, executable_name, executable, app_inst=None):
690697
pre_cmds = []
691698
post_cmds = []
692-
if self._applied:
693-
return pre_cmds, post_cmds
694-
695-
workload = app_inst.get_workload()
696699

697-
# Apply before the first executable from the workload
698-
if executable_name == workload.executables[0]:
699-
self._applied = True
700-
701-
action_funcs = ramble.util.env.action_funcs
702-
shell = ramble.config.get("config:shell")
703-
env_var_dict = self.generate_env_var_dict(app_inst)
704-
env_var_cmds = []
705-
for action, conf in env_var_dict.items():
706-
(env_cmds, _) = action_funcs[action](conf, set(), shell=shell)
707-
708-
for cmd in env_cmds:
709-
if cmd:
710-
env_var_cmds.append(cmd)
711-
712-
pre_cmds.append(
713-
ramble.util.executable.CommandExecutable(
714-
"nccl_env_vars",
715-
template=env_var_cmds,
716-
mpi=False,
717-
redirect="",
718-
output_capture="",
719-
)
700+
action_funcs = ramble.util.env.action_funcs
701+
shell = ramble.config.get("config:shell")
702+
env_var_dict = self.generate_env_var_dict(app_inst)
703+
env_var_cmds = []
704+
for action, conf in env_var_dict.items():
705+
(env_cmds, _) = action_funcs[action](conf, set(), shell=shell)
706+
707+
for cmd in env_cmds:
708+
if cmd:
709+
env_var_cmds.append(cmd)
710+
711+
pre_cmds.append(
712+
ramble.util.executable.CommandExecutable(
713+
"nccl_env_vars",
714+
template=env_var_cmds,
715+
mpi=False,
716+
redirect="",
717+
output_capture="",
720718
)
719+
)
721720

722721
return pre_cmds, post_cmds

var/ramble/repos/builtin/modifiers/pre-exec-print/modifier.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,28 +28,27 @@ class PreExecPrint(BasicModifier):
2828
mode("standard", description="Standard execution mode for pre-print")
2929
default_mode("standard")
3030

31-
executable_modifier("pre_exec_print")
32-
33-
_attr_name = "_applied_pre_exec_print"
31+
executable_modifier("pre_exec_print", usage_filter="once")
3432

3533
def pre_exec_print(self, executable_name, executable, app_inst=None):
3634
from ramble.util.executable import CommandExecutable
3735

3836
pre_cmds = []
3937
post_cmds = []
4038

41-
if not hasattr(self, self._attr_name):
42-
echo_string = "Index: {experiment_index} -- Namespace: {experiment_namespace}"
43-
if "pre_exec_print_template" in app_inst.variables:
44-
echo_string = "{pre_exec_print_template}"
45-
pre_cmds.append(
46-
CommandExecutable(
47-
"perform-pre-exec-print",
48-
template=[f'echo "Running: {echo_string}"'],
49-
mpi=False,
50-
redirect="",
51-
output_capture="",
52-
)
39+
echo_string = (
40+
"Index: {experiment_index} -- Namespace: {experiment_namespace}"
41+
)
42+
if "pre_exec_print_template" in app_inst.variables:
43+
echo_string = "{pre_exec_print_template}"
44+
pre_cmds.append(
45+
CommandExecutable(
46+
"perform-pre-exec-print",
47+
template=[f'echo "Running: {echo_string}"'],
48+
mpi=False,
49+
redirect="",
50+
output_capture="",
5351
)
54-
setattr(self, self._attr_name, True)
52+
)
53+
5554
return pre_cmds, post_cmds

var/ramble/repos/builtin/modifiers/run-directory/modifier.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class RunDirectory(BasicModifier):
7373
dest_path="postrun_copy.sh",
7474
)
7575

76-
executable_modifier("apply_run_directory_change")
76+
executable_modifier("apply_run_directory_change", usage_filter="once")
7777

7878
def apply_run_directory_change(
7979
self, executable_name, executable, app_inst
@@ -89,8 +89,8 @@ def apply_run_directory_change(
8989
return pre_cmds, post_cmds
9090
from ramble.util import executable
9191

92-
if not getattr(self, "_applied", False):
93-
self._applied = True
92+
if not getattr(self, "_target_cleaned", False):
93+
self._target_cleaned = True
9494
should_cleanup = self.expander.expand_var_name(
9595
"cleanup_target_directory_before_run",
9696
typed=True,

0 commit comments

Comments
 (0)