Nicholas Dodds

JAGS on Hopper

JAGS on Hopper

Set up R and JAGS in your own Hopper account, run a small Bayesian model, and download the results. No administrator install needed.

Tested October 2026 on Hopper with R 4.5.3, JAGS 4.3.2 and jagsUI 1.6.3. Setup takes 20–30 minutes plus any queue wait; see Testing and references.

What you'll build

R and JAGS in a Conda environment in your own Hopper account, and a starter project that submits models as Slurm jobs and writes results and plots you can download.

Quick start

Already have a Hopper account and the JAGS environment? Download the starter (step 1), then run this in the extracted folder. If you have Conda but not the environment, run bash setup.sh first. Otherwise, start with Before you start.

source ./activate.sh
bash submit.sh

The first time, enter your Slurm account and partition when asked; they're remembered for this folder. Then check the job:

bash status.sh

Before you start

Copy one command block at a time, and stop if one fails. Model fitting runs as a scheduled job, never on the login node.

1. Connect and download

  1. Connect to your college VPN. Then log in, replacing YOUR_USERNAME with your Hopper username:

    ssh YOUR_USERNAME@hopper.mckenna.edu

    The first time you connect, SSH asks whether to trust the server. Find the algorithm your prompt names and compare its SHA256 fingerprint before typing yes. If the key differs, don't connect; ask Hopper support.

    AlgorithmSHA256 fingerprint
    ED25519SHA256:jt8F40xEaVV+ITKozzR5jFrfJTe7O5HhQg9vS8w73dU
    ECDSASHA256:o32TmYIa3Qxl8KNcD8dLc5QwV75oA8fvIqiTbZ+H3v4
    RSASHA256:GpcwMVW4H/Mo664eVBwb8x5aYzrm6CtE+BAyP00QPOY

    Read on October 5, 2026 over an established, authenticated connection to hopper.mckenna.edu. This is a dated observation, not an administrator's key notice.

    Then type your password; nothing appears as you type.

  2. Download and extract the starter on Hopper:

    mkdir -p "$HOME/jags-workshop"
    cd "$HOME/jags-workshop"
    curl -fL -O https://www.cs.hmc.edu/~ndodds/guides/hopper-jags/hopper-jags-starter.zip
    unzip -n hopper-jags-starter.zip
    cd hopper-jags-starter

    unzip -n keeps files that are already there. To use a later starter release, extract it into a new folder so it doesn't mix with your edited model. If unzip isn't available, extract the ZIP on your computer and copy the folder over with scp.

Download starter ZIP 340 KB The same ZIP as at the top of the page.

The download contains:

FilePurpose
setup.sh, install-jagsUI.RInstall the tested software versions
activate.shActivate the environment after each login
hello.R, run.sbatchExample model and Slurm job script
submit.sh, status.shSubmit jobs and check their results
research-template.RStarting structure for your own model
guide.html, README.mdOffline instructions
validated-demo.pdfReference plots
VALIDATION.txtWhat was tested and what remains untested

2. Check your account

You log in to a login node to edit files and submit work. Slurm, the scheduler, runs jobs on compute nodes. A partition is a queue with resource and time limits. A Slurm account identifies your allocation; it may differ from your username or lab group.

hostname
uname -m
printf 'Shell: %s\n' "$SHELL"
command -v conda
module list
sinfo -s
sacctmgr -nP show assoc where user="$USER" format=Account,Partition

Note your account name for the first submission. The demo uses two cores, 2 GB of RAM and five minutes. Hopper's debug limit was one hour when tested; main allows up to three days, subject to account policy. Check your quota if space is tight.

3. Make Conda available

