Atharva Bhagwat

Taking your work to the HPC cluster

0Plan
Part 2

What this guide was for, when a laptop stops being enough, and how to move the same project onto the cluster. No stars here, just a map.

What this guide was really for

Your laptop is where you learn and where you develop. Data is small, feedback is instant, and a mistake costs seconds. Everything in the earlier stages was practice for the habits that make a cluster usable later:

Habit you builtWhy the cluster needs it
Isolated environment plus environment.ymlYou rebuild the exact same Python on the cluster in one command.
Scripts like make_figure.pyA cluster job runs a script, not a notebook you click through.
Relative paths from a project rootThe same code runs in a different folder on a different machine.
Functions with parametersOne script can process any sample or setting you hand it.
Raw data never edited, results regeneratedJobs can be re-run safely, and you always know where an output came from.
Reading the last line of an errorFailed jobs leave you a log file full of tracebacks. You already know how to read one.

When do you actually need HPC?

Not for this dataset: four thousand rows fit on any laptop. Develop small, then scale up when one of these happens:

  • Memory: you hit MemoryError, or your laptop starts crawling because the data does not fit in RAM.
  • Time: one run takes hours, or you need to repeat it for many samples or many parameter settings.
  • Hardware: you need many cores at once, or a GPU.

The same project, on the cluster

  1. Get access. Request an account and read how resources are allocated: getting an account and requesting resources.
  2. Log in. Use a terminal (SSH) or the browser portal (Open OnDemand). OnDemand also offers Python and Jupyter sessions if you want a notebook on a compute node.
  3. Bring your code. Put the project in a Git repository on your laptop, then git clone it on the cluster. Code travels through Git; it keeps a history and avoids "which copy is newest?".
  4. Bring your data. Large files go through a transfer tool, not Git. See file transfer (Globus is the usual choice) and the file systems page to decide where files should live. Big temporary files belong in scratch.
  5. Rebuild the environment. Load conda or Python the way the Python page describes, then recreate yours: conda env create -f environment.yml. This is why you saved it in Stage 11.
  6. Test on a small slice. Ask for a short interactive job, run your script on a few rows, and fix errors where you can see them.
  7. Submit a batch job. Write a short job script and hand it to Slurm (batch jobs).
  8. Check, then copy results home. Read the log, confirm the outputs look right, and copy results/ back to your laptop for figures and writing.

A job script

A batch script is a shell script with #SBATCH lines that tell Slurm what to reserve. The names of clusters and partitions, and sensible memory and time requests, are specific to your group; copy real values from the manual rather than from this sketch.

run_make_figures.sh
#!/bin/bash
#SBATCH --job-name=make-figures
#SBATCH --cluster=CLUSTER_NAME        # placeholder: copy real values from the manual
#SBATCH --partition=PARTITION_NAME    # placeholder
#SBATCH --nodes=1
#SBATCH --cpus-per-task=4
#SBATCH --mem=16G
#SBATCH --time=01:00:00
#SBATCH --output=logs/%x-%j.out       # %x = job name, %j = job id

# 1. make the same Python the same way you did on your laptop
#    (how to load conda or Python on the cluster is on the manual's Python page)
conda activate pybio

# 2. run from the project root so relative paths behave
cd "$SLURM_SUBMIT_DIR"

# 3. run the script, not a notebook
python make_figure.py

Submit it and keep an eye on it:

terminal on the cluster
mkdir -p logs
sbatch run_make_figures.sh     # prints: Submitted batch job 12345678
squeue --me                    # what is queued or running
sacct -j 12345678              # what happened, after it finishes
scancel 12345678               # stop it

Habits that make cluster work painless

  • Develop small, run big. Add a small slice or a --sample option to your script so you can test in seconds.
  • Many similar tasks? Do not write a loop in one long job; use a job array so each sample runs on its own.
  • Keep sessions alive. tmux and nohup let long-running work survive a dropped connection.
  • Edit comfortably. VS Code can work on cluster files directly: see the VS Code page.
  • Record what you ran. Commit the job script, the environment.yml and the README. Next month, they are your memory.
  • Stuck? Check Common Problems and the main user manual, then ask the support team with the job ID and the last lines of the log.

The full documentation for everything above lives in the CRCD User Manual.

Special thanks to Nilay!