Skip to content

Commit 9fd2f96

Browse files
author
Renaud
committed
Implements feature request tudo-r#7
1 parent eb21cd9 commit 9fd2f96

File tree

2 files changed

+31
-17
lines changed

2 files changed

+31
-17
lines changed

R/applyJobFunction.R

+24-15
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
#' @method applyJobFunction ExperimentRegistry
2-
#' @export
3-
applyJobFunction.ExperimentRegistry = function(reg, job, cache) {
4-
algo = cache(getAlgorithmFilePath(reg$file.dir, job$algo.id),
5-
slot = "algo", parts = "algorithm")$fun
1+
# internal function to define a wrappers for job/reduce functions
2+
# that can have optional arguments job, static and dynamic
3+
.applyJobWrapper = function(reg, job, cache, algo) {
64
algo.use = c("job", "static", "dynamic")
75
algo.use = setNames(algo.use %in% names(formals(algo)), algo.use)
8-
6+
97
# encapsulate the loading into functions for lazy loading
108
#
119
# IMPORTANT: Note that the order of the messages in the log files can be confusing.
@@ -15,17 +13,28 @@ applyJobFunction.ExperimentRegistry = function(reg, job, cache) {
1513
parts = getProblemFilePaths(reg$file.dir, job$prob.id)
1614
static = function() cache(parts["static"], slot = "static", impute = NULL)
1715
dynamic = function() calcDynamic(reg, job, static(), cache(parts["dynamic"], slot = "dynamic", impute = NULL))
18-
16+
1917
# switch on algo formals and apply algorithm function
2018
f = switch(sum(c(1L, 2L, 4L)[algo.use]) + 1L,
21-
function(...) algo(...),
22-
function(...) algo(job = job, ...),
23-
function(...) algo(static = static(), ...),
24-
function(...) algo(job = job, static = static(), ...),
25-
function(...) algo(dynamic = dynamic(), ...),
26-
function(...) algo(job = job, dynamic = dynamic(), ...),
27-
function(...) algo(static = static(), dynamic = dynamic(), ...),
28-
function(...) algo(job = job, static = static(), dynamic = dynamic(), ...))
19+
function(...) algo(...),
20+
function(...) algo(job = job, ...),
21+
function(...) algo(static = static(), ...),
22+
function(...) algo(job = job, static = static(), ...),
23+
function(...) algo(dynamic = dynamic(), ...),
24+
function(...) algo(job = job, dynamic = dynamic(), ...),
25+
function(...) algo(static = static(), dynamic = dynamic(), ...),
26+
function(...) algo(job = job, static = static(), dynamic = dynamic(), ...))
27+
f
28+
}
29+
30+
#' @method applyJobFunction ExperimentRegistry
31+
#' @export
32+
applyJobFunction.ExperimentRegistry = function(reg, job, cache) {
33+
algo = cache(getAlgorithmFilePath(reg$file.dir, job$algo.id),
34+
slot = "algo", parts = "algorithm")$fun
35+
36+
# switch on algo formals and apply algorithm function
37+
f = .applyJobWrapper(reg, job, cache, algo)
2938

3039
messagef("Applying Algorithm %s ...", job$algo.id)
3140
do.call(f, job$algo.pars)

R/reduceResultsExperiments.R

+7-2
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,15 @@ reduceResultsExperiments = function(reg, ids, part = NA_character_, fun, ...,
8585
n = length(ids)
8686
info("Reducing %i results...", n)
8787

88+
# setup cache (needed for .applyJobWrapper and loading of static/dynamic)
89+
cache = makeFileCache(use.cache = n > 1L)
90+
8891
impute = if (with.impute) function(job, res, ...) impute.val else fun
89-
getRow = function(j, reg, part, .fun, missing.ok, ...)
92+
getRow = function(j, reg, part, .fun, missing.ok, ...){
93+
.fun <- .applyJobWrapper(reg, j, cache, .fun)
9094
c(list(id = j$id, prob = j$prob.id), j$prob.pars, list(algo = j$algo.id), j$algo.pars, list(repl = j$repl),
91-
.fun(j, BatchJobs:::getResult(reg, j$id, part, missing.ok), ...))
95+
.fun(BatchJobs:::getResult(reg, j$id, part, missing.ok), ...))
96+
}
9297

9398
aggr = data.frame()
9499
ids2 = chunk(ids, chunk.size = block.size, shuffle = FALSE)

0 commit comments

Comments
 (0)