Skip to content

Commit

Permalink
Added SLURM and Conda support
Browse files Browse the repository at this point in the history
- Modified exe function in base_script.sh.template to support
  aliases
- Added `conda install` support in base_script.sh.template
- Added SLURM support with slurm-script.sh.template
- SLURM support wraps given commands with SLURM commands using bash
  aliases
- Added usage instructions for slurm-script.sh.template and
  remote.sh.template
- Updated secret.tar.enc to use abrghost instead of abrgl
  • Loading branch information
xchoo committed Jun 24, 2021
1 parent 15d3b4b commit b2e7f37
Show file tree
Hide file tree
Showing 9 changed files with 156 additions and 5 deletions.
Binary file modified .ci/secret.tar.enc
Binary file not shown.
33 changes: 31 additions & 2 deletions .nengobones.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ travis_yml:
test_args: --test-arg --test-arg
- script: remote
- script: remote-test
- script: remote-conda-test
- script: remote-slurm-test
- script: test-coverage
env:
TEST_LOCAL_VAR: test local var val
Expand Down Expand Up @@ -98,7 +100,7 @@ ci_scripts:
pre_commands:
- cat .ci/remote.sh
travis_var_key: 2895d60e3414
host: gl
host: abrghost
- template: test
pre_commands:
- cat .ci/test-for-remote.sh
Expand All @@ -110,7 +112,34 @@ ci_scripts:
remote_script: test-for-remote
output_name: remote-test
travis_var_key: 2895d60e3414
host: gl
host: abrghost
coverage: true
- template: remote-script
pre_commands:
- cat .ci/remote-conda-test.sh
conda_install:
- pandoc
remote_script: test-for-remote
output_name: remote-conda-test
travis_var_key: 2895d60e3414
host: abrghost
coverage: true
- template: remote-script
pre_commands:
- cat .ci/remote-slurm-test.sh
remote_script: test-for-slurm
output_name: remote-slurm-test
travis_var_key: 2895d60e3414
host: abrghost
coverage: true
- template: slurm-script
pre_commands:
- cat .ci/test-for-slurm.sh
slurm_command: "srun -pCI"
wrapped_commands:
- pytest
slurm_script: test-for-remote
output_name: test-for-slurm
coverage: true
- template: docs
pre_commands:
Expand Down
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ jobs:
-
env:
SCRIPT="remote-test"
-
env:
SCRIPT="remote-conda-test"
-
env:
SCRIPT="remote-slurm-test"
-
env:
TEST_LOCAL_VAR="test local var val"
Expand Down
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ Release History
- Added support for changing the main branch name with the ``main_branch``
config option. (`#145`_)
- Added template for ``version.py``. (`#151`_)
- Added support for ``conda install`` in remote CI scripts. (`#152`_)
- Added template for running CI scripts through SLURM on remote machines. (`#152`_)

**Changed**

Expand Down Expand Up @@ -92,6 +94,7 @@ Release History
.. _#144: https://github.com/nengo/nengo-bones/pull/144
.. _#145: https://github.com/nengo/nengo-bones/pull/145
.. _#151: https://github.com/nengo/nengo-bones/pull/151
.. _#152: https://github.com/nengo/nengo-bones/pull/152

0.11.1 (April 13, 2020)
=======================
Expand Down
2 changes: 2 additions & 0 deletions nengo_bones/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,8 @@ def validate_ci_config(ci_config):
"pre_commands",
"post_commands",
"codespell_ignore_words",
"conda_install",
"wrapped_commands",
)
for opt in list_opts:
check_list(ci_config, opt)
Expand Down
4 changes: 1 addition & 3 deletions nengo_bones/templates/base_script.sh.template
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ exe() {
for i in "${!args[@]}"; do
[ -n "${args[$i]}" ] || unset "args[$i]"
done
"${args[@]}" || { echo -e "\033[1;31mCOMMAND '${args[0]}' FAILED\033[0m"; STATUS=1; }
eval '"${args[@]}"' || { echo -e "\033[1;31mCOMMAND '${args[0]}' FAILED\033[0m"; STATUS=1; }
}

if [[ ! -e {{ pkg_name }} ]]; then
Expand All @@ -27,10 +27,8 @@ if [[ "$COMMAND" == "install" ]]; then
{% block install %}
{% if pip_install %}
exe pip install {%- for pkg in pip_install %} "{{ pkg }}" {%- endfor %}

{% else %}
:

{% endif %}
{% endblock %}
elif [[ "$COMMAND" == "before_script" ]]; then
Expand Down
25 changes: 25 additions & 0 deletions nengo_bones/templates/remote.sh.template
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,24 @@ and logged in with `travis login --com`

