Skip to content

Commit

Permalink
Allow applications to specify env vars
Browse files Browse the repository at this point in the history
  • Loading branch information
rfbgo committed Feb 9, 2024
1 parent 69cac62 commit 62b4dcb
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lib/ramble/ramble/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,15 @@ def _long_print(self):
if 'tags' in wl_conf and wl_conf['tags']:
out_str.append(colified(wl_conf['tags'], indent=8) + '\n')

if wl_name in self.environment_variables:
out_str.append(rucolor.nested_1('\tEnvironment Variables:\n'))
for var, conf in self.environment_variables[wl_name].items():
indent = '\t\t'

out_str.append(rucolor.nested_2(f'{indent}{var}:\n'))
out_str.append(f'{indent}\tDescription: {conf["description"]}\n')
out_str.append(f'{indent}\tValue: {conf["value"]}\n')

if wl_name in self.workload_variables:
out_str.append(rucolor.nested_1('\tVariables:\n'))
for var, conf in self.workload_variables[wl_name].items():
Expand Down Expand Up @@ -840,6 +849,18 @@ def _set_default_experiment_variables(self):
if var not in self.variables.keys():
self.variables[var] = conf['default']

if self.expander.workload_name in self.environment_variables:
wl_env_vars = self.environment_variables[self.expander.workload_name]

for name, vals in wl_env_vars.items():

action = vals['action']
value = vals['value']

if action in self._env_variable_sets[0]:
if name not in self._env_variable_sets[0][action].keys():
self._env_variable_sets[0][action][name] = value

def _inject_commands(self, executables):
"""For add_expand_vars, inject all commands"""
command = []
Expand Down
28 changes: 28 additions & 0 deletions lib/ramble/ramble/language/application_language.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,34 @@ def _execute_workload_variable(app):
return _execute_workload_variable


@application_directive('environment_variables')
def environment_variable(name, value, description, workload=None,
workloads=None, **kwargs):
"""Define an environment variable to be used in experiments
These can be specific to workloads.
"""

def _execute_environment_variable(app):
all_workloads = ramble.language.language_helpers.require_definition(workload,
workloads,
'workload',
'workloads',
'environment_variable')

for wl_name in all_workloads:
if wl_name not in app.environment_variables:
app.environment_variables[wl_name] = {}

app.environment_variables[wl_name][name] = {
'value': value,
'action': 'set',
'description': description,
}

return _execute_environment_variable


@application_directive('phase_definitions')
def register_phase(name, pipeline=None, depends_on=[]):
"""Register a phase
Expand Down
1 change: 1 addition & 0 deletions lib/ramble/ramble/test/application_language.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def test_application_type_features(app_class):
assert hasattr(test_app, 'figures_of_merit')
assert hasattr(test_app, 'inputs')
assert hasattr(test_app, 'workload_variables')
assert hasattr(test_app, 'environment_variables')
assert hasattr(test_app, 'default_compilers')
assert hasattr(test_app, 'software_specs')
assert hasattr(test_app, 'required_packages')
Expand Down
1 change: 1 addition & 0 deletions lib/ramble/ramble/test/application_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def test_app_features(mutable_mock_apps_repo, app):
assert hasattr(app_inst, 'software_specs')
assert hasattr(app_inst, 'required_packages')
assert hasattr(app_inst, 'workload_variables')
assert hasattr(app_inst, 'environment_variables')
assert hasattr(app_inst, 'builtins')


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ class Basic(ExecutableApplication):
description='Example var',
workload='test_wl')

environment_variable('TEST_ENV', value="1",
description="test var", workload="test_wl")

archive_pattern('{experiment_run_dir}/archive_test.*')

figure_of_merit('test_fom',
Expand Down

0 comments on commit 62b4dcb

Please sign in to comment.