Materials-simulation-skills slurm-job-script-generator
install
source · Clone the upstream repo
git clone https://github.com/HeshamFS/materials-simulation-skills
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/HeshamFS/materials-simulation-skills "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/hpc-deployment/slurm-job-script-generator" ~/.claude/skills/heshamfs-materials-simulation-skills-slurm-job-script-generator && rm -rf "$T"
manifest:
skills/hpc-deployment/slurm-job-script-generator/SKILL.mdsource content
SLURM Job Script Generator
Goal
Generate a correct, copy-pasteable SLURM job script (
.sbatch) for running a simulation, and surface common configuration mistakes (bad walltime format, conflicting memory flags, oversubscription hints).
Requirements
- Python 3.8+
- No external dependencies (Python standard library only)
- Works on Linux, macOS, and Windows (script generation only)
Inputs to Gather
| Input | Description | Example |
|---|---|---|
| Job name | Short identifier for the job | |
| Walltime | SLURM time limit | |
| Partition | Cluster partition/queue (if required) | |
| Account | Project/account (if required) | |
| Nodes | Number of nodes to allocate | |
| MPI tasks | Total tasks, or tasks per node | or per node |
| Threads | CPUs per task (OpenMP threads) | |
| Memory | or (cluster policy dependent) | |
| GPUs | GPUs per node (optional) | |
| Working directory | Where the run should execute | |
| Modules | Environment modules to load (optional) | , |
| Run command | The command to launch under SLURM | |
Decision Guidance
MPI vs MPI+OpenMP layout
Does the code use OpenMP / threading? ├── NO → Use MPI-only: cpus-per-task=1 └── YES → Use hybrid: set cpus-per-task = threads per MPI rank and export OMP_NUM_THREADS = cpus-per-task
Rule of thumb: if you see diminishing strong-scaling efficiency at high MPI ranks, try fewer ranks with more threads per rank (and measure).
Memory flag selection
- Use either
(per node) or--mem
(per CPU), not both.--mem-per-cpu - Follow your cluster’s documentation; some sites enforce one style.
- SLURM
units are integer MB by default, or an integer with suffix--mem
(andK/M/G/T
commonly means “all memory on node”).--mem=0
Script Outputs (JSON Fields)
| Script | Key Outputs |
|---|---|
| , , , |
Workflow
- Gather cluster constraints (partition/account, GPU policy, memory policy).
- Choose a process layout (MPI-only vs hybrid MPI+OpenMP).
- Generate the script with
.slurm_script_generator.py - Inspect warnings (conflicts, suspicious layouts).
- Save the generated script as
.job.sbatch - Submit with
and monitor withsbatch job.sbatch
.squeue
CLI Examples
# Preview a job script (prints to stdout) python3 skills/hpc-deployment/slurm-job-script-generator/scripts/slurm_script_generator.py \ --job-name phasefield \ --time 00:10:00 \ --partition compute \ --nodes 1 \ --ntasks-per-node 8 \ --cpus-per-task 2 \ --mem 16G \ --module gcc/12 \ --module openmpi/4.1 \ -- \ ./simulate --config config.json # Write to a file and also emit structured JSON python3 skills/hpc-deployment/slurm-job-script-generator/scripts/slurm_script_generator.py \ --job-name phasefield \ --time 00:10:00 \ --nodes 1 \ --ntasks 16 \ --cpus-per-task 1 \ --out job.sbatch \ --json \ -- \ /bin/echo hello
Conversational Workflow Example
User: I need an
sbatch script for my MPI simulation. I want 2 nodes, 64 ranks per node, 2 OpenMP threads per rank, and 2 hours.
Agent workflow:
- Confirm partition/account and whether GPUs are needed.
- Generate a hybrid job script:
python3 scripts/slurm_script_generator.py --job-name run --time 02:00:00 --nodes 2 --ntasks-per-node 64 --cpus-per-task 2 -- -- ./simulate - Explain the mapping:
- Total ranks = 128
- Threads per rank = 2 (
)OMP_NUM_THREADS=2
- If the user provides node core counts, sanity-check oversubscription using
.--cores-per-node
Error Handling
| Error | Cause | Resolution |
|---|---|---|
| Bad walltime format | Use or |
| Non-positive nodes | Provide |
| Conflicting memory directives | Choose one memory style |
| Missing launch command | Add |
Security
Input Validation
is validated against strict--time
orHH:MM:SS
format via regexD-HH:MM:SS
,--nodes
,--ntasks
,--ntasks-per-node
,--cpus-per-task
are validated as positive integers with upper bounds--gpus
and--mem
are validated against SLURM's accepted format (--mem-per-cpu
); providing both simultaneously is rejected<int>[K|M|G|T]
is validated against--job-name
(no shell metacharacters)[a-zA-Z0-9_.-]+
and--partition
are validated against safe-character allowlists--account
values are validated to prevent shell injection (no--module
,;
,|
, backticks, or&
)$
File Access
- The script reads no external files; all inputs are provided via CLI arguments
writes the generated sbatch script to a single specified file path--out- The generated script is a plain-text shell script with
directives; it contains no dynamically generated code#SBATCH
Tool Restrictions
- Read: Used to inspect script source, references, and existing job scripts
- Bash: Used to execute
with explicit argument lists; the generated script itself is NOT executed by the agentslurm_script_generator.py - Write: Used to save the generated
file; writes are scoped to the user's working directory.sbatch - Grep/Glob: Used to locate existing scripts, configs, and cluster documentation
Safety Measures
- No
,eval()
, or dynamic code generationexec() - All subprocess calls use explicit argument lists (no
)shell=True - The run command (after
) is included verbatim in the generated script but is never executed by the skill itself-- - Module names are sanitized to prevent injection into
directivesmodule load - Generated scripts use
for safe shell execution on the clusterset -euo pipefail
Limitations
- Does not query cluster hardware or site policies; it can only validate internal consistency.
- SLURM installations vary (GPU directives, QoS rules, partitions). Adjust directives for your site.
References
- Commonreferences/slurm_directives.md
directives and mapping tips#SBATCH
Version History
- v1.0.0 (2026-02-25): Initial SLURM job script generator