Skip to content

Commit

Permalink
resolve R_LIBS issue on Slurm nodes during R CMD check
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian Carroll committed Oct 17, 2017
1 parent 5cabe18 commit d08d871
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
^.*\.Rproj$
^\.Rproj\.user$
^\.Renviron$
^\.travis\.yml$
^cran-comments\.md
^release\.R
Expand Down
2 changes: 2 additions & 0 deletions .Renviron
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# the check directory must be available to the Slurm nodes:
TEMP=/nfs/scratch/
19 changes: 11 additions & 8 deletions tests/testthat/test-slurm_apply.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ context("slurm_apply")

SLURM = system('sinfo', ignore.stdout = TRUE, ignore.stderr = TRUE)
SLURM_MSG = 'Only test on Slurm head node.'
SLURM_OPTS = list(time = '1')

Sys.setenv(R_TESTS = "")

Expand All @@ -18,14 +19,14 @@ ftest <- function(par_m, par_sd = 1, ...) {
c(s_m = mean(samp), s_sd = sd(samp))
}

## slurm libraries
#test0 <- function(i) Sys.getenv()
#slurm_apply(test0, data.frame(i = c(0)), pkgs = c(), jobname = 'test0', nodes = 1, cpus_per_node = 1)
# ## FIXME
# saveRDS(Sys.getenv(), 'testthat_env.RDS')
# slurm_apply(function (i) Sys.getenv(), data.frame(i = c(0)), pkgs = c(), jobname = 'test0', nodes = 1, cpus_per_node = 1)

test_that("slurm_apply gives correct output", {
if (SLURM) skip(SLURM_MSG)
sjob <- slurm_apply(ftest, pars, jobname = "test1", nodes = 2,
cpus_per_node = 1)
cpus_per_node = 1, slurm_options = SLURM_OPTS)
res <- get_slurm_out(sjob, "table")
res_raw <- get_slurm_out(sjob, "raw")
cleanup_files(sjob)
Expand All @@ -37,7 +38,7 @@ test_that("slurm_apply gives correct output", {
test_that("slurm_apply works with single parameter", {
if (SLURM) skip(SLURM_MSG)
sjob <- slurm_apply(ftest, pars[, 1, drop = FALSE], jobname = "test2",
nodes = 2, cpus_per_node = 1)
nodes = 2, cpus_per_node = 1, slurm_options = SLURM_OPTS)
res <- get_slurm_out(sjob, "table")
cleanup_files(sjob)
expect_equal(pars$par_m, res$s_m, tolerance = 0.01)
Expand All @@ -46,7 +47,7 @@ test_that("slurm_apply works with single parameter", {
test_that("slurm_apply works with single row", {
if (SLURM) skip(SLURM_MSG)
sjob <- slurm_apply(ftest, pars[1, ], nodes = 2, jobname = "test3",
cpus_per_node = 1)
cpus_per_node = 1, slurm_options = SLURM_OPTS)
res <- get_slurm_out(sjob, "table")
cleanup_files(sjob)
expect_equal(sjob$nodes, 1)
Expand All @@ -56,7 +57,8 @@ test_that("slurm_apply works with single row", {
test_that("slurm_apply works with single parameter and single row", {
if (SLURM) skip(SLURM_MSG)
sjob <- slurm_apply(ftest, pars[1, 1, drop = FALSE], jobname = "test4",
nodes = 2, cpus_per_node = 1)
nodes = 2, cpus_per_node = 1,
slurm_options = SLURM_OPTS)
res <- get_slurm_out(sjob, "table")
cleanup_files(sjob)
expect_equal(pars$par_m[1], res$s_m, tolerance = 0.01)
Expand All @@ -67,7 +69,8 @@ test_that("slurm_apply correctly handles add_objects", {
sjob <- slurm_apply(function(i) ftest(pars[i, 1], pars[i, 2]),
data.frame(i = 1:nrow(pars)),
add_objects = c('ftest', 'pars'), jobname = "test5",
nodes = 2, cpus_per_node = 1)
nodes = 2, cpus_per_node = 1,
slurm_options = SLURM_OPTS)
res <- get_slurm_out(sjob, "table")
cleanup_files(sjob)
expect_equal(pars, res, tolerance = 0.01, check.attributes = FALSE)
Expand Down
5 changes: 3 additions & 2 deletions tests/testthat/test-slurm_call.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ context("slurm_call")

SLURM = system('sinfo', ignore.stdout = TRUE, ignore.stderr = TRUE)
SLURM_MSG = 'Only test on Slurm head node.'
SLURM_OPTS = list(time = '1')

Sys.setenv(R_TESTS = "")

Expand All @@ -11,7 +12,7 @@ test_that("slurm_job name is correctly edited and output is correct", {
z <- 0
sjob <- slurm_call(function(x, y) x * 2 + y + z, list(x = 5, y = 6),
add_objects = c('z'),
jobname = "test^\\* call")
jobname = "test^\\* call", slurm_options = SLURM_OPTS)
res <- get_slurm_out(sjob)
cleanup_files(sjob)
expect_equal(sjob$jobname, "test_call")
Expand All @@ -27,7 +28,7 @@ test_that("slurm_call will handle a bytecoded function", {
y = 0:100),
formula = y ~ x)
result_local <- do.call(lm, params)
sjob <- slurm_call(lm, params, slurm_options = list(partition = 'sesynctest'))
sjob <- slurm_call(lm, params, slurm_options = SLURM_OPTS)
result_slurm <- get_slurm_out(sjob)
cleanup_files(sjob)
expect_equal(result_slurm$coeficients, result_local$coeficients)
Expand Down

0 comments on commit d08d871

Please sign in to comment.