Skip to content

Commit

Permalink
fix: pass sbatch options correctly to interactive script
Browse files Browse the repository at this point in the history
  • Loading branch information
YodaEmbedding committed Apr 17, 2024
1 parent b8c593e commit f52477b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
14 changes: 12 additions & 2 deletions easy_slurm/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def create_job_interactive_script_source(
job_path = _expand_path(job_path)

return JOB_INTERACTIVE_TEMPLATE.format(
sbatch_options_str=_sbatch_options_to_str(
sbatch_options_str=_sbatch_options_to_str_interactive(
sbatch_options, job_dir, cleanup_seconds
),
job_path=job_path,
Expand Down Expand Up @@ -205,7 +205,7 @@ def submit_job_dir(job_dir: str, interactive: bool):
"""
if interactive:
job_interactive_path = f"{job_dir}/job_interactive.sh"
cmd = ["srun", "--pty", "bash", "--init-file", job_interactive_path]
cmd = [job_interactive_path]
subprocess.run(cmd, check=True, text=True)
return

Expand Down Expand Up @@ -258,6 +258,16 @@ def _sbatch_options_to_str(
return "\n".join(f"#SBATCH --{k}={v}" for k, v in sbatch_options.items())


def _sbatch_options_to_str_interactive(
sbatch_options: dict[str, Any], job_dir: str, cleanup_seconds: int
) -> str:
sbatch_options = {
**sbatch_options,
"signal": f":USR1@{cleanup_seconds}", # send USR1 to Bash before job end time
}
return "\n".join(f" --{k}={v}" for k, v in sbatch_options.items())


def _quote_single_quotes(s: str) -> str:
"""Replaces ' with '"'"'."""
return s.replace("'", """'"'"'""")
Expand Down
10 changes: 10 additions & 0 deletions easy_slurm/templates/job_interactive.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
#!/bin/bash -v

SBATCH_OPTIONS=(
{{sbatch_options_str}}
)

CMD=(bash --init-file _job_interactive.sh)

cat <<EOF > _job_interactive.sh
#!/bin/bash -v
source {{job_path}} --interactive
EOF

srun --pty "${SBATCH_OPTIONS[@]}" "${CMD[@]}"

0 comments on commit f52477b

Please sign in to comment.