makeRegistry
constructs the inter-communication object for all functions in batchtools
.
All communication transactions are processed via the file system:
All information required to run a job is stored as JobCollection
in a file in the
a subdirectory of the file.dir
directory.
Each jobs stores its results as well as computational status information (start time, end time, error message, ...)
also on the file system which is regular merged parsed by the master using syncRegistry
.
After integrating the new information into the Registry, the Registry is serialized to the file system via saveRegistry
.
Both syncRegistry
and saveRegistry
are called whenever required internally.
Therefore it should be safe to quit the R session at any time.
Work can later be resumed by calling loadRegistry
which de-serializes the registry from
the file system.
The registry created last is saved in the package namespace (unless make.default
is set to
FALSE
) and can be retrieved via getDefaultRegistry
.
Canceled jobs and jobs submitted multiple times may leave stray files behind.
These can be swept using sweepRegistry
.
clearRegistry
completely erases all jobs from a registry, including log files and results,
and thus allows you to start over.
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
.
Value
[environment
] of class “Registry” with the following slots:
file.dir
[path]:File directory.
work.dir
[path]:Working directory.
temp.dir
[path]:Temporary directory. Used if
file.dir
isNA
to create temporary registries.packages
[character()]:Packages to load on the slaves.
namespaces
[character()]:Namespaces to load on the slaves.
seed
[integer(1)]:Registry seed. Before each job is executed, the seed
seed + job.id
is set.cluster.functions
[cluster.functions]:Usually set in your
conf.file
. Set via a call tomakeClusterFunctions
. See example.default.resources
[named list()]:Usually set in your
conf.file
. Named list of default resources.max.concurrent.jobs
[integer(1)]:Usually set in your
conf.file
. Maximum number of concurrent jobs for a single user and current registry on the system.submitJobs
will try to respect this setting. The resource “max.concurrent.jobs” has higher precedence.defs
[data.table]:Table with job definitions (i.e. parameters).
status
[data.table]:Table holding information about the computational status. Also see
getJobStatus
.resources
[data.table]:Table holding information about the computational resources used for the job. Also see
getJobResources
.tags
[data.table]:Table holding information about tags. See Tags.
hash
[character(1)]:Unique hash which changes each time the registry gets saved to the file system. Can be utilized to invalidate the cache of knitr.
Details
Currently batchtools understands the following options set via the configuration file:
cluster.functions
:As returned by a constructor, e.g.
makeClusterFunctionsSlurm
.default.resources
:List of resources to use. Will be overruled by resources specified via
submitJobs
.temp.dir
:Path to directory to use for temporary registries.
sleep
:Custom sleep function. See
waitForJobs
.expire.after
:Number of iterations before treating jobs as expired in
waitForJobs
.compress
:Compression algorithm to use via
saveRDS
.
See also
Other Registry:
clearRegistry()
,
getDefaultRegistry()
,
loadRegistry()
,
removeRegistry()
,
saveRegistry()
,
sweepRegistry()
,
syncRegistry()
Examples
tmp = makeRegistry(file.dir = NA, make.default = FALSE)
#> No readable configuration file found
#> Created registry in '/tmp/batchtools-example/reg' using cluster functions 'Interactive'
print(tmp)
#> Job Registry
#> Backend : Interactive
#> File dir : /tmp/batchtools-example/reg
#> Work dir : /home/runner/work/batchtools/batchtools/docs/dev/reference
#> Jobs : 0
#> Seed : 5075
#> Writeable: TRUE
# Set cluster functions to interactive mode and start jobs in external R sessions
tmp$cluster.functions = makeClusterFunctionsInteractive(external = TRUE)
# Change packages to load
tmp$packages = c("MASS")
saveRegistry(reg = tmp)
#> [1] TRUE