Estimates the runtimes of jobs using the random forest implemented in ranger.
Observed runtimes are retrieved from the Registry and runtimes are
predicted for unfinished jobs.
The estimated remaining time is calculated in the print method.
You may also pass n here to determine the number of parallel jobs which is then used
in a simple Longest Processing Time (LPT) algorithm to give an estimate for the parallel runtime.
Usage
estimateRuntimes(tab, ..., reg = getDefaultRegistry())
# S3 method for class 'RuntimeEstimate'
print(x, n = 1L, ...)Arguments
- tab
[
data.table]
Table with column “job.id” and additional columns to predict the runtime. Observed runtimes will be looked up in the registry and serve as dependent variable. All columns intabexcept “job.id” will be passed torangeras independent variables to fit the model.- ...
[ANY]
Additional parameters passed toranger. Ignored for theprintmethod.- reg
[
Registry]
Registry. If not explicitly passed, uses the default registry (seesetDefaultRegistry).- x
[
RuntimeEstimate]
Object to print.- n
[
integer(1)]
Number of parallel jobs to assume for runtime estimation.
Value
[RuntimeEstimate] which is a list with two named elements:
“runtimes” is a data.table with columns “job.id”,
“runtime” (in seconds) and “type” (“estimated” if runtime is estimated,
“observed” if runtime was observed).
The other element of the list named “model”] contains the fitted random forest object.
Examples
# Create a simple toy registry
set.seed(1)
tmp = makeExperimentRegistry(file.dir = NA, make.default = FALSE, seed = 1)
#> No readable configuration file found
#> Created registry in '/tmp/batchtools-example/reg' using cluster functions 'Interactive'
addProblem(name = "iris", data = iris, fun = function(data, ...) nrow(data), reg = tmp)
#> Adding problem 'iris'
addAlgorithm(name = "nrow", function(instance, ...) nrow(instance), reg = tmp)
#> Adding algorithm 'nrow'
addAlgorithm(name = "ncol", function(instance, ...) ncol(instance), reg = tmp)
#> Adding algorithm 'ncol'
addExperiments(algo.designs = list(nrow = data.table::CJ(x = 1:50, y = letters[1:5])), reg = tmp)
#> Adding 250 experiments ('iris'[1] x 'nrow'[250] x repls[1]) ...
addExperiments(algo.designs = list(ncol = data.table::CJ(x = 1:50, y = letters[1:5])), reg = tmp)
#> Adding 250 experiments ('iris'[1] x 'ncol'[250] x repls[1]) ...
# We use the job parameters to predict runtimes
tab = unwrap(getJobPars(reg = tmp))
# First we need to submit some jobs so that the forest can train on some data.
# Thus, we just sample some jobs from the registry while grouping by factor variables.
library(data.table)
ids = tab[, .SD[sample(nrow(.SD), 5)], by = c("problem", "algorithm", "y")]
setkeyv(ids, "job.id")
submitJobs(ids, reg = tmp)
#> Submitting 50 jobs in 50 chunks using cluster functions 'Interactive' ...
waitForJobs(reg = tmp)
#> [1] TRUE
# We "simulate" some more realistic runtimes here to demonstrate the functionality:
# - Algorithm "ncol" is 5 times more expensive than "nrow"
# - x has no effect on the runtime
# - If y is "a" or "b", the runtimes are really high
runtime = function(algorithm, x, y) {
ifelse(algorithm == "nrow", 100L, 500L) + 1000L * (y %in% letters[1:2])
}
tmp$status[ids, done := done + tab[ids, runtime(algorithm, x, y)]]
#> Key: <job.id>
#> job.id def.id submitted started done error mem.used resource.id
#> <int> <int> <num> <num> <num> <char> <num> <int>
#> 1: 1 1 NA NA NA <NA> NA NA
#> 2: 2 2 NA NA NA <NA> NA NA
#> 3: 3 3 NA NA NA <NA> NA NA
#> 4: 4 4 NA NA NA <NA> NA NA
#> 5: 5 5 NA NA NA <NA> NA NA
#> ---
#> 496: 496 496 NA NA NA <NA> NA NA
#> 497: 497 497 NA NA NA <NA> NA NA
#> 498: 498 498 NA NA NA <NA> NA NA
#> 499: 499 499 1755115437 1755115437 1755115937 <NA> NA 1
#> 500: 500 500 NA NA NA <NA> NA NA
#> batch.id log.file job.hash job.name repl
#> <char> <char> <char> <char> <int>
#> 1: <NA> <NA> <NA> <NA> 1
#> 2: <NA> <NA> <NA> <NA> 1
#> 3: <NA> <NA> <NA> <NA> 1
#> 4: <NA> <NA> <NA> <NA> 1
#> 5: <NA> <NA> <NA> <NA> 1
#> ---
#> 496: <NA> <NA> <NA> <NA> 1
#> 497: <NA> <NA> <NA> <NA> 1
#> 498: <NA> <NA> <NA> <NA> 1
#> 499: cfInteractive <NA> job55d366655f2487b7a32ee3100b164e08 <NA> 1
#> 500: <NA> <NA> <NA> <NA> 1
rjoin(sjoin(tab, ids), getJobStatus(ids, reg = tmp)[, c("job.id", "time.running")])
#> Key: <job.id>
#> job.id problem algorithm x y time.running
#> <int> <char> <char> <int> <char> <difftime>
#> 1: 32 iris nrow 7 b 1100.0348 secs
#> 2: 42 iris nrow 9 b 1100.0346 secs
#> 3: 47 iris nrow 10 b 1100.0338 secs
#> 4: 66 iris nrow 14 a 1100.0333 secs
#> 5: 73 iris nrow 15 c 100.0333 secs
#> 6: 75 iris nrow 15 e 100.0368 secs
#> 7: 86 iris nrow 18 a 1100.0355 secs
#> 8: 100 iris nrow 20 e 100.0352 secs
#> 9: 101 iris nrow 21 a 1100.0337 secs
#> 10: 103 iris nrow 21 c 100.0334 secs
#> 11: 123 iris nrow 25 c 100.0330 secs
#> 12: 125 iris nrow 25 e 100.0338 secs
#> 13: 161 iris nrow 33 a 1100.0356 secs
#> 14: 165 iris nrow 33 e 100.0341 secs
#> 15: 169 iris nrow 34 d 100.0330 secs
#> 16: 183 iris nrow 37 c 100.0332 secs
#> 17: 184 iris nrow 37 d 100.0368 secs
#> 18: 203 iris nrow 41 c 100.0350 secs
#> 19: 207 iris nrow 42 b 1100.0357 secs
#> 20: 209 iris nrow 42 d 100.0340 secs
#> 21: 220 iris nrow 44 e 100.0336 secs
#> 22: 227 iris nrow 46 b 1100.0332 secs
#> 23: 229 iris nrow 46 d 100.0339 secs
#> 24: 231 iris nrow 47 a 1100.0354 secs
#> 25: 244 iris nrow 49 d 100.0343 secs
#> 26: 260 iris ncol 2 e 500.0331 secs
#> 27: 276 iris ncol 6 a 1500.0334 secs
#> 28: 278 iris ncol 6 c 500.0368 secs
#> 29: 279 iris ncol 6 d 500.0355 secs
#> 30: 296 iris ncol 10 a 1500.0353 secs
#> 31: 320 iris ncol 14 e 500.0333 secs
#> 32: 340 iris ncol 18 e 500.0335 secs
#> 33: 347 iris ncol 20 b 1500.0364 secs
#> 34: 363 iris ncol 23 c 500.0354 secs
#> 35: 369 iris ncol 24 d 500.0352 secs
#> 36: 373 iris ncol 25 c 500.0334 secs
#> 37: 387 iris ncol 28 b 1500.0340 secs
#> 38: 410 iris ncol 32 e 500.0385 secs
#> 39: 421 iris ncol 35 a 1500.0361 secs
#> 40: 436 iris ncol 38 a 1500.0345 secs
#> 41: 444 iris ncol 39 d 500.0332 secs
#> 42: 448 iris ncol 40 c 500.0337 secs
#> 43: 456 iris ncol 42 a 1500.0392 secs
#> 44: 459 iris ncol 42 d 500.0354 secs
#> 45: 467 iris ncol 44 b 1500.0332 secs
#> 46: 468 iris ncol 44 c 500.0335 secs
#> 47: 475 iris ncol 45 e 500.0379 secs
#> 48: 482 iris ncol 47 b 1500.0351 secs
#> 49: 492 iris ncol 49 b 1500.0366 secs
#> 50: 499 iris ncol 50 d 500.0333 secs
#> job.id problem algorithm x y time.running
# Estimate runtimes:
est = estimateRuntimes(tab, reg = tmp)
print(est)
#> Runtime Estimate for 500 jobs with 1 CPUs
#> Done : 0d 09h 43m 21.7s
#> Remaining: 3d 17h 35m 7.4s
#> Total : 4d 03h 18m 29.1s
rjoin(tab, est$runtimes)
#> Key: <job.id>
#> job.id problem algorithm x y type runtime
#> <int> <char> <char> <int> <char> <fctr> <num>
#> 1: 1 iris nrow 1 a estimated 1103.6481
#> 2: 2 iris nrow 1 b estimated 1087.4424
#> 3: 3 iris nrow 1 c estimated 336.2410
#> 4: 4 iris nrow 1 d estimated 316.6670
#> 5: 5 iris nrow 1 e estimated 315.2178
#> ---
#> 496: 496 iris ncol 50 a estimated 1385.9546
#> 497: 497 iris ncol 50 b estimated 1392.8439
#> 498: 498 iris ncol 50 c estimated 617.8169
#> 499: 499 iris ncol 50 d observed 500.0333
#> 500: 500 iris ncol 50 e estimated 577.6098
print(est, n = 10)
#> Runtime Estimate for 500 jobs with 10 CPUs
#> Done : 0d 09h 43m 21.7s
#> Remaining: 3d 17h 35m 7.4s
#> Parallel : 0d 08h 58m 14.8s
#> Total : 4d 03h 18m 29.1s
# Submit jobs with longest runtime first:
ids = est$runtimes[type == "estimated"][order(runtime, decreasing = TRUE)]
print(ids)
#> job.id type runtime
#> <int> <fctr> <num>
#> 1: 466 estimated 1424.3352
#> 2: 461 estimated 1420.9421
#> 3: 472 estimated 1416.9936
#> 4: 462 estimated 1416.8405
#> 5: 457 estimated 1416.0405
#> ---
#> 446: 194 estimated 133.4060
#> 447: 185 estimated 132.4015
#> 448: 189 estimated 131.7394
#> 449: 174 estimated 131.1215
#> 450: 179 estimated 129.9753
if (FALSE) { # \dontrun{
submitJobs(ids, reg = tmp)
} # }
# Group jobs into chunks with runtime < 1h
ids = est$runtimes[type == "estimated"]
ids[, chunk := binpack(runtime, 3600)]
#> Key: <job.id>
#> job.id type runtime chunk
#> <int> <fctr> <num> <int>
#> 1: 1 estimated 1103.6481 48
#> 2: 2 estimated 1087.4424 52
#> 3: 3 estimated 336.2410 37
#> 4: 4 estimated 316.6670 33
#> 5: 5 estimated 315.2178 70
#> ---
#> 446: 495 estimated 583.3444 15
#> 447: 496 estimated 1385.9546 19
#> 448: 497 estimated 1392.8439 13
#> 449: 498 estimated 617.8169 4
#> 450: 500 estimated 577.6098 22
print(ids)
#> Key: <job.id>
#> job.id type runtime chunk
#> <int> <fctr> <num> <int>
#> 1: 1 estimated 1103.6481 48
#> 2: 2 estimated 1087.4424 52
#> 3: 3 estimated 336.2410 37
#> 4: 4 estimated 316.6670 33
#> 5: 5 estimated 315.2178 70
#> ---
#> 446: 495 estimated 583.3444 15
#> 447: 496 estimated 1385.9546 19
#> 448: 497 estimated 1392.8439 13
#> 449: 498 estimated 617.8169 4
#> 450: 500 estimated 577.6098 22
print(ids[, list(runtime = sum(runtime)), by = chunk])
#> chunk runtime
#> <int> <num>
#> 1: 48 3486.041
#> 2: 52 3599.252
#> 3: 37 3598.471
#> 4: 33 3595.797
#> 5: 70 3489.390
#> 6: 49 3478.671
#> 7: 51 3594.443
#> 8: 71 3486.783
#> 9: 53 3598.058
#> 10: 68 3495.782
#> 11: 72 3483.524
#> 12: 54 3587.151
#> 13: 69 3494.589
#> 14: 73 3477.851
#> 15: 46 3516.988
#> 16: 50 3599.902
#> 17: 42 3572.702
#> 18: 63 3518.452
#> 19: 66 3505.528
#> 20: 43 3568.622
#> 21: 64 3515.915
#> 22: 67 3503.356
#> 23: 38 3598.313
#> 24: 60 3533.263
#> 25: 35 3599.559
#> 26: 47 3493.657
#> 27: 39 3591.530
#> 28: 55 3582.077
#> 29: 58 3547.763
#> 30: 41 3583.580
#> 31: 57 3561.601
#> 32: 36 3599.575
#> 33: 40 3587.694
#> 34: 56 3571.628
#> 35: 59 3543.274
#> 36: 44 3534.044
#> 37: 61 3524.581
#> 38: 62 3522.177
#> 39: 45 3533.094
#> 40: 34 3599.918
#> 41: 65 3511.171
#> 42: 27 3598.000
#> 43: 24 3598.219
#> 44: 28 3576.024
#> 45: 25 3599.683
#> 46: 23 3598.927
#> 47: 29 3568.857
#> 48: 75 3599.769
#> 49: 12 3565.943
#> 50: 74 3477.284
#> 51: 8 3591.486
#> 52: 21 3517.502
#> 53: 20 3523.441
#> 54: 7 3593.503
#> 55: 11 3568.155
#> 56: 5 3594.547
#> 57: 6 3599.627
#> 58: 32 3599.757
#> 59: 10 3581.631
#> 60: 80 3483.700
#> 61: 83 3597.182
#> 62: 2 3599.786
#> 63: 76 3596.628
#> 64: 79 3494.532
#> 65: 81 3471.919
#> 66: 77 3519.921
#> 67: 87 3563.475
#> 68: 90 3523.224
#> 69: 91 2292.731
#> 70: 78 3504.521
#> 71: 89 3543.274
#> 72: 4 3594.086
#> 73: 86 3572.755
#> 74: 85 3578.980
#> 75: 3 3599.995
#> 76: 88 3553.705
#> 77: 82 3599.121
#> 78: 84 3588.278
#> 79: 9 3587.548
#> 80: 30 3561.745
#> 81: 19 3573.905
#> 82: 17 3586.588
#> 83: 31 3552.439
#> 84: 13 3596.849
#> 85: 14 3599.422
#> 86: 22 3598.085
#> 87: 18 3581.075
#> 88: 26 3587.389
#> 89: 15 3599.314
#> 90: 16 3597.013
#> 91: 1 3470.053
#> chunk runtime
if (FALSE) { # \dontrun{
submitJobs(ids, reg = tmp)
} # }
# Group jobs into 10 chunks with similar runtime
ids = est$runtimes[type == "estimated"]
ids[, chunk := lpt(runtime, 10)]
#> Key: <job.id>
#> job.id type runtime chunk
#> <int> <fctr> <num> <int>
#> 1: 1 estimated 1103.6481 3
#> 2: 2 estimated 1087.4424 9
#> 3: 3 estimated 336.2410 8
#> 4: 4 estimated 316.6670 6
#> 5: 5 estimated 315.2178 2
#> ---
#> 446: 495 estimated 583.3444 1
#> 447: 496 estimated 1385.9546 10
#> 448: 497 estimated 1392.8439 9
#> 449: 498 estimated 617.8169 5
#> 450: 500 estimated 577.6098 1
print(ids[, list(runtime = sum(runtime)), by = chunk])
#> chunk runtime
#> <int> <num>
#> 1: 3 32294.71
#> 2: 9 32214.29
#> 3: 8 32212.39
#> 4: 6 32218.41
#> 5: 2 32277.32
#> 6: 5 32212.50
#> 7: 4 32212.12
#> 8: 10 32276.53
#> 9: 1 32294.28
#> 10: 7 32294.81