This step installs Miniforge, a minimal Conda, in your home directory. Any working Miniconda, Miniforge or Anaconda is enough, so check for one first; the first two items let you skip ahead if you have one.

  1. Check whether Conda already works:

    conda --version

    If it prints a version, load it and continue to step 4:

    source "$(conda info --base)/etc/profile.d/conda.sh"
  2. If not, look for an installation that isn't loaded:

    ls -d "$HOME/miniconda3" "$HOME/miniforge3" "$HOME/anaconda3" 2>/dev/null

    If one is listed, load it, then continue to step 4. This loads miniconda3; use miniforge3 or anaconda3 instead if that's what you have:

    source "$HOME/miniconda3/etc/profile.d/conda.sh"
    conda --version
  3. Otherwise, install Miniforge. These are Linux commands run on Hopper, even if your computer is a Mac or Windows machine. They download a versioned installer from the official Miniforge project and its checksum, and verify it:

    mkdir -p "$HOME/software-installers"
    cd "$HOME/software-installers"
    curl -fL -O https://github.com/conda-forge/miniforge/releases/download/26.7.2-0/Miniforge3-26.7.2-0-Linux-x86_64.sh
    curl -fL -O https://github.com/conda-forge/miniforge/releases/download/26.7.2-0/Miniforge3-26.7.2-0-Linux-x86_64.sh.sha256
    sha256sum -c Miniforge3-26.7.2-0-Linux-x86_64.sh.sha256

    Continue only if the result ends in OK:

    ./Miniforge3-26.7.2-0-Linux-x86_64.sh: OK
  4. Run the installer:

    bash Miniforge3-26.7.2-0-Linux-x86_64.sh

    Press Enter to read the license, type yes if you accept it, press Enter for the default location, and answer no to shell initialization. If the destination already exists, load that installation instead of replacing it.

  5. When the prompt returns, load Conda and go back to the starter:

    source "$HOME/miniforge3/etc/profile.d/conda.sh"
    conda --version
    cd "$HOME/jags-workshop/hopper-jags-starter"

4. Install and activate JAGS

  1. For a new environment, run the setup once:

    cd "$HOME/jags-workshop/hopper-jags-starter"
    bash setup.sh

    It installs R, JAGS and their dependencies from conda-forge into $HOME/.conda/envs/jags, then installs jagsUI from CRAN, accepting the Conda package plan automatically. If the environment already exists, skip this step.

  2. Activate and verify:

    source ./activate.sh
    command -v R Rscript
    Rscript --vanilla -e 'cat(R.version.string,"\n"); library(rjags); library(jagsUI); print(jags.version()); print(packageVersion("jagsUI"))'

R and Rscript are inside .conda/envs/jags/bin, and the versions are R 4.5.3, JAGS 4.3.2 and jagsUI 1.6.3. A message that traceplot is “masked” is normal: two packages define a function with that name.

The helper saves your Conda path in conda-base.txt. After each new login, go back to the folder and run source ./activate.sh. Scheduled jobs use the same helper.

5. Submit your first model

  1. Submit the example:

    bash submit.sh

    The first time, enter your Slurm account and a partition you're authorized for, usually debug for this short test. Once Slurm accepts the job, the helper saves them in .slurm-settings and the job ID in last-job-id.txt, so they survive reconnecting. Later submissions show the saved values first.

  2. Check on it:

    bash status.sh

    A pending job is waiting for resources and a running job needs more time; check again later.

Success shows the PASS line and a completed job with exit code 0:0. Your job ID will differ.

PASS: parallel JAGS sampling completed successfully.
JobID             State ExitCode
366462        COMPLETED      0:0
366462.batch  COMPLETED      0:0

The job writes hello-fit.rds, hello-summary.csv, hello-diagnostics.pdf and hello-session.txt. Email your job ID and PASS line to ndodds@g.hmc.edu.

Each run replaces the last results

Running again in the same folder replaces the result files. Finish one run before starting another, and use separate project copies to keep experiments apart.

6. Read the results

Open another terminal on your computer and change to the folder where you want the results. Replace YOUR_USERNAME:

scp 'YOUR_USERNAME@hopper.mckenna.edu:~/jags-workshop/hopper-jags-starter/hello-*' .

Open the CSV and PDF. The reference PDF shows the same example.

Two-chain trace plot
Both chains move around 2 with no lasting trend.
Posterior density for the example mean
The density centres near 2; its width shows the uncertainty about the mean.

How the numerical check works

The observations are 1.8, 2.1, 2.0, 1.9, 2.2, with standard deviation fixed at 1. The prior for the mean has mean 0 and standard deviation 10. JAGS works in precision (1 divided by variance), so the model uses precisions 1 and 0.01.

The analytic posterior mean is 10 / 5.01 ≈ 1.996, with standard deviation sqrt(1 / 5.01) ≈ 0.447. The check needs finite draws and a sampled mean within 0.15 of the analytic mean. It keeps 1,500 samples per chain (3,000 in total) after 500 adaptation iterations.

It's a software check. Passing it, or an Rhat near 1, says nothing about another model's assumptions or convergence.

