Prepare inputs and write an R script and SLURM submission script to run an INLA model on a SLURM cluster. This function saves model inputs (and optional extra objects) to an .RData file, writes an R script that loads those inputs and runs INLA, and writes a SLURM submission script to run that R script.

run_inla_on_slurm(
  stk_path,
  inla_formula,
  inla_family = "nbinomial",
  inla_control_predictor = list(compute = TRUE),
  inla_control_compute = list(dic = TRUE, waic = TRUE, cpo = TRUE),
  job_name = "INLAjob",
  partition = "fuchs",
  time = "8:00:00",
  ntasks = 1,
  nodes = 1,
  conda_env = "kinh",
  rscript = "run.r",
  work_dir = ".",
  rsave_path = "inla_input.RData",
  submit = FALSE,
  submit_cmd = "sbatch",
  extra_objects = NULL,
  ...
)

Arguments

stk_path

Path to a saved INLA stack (.RData) that contains an object named `stk`.

inla_formula

A formula to pass to INLA.

inla_family

Family name passed to INLA (default: "nbinomial").

inla_control_predictor

List passed to control.predictor (default: list(compute = TRUE)).

inla_control_compute

List passed to control.compute (default: list(dic = TRUE, waic = TRUE, cpo = TRUE)).

job_name, partition, time, ntasks, nodes, conda_env, rscript, work_dir, rsave_path, submit, submit_cmd

See function arguments for SLURM and script control.

partition

SLURM partition to use (default: "fuchs").

time

Walltime for the job (default: "8:00:00").

ntasks

Number of tasks (default: 1).

nodes

Number of nodes (default: 1).

conda_env

Name of the conda environment to activate (default: "kinh").

rscript

Name of the R script file to write (default: "run.r").

work_dir

Working directory where scripts and .RData will be saved (default: current directory).

rsave_path

Path to save the .RData file containing model inputs (default: "inla_input.RData").

submit

set to TRUE to submit the job immediately after writing the scripts.

submit_cmd

Command to use for submission (default: "sbatch").

extra_objects

Named list of additional R objects to save into the .RData file (e.g. list(pc_prec = pc_prec)).

...

Additional unused arguments kept for extensibility.

Value

Invisibly returns a list with paths to the generated files and submission info: list(submitted = logical, rscript = <path>, slurm = <path>, rdata = <path>, output = <submission output if any>).