-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: allow mustache templates in job environment variables #6506
base: master
Are you sure you want to change the base?
Conversation
3eb221f
to
8185f27
Compare
This seems like it could be really powerful. Nice! |
Problem: It would be useful to allow expansion of mustache templates in envionment variables in the job shell. However, expanding templates in the entire jobspec environment dictionary would be inefficient, since values with templates would be by far the uncommon case. Also, environment variables may legitimately contain values that look like mustache templates but should not be expanded. Add a new shell builtin plugin for expanding select environment variables in a `env-expand` shell options dictionary. This allows the jobspec to opt-in to mustache expansion for a select set of environment variables, solving the issues noted above.
Problem: It would be useful to expand mustache templates in environment variable values, but this is currently not supported in the submission cli commands. When processing the `--env*` set of options, detect any provided environment variable values that appear to contain a mustache template. Return these in a separate dict from the main environ dictionary and add them to `attributes.system.shel.optionsenv-expand` in jobspec. The job shell will then expand these variables before running the job.
Problem: Environment variables in the env-expand jobspec options dictionary cannot be expanded to different values per task because the env-expand plugin only runs at the shell.init callback. Add a task_expand_env() function in the env-expand plugin that runs at task.init and thus is able to set per-task environment variables. To avoid processing the same mustache templates multiple times, keep the original env_expand() function to expand non task-specific templates. When a template is detected to be fully expanded, it is removed from the env-expand object so that it is not re-processed per task.
Problem: The shell env-expand plugin now supports task-specific template expansion, but the shell doesn't provide any task tags. Add support to the job shell for expanding the following task-specific mustache tags: - {{taskid}}, {{task.id}}, or {{task.rank}} - global task rank - {{task.index}} or {{task.localid}} - local task rank
Problem: The job shell supports a limited set of mustache tags. Expand the set of supported tags, including: - {{nnodes}} and {{size}} for the total node and task count - A set of node.* tags including: - {{node.id}}: index of this shell relative to job - {{node.ntasks}}: number of tasks local to this node - {{node.name}}: hostname - {{node.ncores}}: number of allocated cores on this node - {{node.ngpus}}: number of allocated gpus on this node - {{node.taskids}: task idset, e.g. 0-3 - {{node.coreids}}: core idset, e.g. "0-3" - {{node.gpuids}}: gpu idset e.g. "0"
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #6506 +/- ##
===========================================
+ Coverage 53.67% 83.56% +29.89%
===========================================
Files 475 526 +51
Lines 79573 87797 +8224
===========================================
+ Hits 42709 73369 +30660
+ Misses 36864 14428 -22436
|
I've just pushed an update (though this PR should still be considered an experimental WIP) that adds per-task environment variable mustache template expansion, along with some new task-specific mustache tags:
Additionally, a set of job and node specific mustache tags are added:
With this, users could "opt-in" to having some equivalent environment variables to the 60 or set by default by Slurm. This could also be useful in the cli plugins prototyped in #2875. Finally, if the shell output plugin is modified to render the output file name per task, we can possibly close #4696, since a unique template per-task or per-node would result in per-task or per-node output files. |
The job shell expands mustache templates for input/output filenames as well as in command arguments. It would also be useful to support this template expansion in environment variables, but currently this is not supported. It probably isn't efficient to wholesale expand mustache templates in all environment variables, since the common case would be no variables to expand. Also, some environment variables may happen to contain mustache templates which should not be expanded.
This PR introduces a new
env-expand
shell builtin plugin which applies mustache expansion to any environment variables in a newenv-expand
shell options key in jobspec.On the cli side, the
get_filtered_environment()
function is extended to look for environment variable values specified on the command line and pass these back in a dictionary separate from the main environment. This dictionary is then saved in theattributes.system.shell.options.env-expand
key for use by the shell plugin.This means that only environment variables specified on the command line or in a file as
VAR=TEMPLATE
whereTEMPLATE
contains{{}}
will be expanded. Variables in the environment that already do contain{{}}
pass through the normal environment dictionary unmodified. Additionally, theenv-expand
shell plugin only has to process the minimum number of variables.This is a WIP so I can get feedback on the approach before writing tests.
The current use case here is to place files in the job's tmpdir and set environment variables in the job to point to these files, e.g. to extend rc1: