Created
May 30, 2018 01:08
-
-
Save benfasoli/c36b9d517c333685d1e50b9676d892ea to your computer and use it in GitHub Desktop.
Verify that a list column of a data frame is passed through rslurm::slurm_apply to mapped function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Ben Fasoli | |
# Check that rslurm::slurm_apply accepts a list as a dataframe column | |
library(rslurm) | |
slurm_options <- list( | |
time = '300:00:00', | |
account = 'lin-kp', | |
partition = 'lin-kp' | |
) | |
fun <- function(x, y) { | |
str(y) | |
m <- matrix(1:(x * y), nrow = x, ncol = mean(y)) | |
mean(m) | |
} | |
args <- data.frame(x = 1:100, y = 1:100) | |
args$y <- as.list(args$y) | |
args$y <- lapply(args$y, function(x) c(x, 10*x)) | |
# Remove previous _rslurm dumps | |
system('rm -r _rslurm_*') | |
# Run fun on each row of args | |
output <- slurm_apply(fun, args, nodes = 1, | |
cpus_per_node = 16, slurm_options = slurm_options) | |
# Pause while slurm job completes | |
wait_for_slurm <- function(slr_job) { | |
cmd <- paste('squeue -hn', slr_job$jobname) | |
while (length(system(cmd, intern = T)) > 0) { | |
Sys.sleep(1) | |
} | |
} | |
wait_for_slurm(output) | |
# Grab slurm dump of the structure of argument y | |
id <- dir('.', '_rslurm') | |
system(paste('head', (file.path(id, 'slurm_0.out')))) | |
# num [1:2] 1 10 | |
# num [1:2] 17 170 | |
# num [1:2] 33 330 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment