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.

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 in tab except “job.id” will be passed to ranger as independent variables to fit the model.

...

[ANY]
Additional parameters passed to ranger. Ignored for the print method.

reg

[Registry]
Registry. If not explicitly passed, uses the default registry (see setDefaultRegistry).

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.

See also

binpack and lpt to chunk jobs according to their estimated runtimes.

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 1760453475 1760453475 1760453975   <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> jobd3307f1c7044bae0d9b5eaaa4cb90db8     <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.0533 secs
#>  2:     42    iris      nrow     9      b 1100.0317 secs
#>  3:     47    iris      nrow    10      b 1100.0353 secs
#>  4:     66    iris      nrow    14      a 1100.0412 secs
#>  5:     73    iris      nrow    15      c  100.0343 secs
#>  6:     75    iris      nrow    15      e  100.0535 secs
#>  7:     86    iris      nrow    18      a 1100.0426 secs
#>  8:    100    iris      nrow    20      e  100.0373 secs
#>  9:    101    iris      nrow    21      a 1100.0332 secs
#> 10:    103    iris      nrow    21      c  100.0301 secs
#> 11:    123    iris      nrow    25      c  100.0434 secs
#> 12:    125    iris      nrow    25      e  100.0345 secs
#> 13:    161    iris      nrow    33      a 1100.0400 secs
#> 14:    165    iris      nrow    33      e  100.0383 secs
#> 15:    169    iris      nrow    34      d  100.0433 secs
#> 16:    183    iris      nrow    37      c  100.0352 secs
#> 17:    184    iris      nrow    37      d  100.0346 secs
#> 18:    203    iris      nrow    41      c  100.0341 secs
#> 19:    207    iris      nrow    42      b 1100.0466 secs
#> 20:    209    iris      nrow    42      d  100.0372 secs
#> 21:    220    iris      nrow    44      e  100.0535 secs
#> 22:    227    iris      nrow    46      b 1100.0371 secs
#> 23:    229    iris      nrow    46      d  100.0347 secs
#> 24:    231    iris      nrow    47      a 1100.0365 secs
#> 25:    244    iris      nrow    49      d  100.0466 secs
#> 26:    260    iris      ncol     2      e  500.0564 secs
#> 27:    276    iris      ncol     6      a 1500.0487 secs
#> 28:    278    iris      ncol     6      c  500.0709 secs
#> 29:    279    iris      ncol     6      d  500.0404 secs
#> 30:    296    iris      ncol    10      a 1500.0523 secs
#> 31:    320    iris      ncol    14      e  500.0431 secs
#> 32:    340    iris      ncol    18      e  500.0332 secs
#> 33:    347    iris      ncol    20      b 1500.0318 secs
#> 34:    363    iris      ncol    23      c  500.0442 secs
#> 35:    369    iris      ncol    24      d  500.0553 secs
#> 36:    373    iris      ncol    25      c  500.0509 secs
#> 37:    387    iris      ncol    28      b 1500.0392 secs
#> 38:    410    iris      ncol    32      e  500.0345 secs
#> 39:    421    iris      ncol    35      a 1500.0363 secs
#> 40:    436    iris      ncol    38      a 1500.0327 secs
#> 41:    444    iris      ncol    39      d  500.0334 secs
#> 42:    448    iris      ncol    40      c  500.0333 secs
#> 43:    456    iris      ncol    42      a 1500.0321 secs
#> 44:    459    iris      ncol    42      d  500.0435 secs
#> 45:    467    iris      ncol    44      b 1500.0350 secs
#> 46:    468    iris      ncol    44      c  500.0366 secs
#> 47:    475    iris      ncol    45      e  500.0355 secs
#> 48:    482    iris      ncol    47      b 1500.0350 secs
#> 49:    492    iris      ncol    49      b 1500.0534 secs
#> 50:    499    iris      ncol    50      d  500.0457 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 22.0s
#>   Remaining: 3d 17h 37m 49.3s
#>   Total    : 4d 03h 21m 11.4s
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 1107.2567
#>   2:      2    iris      nrow     1      b estimated 1091.2113
#>   3:      3    iris      nrow     1      c estimated  338.3696
#>   4:      4    iris      nrow     1      d estimated  318.6494
#>   5:      5    iris      nrow     1      e estimated  318.6948
#>  ---                                                          
#> 496:    496    iris      ncol    50      a estimated 1383.8348
#> 497:    497    iris      ncol    50      b estimated 1391.0858
#> 498:    498    iris      ncol    50      c estimated  619.0990
#> 499:    499    iris      ncol    50      d  observed  500.0457
#> 500:    500    iris      ncol    50      e estimated  580.0901
print(est, n = 10)
#> Runtime Estimate for 500 jobs with 10 CPUs
#>   Done     : 0d 09h 43m 22.0s
#>   Remaining: 3d 17h 37m 49.3s
#>   Parallel : 0d 08h 58m 29.1s
#>   Total    : 4d 03h 21m 11.4s

