makeExperimentRegistry
constructs a special Registry
which
is suitable for the definition of large scale computer experiments.
Each experiments consists of a Problem
and an Algorithm
.
These can be parametrized with addExperiments
to actually define computational
jobs.
Arguments
- file.dir
[
character(1)
]
Path where all files of the registry are saved. Default is directory “registry” in the current working directory. The provided path will get normalized unless it is given relative to the home directory (i.e., starting with “~”). Note that some templates do not handle relative paths well.If you pass
NA
, a temporary directory will be used. This way, you can create disposable registries forbtlapply
or examples. By default, the temporary directorytempdir()
will be used. If you want to use another directory, e.g. a directory which is shared between nodes, you can set it in your configuration file by setting the variabletemp.dir
.- work.dir
[
character(1)
]
Working directory for R process for running jobs. Defaults to the working directory currently set during Registry construction (seegetwd
).loadRegistry
uses the storedwork.dir
, but you may also explicitly overwrite it, e.g., after switching to another system.The provided path will get normalized unless it is given relative to the home directory (i.e., starting with “~”). Note that some templates do not handle relative paths well.
- conf.file
[
character(1)
]
Path to a configuration file which is sourced while the registry is created. In the configuration file you can define how batchtools interacts with the system viaClusterFunctions
. Separating the configuration of the underlying host system from the R code allows to easily move computation to another site.The file lookup is implemented in the internal (but exported) function
findConfFile
which returns the first file found of the following candidates:File “batchtools.conf.R” in the path specified by the environment variable “R_BATCHTOOLS_SEARCH_PATH”.
File “batchtools.conf.R” in the current working directory.
File “config.R” in the user configuration directory as reported by
rappdirs::user_config_dir("batchtools", expand = FALSE)
(depending on OS, e.g., on linux this usually resolves to “~/.config/batchtools/config.R”).“.batchtools.conf.R” in the home directory (“~”).
“config.R” in the site config directory as reported by
rappdirs::site_config_dir("batchtools")
(depending on OS). This file can be used for admins to set sane defaults for a computation site.
Set to
NA
if you want to suppress reading any configuration file. If a configuration file is found, it gets sourced inside the environment of the registry after the defaults for all variables are set. Therefore you can set and overwrite slots, e.g.default.resources = list(walltime = 3600)
to set default resources or “max.concurrent.jobs” to limit the number of jobs allowed to run simultaneously on the system.- packages
[
character
]
Packages that will always be loaded on each node. Usesrequire
internally. Default ischaracter(0)
.- namespaces
[
character
]
Same aspackages
, but the packages will not be attached. UsesrequireNamespace
internally. Default ischaracter(0)
.- source
[
character
]
Files which should be sourced on the slaves prior to executing a job. Callssys.source
using the.GlobalEnv
.- load
[
character
]
Files which should be loaded on the slaves prior to executing a job. Callsload
using the.GlobalEnv
.- seed
[
integer(1)
]
Start seed for jobs. Each job uses the (seed
+job.id
) as seed. Default is a random integer between 1 and 32768. Note that there is an additional seeding mechanism to synchronize instantiation ofProblem
s in aExperimentRegistry
.- make.default
[
logical(1)
]
If set toTRUE
, the created registry is saved inside the package namespace and acts as default registry. You might want to switch this off if you work with multiple registries simultaneously. Default isTRUE
.
Examples
tmp = makeExperimentRegistry(file.dir = NA, make.default = FALSE)
#> No readable configuration file found
#> Created registry in '/tmp/batchtools-example/reg' using cluster functions 'Interactive'
# Definde one problem, two algorithms and add them with some parameters:
addProblem(reg = tmp, "p1",
fun = function(job, data, n, mean, sd, ...) rnorm(n, mean = mean, sd = sd))
#> Adding problem 'p1'
addAlgorithm(reg = tmp, "a1", fun = function(job, data, instance, ...) mean(instance))
#> Adding algorithm 'a1'
addAlgorithm(reg = tmp, "a2", fun = function(job, data, instance, ...) median(instance))
#> Adding algorithm 'a2'
ids = addExperiments(reg = tmp, list(p1 = data.table::CJ(n = c(50, 100), mean = -2:2, sd = 1:4)))
#> Adding 40 experiments ('p1'[40] x 'a1'[1] x repls[1]) ...
#> Adding 40 experiments ('p1'[40] x 'a2'[1] x repls[1]) ...
# Overview over defined experiments:
tmp$problems
#> [1] "p1"
tmp$algorithms
#> [1] "a1" "a2"
summarizeExperiments(reg = tmp)
#> problem algorithm .count
#> <char> <char> <int>
#> 1: p1 a1 40
#> 2: p1 a2 40
summarizeExperiments(reg = tmp, by = c("problem", "algorithm", "n"))
#> problem algorithm n .count
#> <char> <char> <num> <int>
#> 1: p1 a1 50 20
#> 2: p1 a1 100 20
#> 3: p1 a2 50 20
#> 4: p1 a2 100 20
ids = findExperiments(prob.pars = (n == 50), reg = tmp)
print(unwrap(getJobPars(ids, reg = tmp)))
#> Key: <job.id>
#> job.id problem algorithm n mean sd
#> <int> <char> <char> <num> <int> <int>
#> 1: 1 p1 a1 50 -2 1
#> 2: 2 p1 a1 50 -2 2
#> 3: 3 p1 a1 50 -2 3
#> 4: 4 p1 a1 50 -2 4
#> 5: 5 p1 a1 50 -1 1
#> 6: 6 p1 a1 50 -1 2
#> 7: 7 p1 a1 50 -1 3
#> 8: 8 p1 a1 50 -1 4
#> 9: 9 p1 a1 50 0 1
#> 10: 10 p1 a1 50 0 2
#> 11: 11 p1 a1 50 0 3
#> 12: 12 p1 a1 50 0 4
#> 13: 13 p1 a1 50 1 1
#> 14: 14 p1 a1 50 1 2
#> 15: 15 p1 a1 50 1 3
#> 16: 16 p1 a1 50 1 4
#> 17: 17 p1 a1 50 2 1
#> 18: 18 p1 a1 50 2 2
#> 19: 19 p1 a1 50 2 3
#> 20: 20 p1 a1 50 2 4
#> 21: 41 p1 a2 50 -2 1
#> 22: 42 p1 a2 50 -2 2
#> 23: 43 p1 a2 50 -2 3
#> 24: 44 p1 a2 50 -2 4
#> 25: 45 p1 a2 50 -1 1
#> 26: 46 p1 a2 50 -1 2
#> 27: 47 p1 a2 50 -1 3
#> 28: 48 p1 a2 50 -1 4
#> 29: 49 p1 a2 50 0 1
#> 30: 50 p1 a2 50 0 2
#> 31: 51 p1 a2 50 0 3
#> 32: 52 p1 a2 50 0 4
#> 33: 53 p1 a2 50 1 1
#> 34: 54 p1 a2 50 1 2
#> 35: 55 p1 a2 50 1 3
#> 36: 56 p1 a2 50 1 4
#> 37: 57 p1 a2 50 2 1
#> 38: 58 p1 a2 50 2 2
#> 39: 59 p1 a2 50 2 3
#> 40: 60 p1 a2 50 2 4
#> job.id problem algorithm n mean sd
# Submit jobs
submitJobs(reg = tmp)
#> Submitting 80 jobs in 80 chunks using cluster functions 'Interactive' ...
waitForJobs(reg = tmp)
#> [1] TRUE
# Reduce the results of algorithm a1
ids.mean = findExperiments(algo.name = "a1", reg = tmp)
reduceResults(ids.mean, fun = function(aggr, res, ...) c(aggr, res), reg = tmp)
#> [1] -2.00073766 -1.83988515 -2.19491590 -1.88744748 -1.16661898 -1.01586977
#> [7] -0.52913619 -0.63585094 -0.09331735 0.11880843 0.22120996 1.22939842
#> [13] 1.00632897 1.26918801 2.11616673 1.81935795 1.90243597 1.93950861
#> [19] 2.33621891 2.81313094 -1.95745534 -2.29431806 -1.82269005 -1.80889629
#> [25] -0.91933173 -1.03820621 -0.95531362 -1.49309041 0.09203207 0.05360571
#> [31] 0.04219920 -0.11534443 1.14488890 0.83504259 0.82821428 1.07835718
#> [37] 2.06274541 2.28296085 2.26426388 1.74159301
# Join info table with all results and calculate mean of results
# grouped by n and algorithm
ids = findDone(reg = tmp)
pars = unwrap(getJobPars(ids, reg = tmp))
results = unwrap(reduceResultsDataTable(ids, fun = function(res) list(res = res), reg = tmp))
tab = ljoin(pars, results)
tab[, list(mres = mean(res)), by = c("n", "algorithm")]
#> n algorithm mres
#> <num> <char> <num>
#> 1: 50 a1 0.270398674
#> 2: 100 a1 0.001062847
#> 3: 50 a2 0.068935673
#> 4: 100 a2 0.020262158