Try a small change

  1. Open the example:

    nano hello.R
  2. Change y <- c(1.8, 2.1, 2.0, 1.9, 2.2) to y <- c(2.8, 3.1, 3.0, 2.9, 3.2). Save with Control + O and Enter, then exit with Control + X.
  3. Run bash submit.sh and bash status.sh again. The expected mean becomes 15 / 5.01 ≈ 2.994, and the check adjusts automatically.
  4. Put the original observations back when you're done.

7. Run your research model

  1. Copy the starter to a new project folder. my-project must not already exist; pick another name if it does.

    cd "$HOME/jags-workshop"
    cp -r hopper-jags-starter my-project
    cd my-project
    cp research-template.R analysis.R
    source ./activate.sh
  2. Edit analysis.R to load your data and JAGS model. The template deliberately stops until you replace its example. It already uses the Slurm CPU allocation, saves results and records R session information.

    If we're working through your model together, bring your script, a small dataset, your package list and any custom JAGS modules.

  3. Submit it to main or another longer partition you're authorized for, not debug with its one-hour limit. This example asks for four cores, 4 GB of RAM and two hours; adjust for your model and account limits.

    bash submit.sh analysis.R --partition main --cpus-per-task 4 --mem 4G --time 02:00:00
    bash status.sh

The copied folder keeps your saved account, and a successful submission saves main as this project's partition. The helper accepts --account, --partition, --cpus-per-task, --mem, --time and --job-name, as --name value or --name=value; see bash submit.sh --help.

Paths are relative to the project folder. Rscript --vanilla doesn't restore a saved workspace, so load all data and packages explicitly. Keep parallel workers within your allocated CPUs. Start small, check resource use with status.sh, and look at mixing, effective sample size, Rhat and model-specific diagnostics before interpreting results.

8. Keep a reproducibility record

Once your model runs, save its environment alongside the code, the input data version, seeds and job settings:

source ./activate.sh
conda list --explicit > conda-linux-64-explicit.txt
conda env export --no-builds > environment-record.yml
Rscript --vanilla -e 'write.csv(installed.packages()[,c("Package","Version","LibPath")], "r-packages.csv", row.names=FALSE); writeLines(capture.output(sessionInfo()), "session-info.txt")'

Conda's exports don't fully describe jagsUI, which comes from CRAN, so keep install-jagsUI.R and r-packages.csv too. The installer picks jagsUI 1.6.3 from current CRAN or, if needed, CRAN's archive.

Recreate the environment

From a folder with the export and installer files, create a new environment. This accepts the exported package plan automatically:

conda create --yes --prefix "$HOME/.conda/envs/jags-reproduced" --file conda-linux-64-explicit.txt
conda activate "$HOME/.conda/envs/jags-reproduced"
Rscript --vanilla install-jagsUI.R

This was tested on Hopper, including a successful scheduled demo in the rebuilt environment. To use it with the helpers, run export JAGS_ENV_PREFIX="$HOME/.conda/envs/jags-reproduced" before activating and submitting; unset JAGS_ENV_PREFIX returns to the default. The exports work on compatible Hopper Linux systems, not on your Mac or Windows R.

Troubleshooting

SymptomWhat to do
conda: command not foundLoad your existing installation (step 3), or install Miniforge.
Run 'conda init' before 'conda activate'Use source ./activate.sh, or source your installation's conda.sh.
Permission denied when logging inCheck the VPN, username and password; contact support if it continues.
Permission denied during setupMake sure the destination is in your own home directory.
Environment already existsSkip setup, then activate and verify.
there is no package called ...Check which R is active and read the first installation error.
rjags can't find JAGSUse R and JAGS from the same Conda environment.
Invalid account or account/partition combination specifiedCheck your account list; retry with --reset or give the account and partition explicitly.
Saved settings are wrong or garbledRun bash submit.sh --reset. Settings are only saved after a submission is accepted.
No log, or the job is PENDINGWait for resources, then check the status again.
OUT_OF_MEMORY, TIMEOUT, or no PASSRead the log before changing resource requests.
Quota or checksum errorStop and keep the error; check your quota or retry the official download.

For help, email ndodds@g.hmc.edu or hpc-help@its.cmc.edu with your command, the full error, the job ID and the log. Never send a password. To cancel one of your jobs, run scancel followed by its job ID.

Testing and references

The example, a fresh installation, Miniforge setup, the plots and the downloaded starter were tested on Hopper; VALIDATION.txt in the ZIP has the details. Your own access and research dependencies still need checking.

The Miniforge installer was tested in batch mode, while this guide uses its interactive prompts. The fallback to CRAN's archive hasn't been exercised, because jagsUI 1.6.3 is still on current CRAN.