Arrays for parallel recording, and a categorical feature

Arrays for parallel recording, and a categorical feature#

Recording multiple jobs collected its runs one after another inside a single allocation. Here we collect them in parallel with a SLURM array, and then look at what changes when a job’s feature isn’t a number.

Its three arrays come to 112 tasks, and each sbatch --wait waits for every task in its array. On a small or busy cluster that is a long wait for a lesson whose subject is what the records look like afterwards, so the mocked option is a reasonable choice here even if you ran the earlier lessons for real.

To follow along, cd into 04_array_jobs/.

Arrays, and why no --step-id#

run_perfectScaler.sbatch#
#!/bin/bash
#SBATCH --nodes=1
#SBATCH --ntasks=1
#SBATCH --cpus-per-task=1
#SBATCH --mem=6G
#SBATCH --time=00:05:00
#SBATCH --array=0-25
#SBATCH --job-name=perfectScaler
#SBATCH --output=out_slurm_logs/slurm-%x-%j.out

intensities=(500 1000 1500 2000 2500 3000 3500 4000)

idx=$((SLURM_ARRAY_TASK_ID % 8))
intensity=${intensities[$idx]}

srun ../bin/perfectScaler --intensity "$intensity"

slurmise record \
    "perfectScaler --intensity $intensity"

--array=0-25 asks for 26 tasks. Each one picks an intensity out of the list with its own $SLURM_ARRAY_TASK_ID, runs perfectScaler once, and records it. Only 8 intensities are on offer, so the modulo means each gets run three or four times.

Notice what’s not there: no --step-id. In lesson 02 all 13 runs were steps of one job and shared a $SLURM_JOB_ID, so slurmise needed the step counter to keep the records apart. An array task is a job in its own right, with its own id, so there is nothing to disambiguate.

That’s the trade. The loop needs one allocation and runs serially; the array needs 26 and runs as wide as the queue lets it.

The numeric arrays#

mkdir -p out_slurm_logs
sbatch --wait run_perfectScaler.sbatch
sbatch --wait run_complexMemScaler.sbatch

--wait on an array waits for the whole array, not just the first task.

bash mock_perfectScaler.sh
bash mock_complexMemScaler.sh
slurmise --toml slurmise.toml print | head -20
complexMemScaler
|--- 32000
|    |--- intensity: () int64 500
|    |--- memory: () int64 1545
|    |--- runtime: () int64 0
|--- 32001
|    |--- intensity: () int64 1000
|    |--- memory: () int64 1970
|    |--- runtime: () int64 0
|--- 32002
|    |--- intensity: () int64 1500
|    |--- memory: () int64 2230
|    |--- runtime: () int64 0
|--- 32003
|    |--- intensity: () int64 2000
|    |--- memory: () int64 2800
|    |--- runtime: () int64 0
|--- 32004
|    |--- intensity: () int64 2500
|    |--- memory: () int64 3375

26 records for each job — comfortably past the ~13 completed runs slurmise wants before it will predict from a model rather than from the toml’s defaults.

Predict#

slurmise keeps one fitted model per base_dir, so fit the job you’re about to ask about:

slurmise update-model --job-name perfectScaler
grep -o '"job_name": "[^"]*"' PolynomialFit/*/fits.json
"job_name": "perfectScaler"
slurmise predict "perfectScaler --intensity 2750"
Predicted runtime: 60
Predicted memory: 2770
Warnings:
  Predicted runtime for job perfectScaler is zero or negative (0).
  Run: slurmise update-model --job-name perfectScaler

2750 was never run — it sits between the 2500 and 3000 that were — and the memory prediction should land near it anyway. Every task here took about a second, recorded as 0 minutes, so runtime falls back to a default with a warning; memory is the interesting one.

slurmise update-model --job-name complexMemScaler
slurmise predict "complexMemScaler --intensity 2750"
Predicted runtime: 60
Predicted memory: 3773
Warnings:
  Predicted runtime for job complexMemScaler is zero or negative (0).
  Run: slurmise update-model --job-name complexMemScaler

Higher, when you get a model answer at all: ../bin/complexMemScaler adds a flat 1000 MB on top of the intensity you ask for, and jitters it by ±20% on the way. That noise sometimes pushes the fit’s error past 20%, and slurmise then returns default_mem with a warning instead — A job whose memory doesn’t sit still covers why.

A feature that isn’t a number#

../bin/categoricalScaler takes a --scaling of linear, quadratic, or cubic, and raises --intensity to that power to decide how much memory to allocate. So the same --intensity 20 means 20 MB, 400 MB, or 8000 MB depending on a word, not a number.

The toml declares that word as a category:

slurmise.toml#
[slurmise]
base_dir = "."

[slurmise.job.perfectScaler]
job_spec = "--intensity {intensity}"
[slurmise.job.perfectScaler.variables]
intensity = {type = "numeric"}

[slurmise.job.complexMemScaler]
job_spec = "--intensity {intensity}"
[slurmise.job.complexMemScaler.variables]
intensity = {type = "numeric"}

[slurmise.job.categoricalScaler]
job_spec = "--intensity {intensity} --scaling {scaling}"
[slurmise.job.categoricalScaler.variables]
intensity = {type = "numeric"}
scaling = {type = "category"}

scaling = {type = "category"} is the only new thing here — intensity is numeric as ever. That one word changes how slurmise stores the job’s history, as the next command shows. The array runs 60 tasks, 20 at each of the three --scaling values:

sbatch --wait run_categoryScaler.sbatch
bash mock_categoryScaler.sh
slurmise --toml slurmise.toml print | grep -A3 'scaling='
|--- scaling=cubic
|    |--- 33002
|    |    |--- intensity: () int64 20
|    |    |--- memory: () int64 8320
--
|--- scaling=linear
|    |--- 33000
|    |    |--- intensity: () int64 20
|    |    |--- memory: () int64 18
--
|--- scaling=quadratic
|    |--- 33001
|    |    |--- intensity: () int64 20
|    |    |--- memory: () int64 380

Look at how print lays those out. The numeric jobs listed their records straight under the job name; this one groups them by category first:

categoricalScaler
|--- scaling=linear
|    |--- ...
|--- scaling=quadratic
|--- scaling=cubic

A category splits the job’s history into separate piles, and each pile is fit separately. That’s the substantive difference from a numeric feature. A model can interpolate --intensity 2750 from runs at 2500 and 3000; there is no such thing as halfway between linear and cubic, so slurmise doesn’t try — it keeps a model per category instead.

The practical consequence is that the ~13-run threshold applies to each pile. The 60 tasks above are 20 per --scaling value, which clears it three times over — but a fourth category added tomorrow would start again from nothing, however much history the other three have.

So fit and ask one category at a time:

slurmise update-model --job-name categoricalScaler
slurmise predict "categoricalScaler --intensity 20 --scaling linear"
Predicted runtime: 60
Predicted memory: 20
Warnings:
  Predicted runtime for job categoricalScaler is zero or negative (0).
  Run: slurmise update-model --job-name categoricalScaler

About 20 MB — --scaling linear means intensity to the first power. Now the same question at the other end of the scale:

slurmise predict "categoricalScaler --intensity 20 --scaling cubic"
Predicted runtime: 60
Predicted memory: 7915
Warnings:
  Predicted runtime for job categoricalScaler is zero or negative (0).
  Memory prediction for job categoricalScaler has high uncertainty.
  Run: slurmise update-model --job-name categoricalScaler

About 8000 MB — 20³. Same job, same --intensity, a four-hundred-fold difference in what it needs, and slurmise has it because it never mixed the two histories together.