prioritizr / prioritizr

Systematic conservation prioritization in R

Home Page:https://prioritizr.net

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Information on use in clusters

andresrj opened this issue · comments

Hi, I´ve been looking in the documentation but with no luck. Is there any guide/example of how to use prioritizr::solver in a cluster with SLURM?

Thank you!

Thanks for reaching out @andresrj!

I'm sorry, I've never used SLURM before. Based on reading this web site (https://help.rc.ufl.edu/doc/Sample_SLURM_Scripts), it seems that you need to write a plain text file (possibly BASH script?) with (1) some comments containing job requirements (e.g. CPU usage and RAM usage) and (2) some system commands that tell it how to run the code. I would suggest writing an R script that contains the R code for running prioritizr and then calling it in in the SLURM job file. I'm guessing something like this might work as a starting point?

SLURM file (note that you might need to change some things, e.g., modules, email address, file paths)

#!/bin/bash
#SBATCH --job-name=prioritizr-run      # Job name
#SBATCH --mail-type=END,FAIL         # Mail events (NONE, BEGIN, END, FAIL, ALL)
#SBATCH --mail-user=email@ufl.edu    # Where to send mail	
#SBATCH --nodes=1                    # Run all processes on a single node	
#SBATCH --ntasks=1                   # Run a single task		
#SBATCH --cpus-per-task=4            # Number of CPU cores per task
#SBATCH --mem=5gb                    # Job memory request
#SBATCH --time=00:05:00              # Time limit hrs:min:sec
#SBATCH --output=prioritizr-run-%j.log     # Standard output and error log
pwd; hostname; date

module load R

R CMD BATCH --no-restore --no-save prioritizr-code.R

/data/training/SLURM/prime/prime

date

R script (saved in file prioritizr-code.R):

# load packages
library(prioritizr)

# load data
data(sim_pu_raster, sim_features)

# create problem
p <- problem(sim_pu_raster, sim_features) %>%
     add_min_set_objective() %>%
     add_relative_targets(0.1) %>%
     add_binary_decisions() %>%
     add_cbc_solver(gap = 0, verbose = FALSE)

# generate solution
s <- solve(p)

# save solution
saveRDS(s, "results.rds")

Does that help?

@andresrj, I just wanted to follow up and ask if you were able to get prioritizr running on the cluster?

Yes, thank you very much. I contacted gurobi and obtained an academic licence for the cluster in our university (it seemed that was the problem because we use gurobi as prioritizr solver). I even had the chance to play a little with singularity and that way avoid other library errors I was getting from my R script launched with SLURM... It was really a lot to learn but a nice experience after all (and I still have a lot to learn from prioritizr website. Thanks!)

Awesome! It sounds like everything's working now - is that right? If so, would you mind if I closed the issue? Happy to answer any more questions if that's helpful?

Yes, I have it working and now to learn how to use it properly. Thank you very much, you have been very helpful! :D

No worries - happy to help!