See https://docs.travis-ci.com/user/encrypting-files/ for more details.


Usage Instructions
==================

This script executes a NengoBones generated CI script on a remote machine.

.nengobones.yml parameters:

`host`: The <hostname> of the remote machine defined in the `config` file above.

`travis_var_key`: The TravisCI variable key as defined in Step 6 of the setup
instructions above.

`remote_script`: The name of the script to be executed on the remote machine. This
script must be defined as a separate entry in the `ci_scripts` section of yml file.

`output_name`: Desired output name of the generated CI script.

#}

{% set pkg = pkg_name | replace("_", "-") %}
Expand Down Expand Up @@ -112,6 +130,13 @@ See https://docs.travis-ci.com/user/encrypting-files/ for more details.
echo "({{ host }}) Failed to create conda environment. Exiting.";
exit \$REMOTE_STATUS;
fi

{% if conda_install %}
# Install necessary conda packages
echo "$ ({{ host }}) Conda installing {%- for conda_pkg in conda_install %} "{{ conda_pkg }}" {%- endfor %}"
conda install -y {%- for conda_pkg in conda_install %} "{{ conda_pkg }}" {%- endfor %}

{% endif %}
cd {{ pkg }} || REMOTE_STATUS=1
echo "$ ({{ host }}) Installing {{ pkg }}"
{% endblock %}
Expand Down
76 changes: 76 additions & 0 deletions nengo_bones/templates/slurm-script.sh.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{% extends "templates/base_script.sh.template" %}

{#

Usage Instructions
==================

This script is intended to be used to apply a SLURM wrapper around other NengoBones
generated CI scripts.

.nengobones.yml parameters:

`slurm_command`: The SLURM command used to create the SLURM job. Use quotations to avoid
problems with the space character. Examples:
- "srun"
- "srun -pCI -G1"
- "sbatch"

`wrapped_commands`: A list of commands to be wrapped with `slurm_command`. The command
will be executed as: <slurm_command> <command>
Example, if <slurm_command> is "srun -pCI", and <command> is "pytest", then the command
will be executed as "srun -pCI pytest"

`slurm_script`: The CI script to be executed, but using the SLURM-wrapped commands
instead of the typical non-SLURM invocation.

`output_name`: Desired output name of the generated CI script.

#}

{% block install %}
bash .ci/{{ slurm_script }}.sh install || STATUS=1
{% endblock %}

{% block before_script %}
bash .ci/{{ slurm_script }}.sh before_script || STATUS=1
{% endblock %}

{% block script %}
# Enable `expand_aliases` option for bash interpreter
shopt -s expand_aliases

# Create aliases for commands to include SLURM command prefix
{% for command in wrapped_commands %}
alias {{ command }}="{{ slurm_command }} {{ command }}"
echo "Created alias for {{ command }}: "
type -a {{ command }}

{% endfor %}
# Run script. Use existing shell instead of subshell to ensure alias applies.
. .ci/{{ slurm_script }}.sh script || STATUS=1
{% endblock %}

{% block before_cache %}
bash .ci/{{ slurm_script }}.sh before_cache || STATUS=1
{% endblock %}

{% block after_success %}
bash .ci/{{ slurm_script }}.sh after_success || STATUS=1
{% endblock %}

{% block after_failure %}
bash .ci/{{ slurm_script }}.sh after_failure || STATUS=1
{% endblock %}

{% block before_deploy %}
bash .ci/{{ slurm_script }}.sh before_deploy || STATUS=1
{% endblock %}

{% block after_deploy %}
bash .ci/{{ slurm_script }}.sh after_deploy || STATUS=1
{% endblock %}

{% block after_script %}
bash .ci/{{ slurm_script }}.sh after_script || STATUS=1
{% endblock %}
12 changes: 12 additions & 0 deletions nengo_bones/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,18 @@ def test_validate_config():
config.validate_config(init_cfg)
test_cfg["pre_commands"] = ["command"]

# error when conda_install is a string instead of list
test_cfg["conda_install"] = "conda_req"
with pytest.raises(TypeError, match="conda_install should be a list"):
config.validate_config(init_cfg)
test_cfg["conda_install"] = ["conda_req"]

# error when wrapped_commands is a string instead of list
test_cfg["wrapped_commands"] = "command"
with pytest.raises(TypeError, match="wrapped_commands should be a list"):
config.validate_config(init_cfg)
test_cfg["wrapped_commands"] = ["command"]

# error when only one of pre_commit_config_yaml or pyproject_toml exists
init_cfg["pyproject_toml"] = {}
with pytest.raises(KeyError, match="must define both"):
Expand Down

0 comments on commit b2e7f37

Please sign in to comment.