# 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 1421.1282
#>   2:    461 estimated 1419.7348
#>   3:    462 estimated 1415.9087
#>   4:    457 estimated 1415.9086
#>   5:    472 estimated 1415.0621
#>  ---                           
#> 446:    194 estimated  132.4721
#> 447:    189 estimated  131.8054
#> 448:    204 estimated  131.7223
#> 449:    174 estimated  131.1890
#> 450:    179 estimated  130.0412
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 1107.2567    47
#>   2:      2 estimated 1091.2113    51
#>   3:      3 estimated  338.3696    37
#>   4:      4 estimated  318.6494    70
#>   5:      5 estimated  318.6948    33
#>  ---                                 
#> 446:    495 estimated  587.0244    14
#> 447:    496 estimated 1383.8348    19
#> 448:    497 estimated 1391.0858    13
#> 449:    498 estimated  619.0990     4
#> 450:    500 estimated  580.0901    17
print(ids)
#> Key: <job.id>
#>      job.id      type   runtime chunk
#>       <int>    <fctr>     <num> <int>
#>   1:      1 estimated 1107.2567    47
#>   2:      2 estimated 1091.2113    51
#>   3:      3 estimated  338.3696    37
#>   4:      4 estimated  318.6494    70
#>   5:      5 estimated  318.6948    33
#>  ---                                 
#> 446:    495 estimated  587.0244    14
#> 447:    496 estimated 1383.8348    19
#> 448:    497 estimated 1391.0858    13
#> 449:    498 estimated  619.0990     4
#> 450:    500 estimated  580.0901    17
print(ids[, list(runtime = sum(runtime)), by = chunk])
#>     chunk  runtime
#>     <int>    <num>
#>  1:    47 3493.903
#>  2:    51 3595.348
#>  3:    37 3597.163
#>  4:    70 3490.491
#>  5:    33 3599.662
#>  6:    54 3589.077
#>  7:    71 3488.381
#>  8:    48 3492.394
#>  9:    52 3599.825
#> 10:    55 3580.492
#> 11:    72 3485.419
#> 12:    68 3495.168
#> 13:    56 3566.849
#> 14:    73 3478.614
#> 15:    69 3493.178
#> 16:    46 3519.658
#> 17:    50 3599.956
#> 18:    38 3598.919
#> 19:    64 3515.549
#> 20:    34 3599.756
#> 21:    39 3596.919
#> 22:    65 3512.143
#> 23:    62 3519.006
#> 24:    43 3579.570
#> 25:    61 3529.298
#> 26:    60 3533.421
#> 27:    53 3599.578
#> 28:    40 3598.912
#> 29:    58 3547.824
#> 30:    57 3560.195
#> 31:    49 3484.275
#> 32:    42 3586.102
#> 33:    59 3537.205
#> 34:    35 3599.877
#> 35:    41 3587.732
#> 36:    36 3598.976
#> 37:    44 3547.085
#> 38:    63 3517.317
#> 39:    66 3506.777
#> 40:    45 3545.898
#> 41:    67 3505.802
#> 42:    28 3593.112
#> 43:    24 3596.859
#> 44:    26 3587.720
#> 45:    25 3598.983
#> 46:    29 3567.741
#> 47:    23 3599.829
#> 48:    75 3599.847
#> 49:    20 3520.988
#> 50:    74 3472.919
#> 51:     9 3590.197
#> 52:    21 3514.818
#> 53:    12 3562.487
#> 54:     8 3594.973
#> 55:     6 3591.969
#> 56:     5 3593.786
#> 57:    10 3577.467
#> 58:    32 3599.440
#> 59:    11 3575.203
#> 60:    81 3480.912
#> 61:    83 3599.907
#> 62:    76 3593.037
#> 63:     3 3599.636
#> 64:    79 3501.757
#> 65:    80 3492.301
#> 66:    86 3580.240
#> 67:    88 3560.468
#> 68:    91 2422.115
#> 69:    82 3470.248
#> 70:    78 3511.647
#> 71:    89 3551.825
#> 72:    90 3528.456
#> 73:     2 3599.707
#> 74:    77 3526.878
#> 75:    85 3587.614
#> 76:    87 3569.977
#> 77:    84 3593.995
#> 78:     4 3599.018
#> 79:     7 3596.572
#> 80:    30 3563.571
#> 81:    18 3575.196
#> 82:    14 3596.808
#> 83:    22 3599.506
#> 84:    19 3571.153
#> 85:    17 3583.873
#> 86:    31 3550.507
#> 87:    13 3598.899
#> 88:    27 3583.829
#> 89:    15 3599.764
#> 90:    16 3597.165
#> 91:     1 3470.720
#>     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 1107.2567     3
#>   2:      2 estimated 1091.2113    10
#>   3:      3 estimated  338.3696     6
#>   4:      4 estimated  318.6494     7
#>   5:      5 estimated  318.6948     5
#>  ---                                 
#> 446:    495 estimated  587.0244     9
#> 447:    496 estimated 1383.8348     9
#> 448:    497 estimated 1391.0858     3
#> 449:    498 estimated  619.0990     2
#> 450:    500 estimated  580.0901     2
print(ids[, list(runtime = sum(runtime)), by = chunk])
#>     chunk  runtime
#>     <int>    <num>
#>  1:     3 32231.74
#>  2:    10 32308.50
#>  3:     6 32230.86
#>  4:     7 32308.83
#>  5:     5 32234.56
#>  6:     4 32230.05
#>  7:     1 32309.06
#>  8:     8 32231.39
#>  9:     2 32292.48
#> 10:     9 32291.88