Hi Max, back on my computer with windows
I've decided to make 4 tests:
- Test 1 : no parallel backend | no timeout
- Test 2 : no parallel backend | timeout
- Test 3 : parallel backend | no timeout
- Test 4 : parallel backend | timeout
# Clear workspace -------------------------------------------------------------
rm(list = ls())
# Load library ----------------------------------------------------------------
library(dplyr)
#>
#> Attachement du package : 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(caret)
#> Le chargement a nécessité le package : lattice
#> Le chargement a nécessité le package : ggplot2
#> Registered S3 methods overwritten by 'ggplot2':
#> method from
#> [.quosures rlang
#> c.quosures rlang
#> print.quosures rlang
library(R.utils)
#> Le chargement a nécessité le package : R.oo
#> Le chargement a nécessité le package : R.methodsS3
#> R.methodsS3 v1.7.1 (2016-02-15) successfully loaded. See ?R.methodsS3 for help.
#> Registered S3 method overwritten by 'R.oo':
#> method from
#> throw.default R.methodsS3
#> R.oo v1.22.0 (2018-04-21) successfully loaded. See ?R.oo for help.
#>
#> Attachement du package : 'R.oo'
#> The following objects are masked from 'package:methods':
#>
#> getClasses, getMethods
#> The following objects are masked from 'package:base':
#>
#> attach, detach, gc, load, save
#> R.utils v2.8.0 successfully loaded. See ?R.utils for help.
#>
#> Attachement du package : 'R.utils'
#> The following object is masked from 'package:utils':
#>
#> timestamp
#> The following objects are masked from 'package:base':
#>
#> cat, commandArgs, getOption, inherits, isOpen, nullfile,
#> parse, warnings
# Load data -------------------------------------------------------------------
data("AirPassengers")
data <- airquality %>% na.omit()
# Parameters ------------------------------------------------------------------
nbCore <- parallel::detectCores() - 1
# Test 1 : no parallel | no timeout
trControl <- caret::trainControl(method = "LOOCV", allowParallel = FALSE)
system.time(
model <- caret::train(Ozone ~ .,
data = data,
method = "nnet",
trControl = trControl,
trace = FALSE, tuneLength = 10)
)
#> utilisateur systÚme écoulé
#> 66.50 0.03 66.54
# Test 2 : no parallel | timeout
trControl <- caret::trainControl(method = "LOOCV", allowParallel = FALSE)
system.time(
model <- R.utils::withTimeout({
caret::train(Ozone ~ .,
data = data,
method = "nnet",
trControl = trControl,
trace = FALSE, tuneLength = 10)
}, timeout = 5)
)
#> Warning: predictions failed for Fold009: size= 1, decay=0.1000000000 Error in `[.data.frame`(object, !omit, , drop = FALSE) :
#> la limite de temps est atteinte
#> Error in pred - obs: argument non numérique pour un opérateur binaire
#> Timing stopped at: 67.64 0.03 67.74
# Test 3 : parallel | no timeout
doParallel::registerDoParallel(nbCore)
showConnections()
#> description class mode text isopen
#> 4 "output" "textConnection" "wr" "text" "opened"
#> 5 "<-DESKTOP-2BU44RT:11895" "sockconn" "a+b" "binary" "opened"
#> 6 "<-DESKTOP-2BU44RT:11895" "sockconn" "a+b" "binary" "opened"
#> 7 "<-DESKTOP-2BU44RT:11895" "sockconn" "a+b" "binary" "opened"
#> 8 "<-DESKTOP-2BU44RT:11895" "sockconn" "a+b" "binary" "opened"
#> 9 "<-DESKTOP-2BU44RT:11895" "sockconn" "a+b" "binary" "opened"
#> 10 "<-DESKTOP-2BU44RT:11895" "sockconn" "a+b" "binary" "opened"
#> 11 "<-DESKTOP-2BU44RT:11895" "sockconn" "a+b" "binary" "opened"
#> can read can write
#> 4 "no" "yes"
#> 5 "yes" "yes"
#> 6 "yes" "yes"
#> 7 "yes" "yes"
#> 8 "yes" "yes"
#> 9 "yes" "yes"
#> 10 "yes" "yes"
#> 11 "yes" "yes"
trControl <- caret::trainControl(method = "LOOCV", allowParallel = TRUE)
system.time(
model <- caret::train(Ozone ~ .,
data = data,
method = "nnet",
trControl = trControl,
trace = FALSE, tuneLength = 10)
)
#> utilisateur systÚme écoulé
#> 6.64 0.62 21.25
doParallel::stopImplicitCluster()
showConnections()
#> description class mode text isopen can read can write
#> 4 "output" "textConnection" "wr" "text" "opened" "no" "yes"
# Test 4 : parallel | timeout
doParallel::registerDoParallel(nbCore)
showConnections()
#> description class mode text isopen
#> 4 "output" "textConnection" "wr" "text" "opened"
#> 5 "<-DESKTOP-2BU44RT:11895" "sockconn" "a+b" "binary" "opened"
#> 6 "<-DESKTOP-2BU44RT:11895" "sockconn" "a+b" "binary" "opened"
#> 7 "<-DESKTOP-2BU44RT:11895" "sockconn" "a+b" "binary" "opened"
#> 8 "<-DESKTOP-2BU44RT:11895" "sockconn" "a+b" "binary" "opened"
#> 9 "<-DESKTOP-2BU44RT:11895" "sockconn" "a+b" "binary" "opened"
#> 10 "<-DESKTOP-2BU44RT:11895" "sockconn" "a+b" "binary" "opened"
#> 11 "<-DESKTOP-2BU44RT:11895" "sockconn" "a+b" "binary" "opened"
#> can read can write
#> 4 "no" "yes"
#> 5 "yes" "yes"
#> 6 "yes" "yes"
#> 7 "yes" "yes"
#> 8 "yes" "yes"
#> 9 "yes" "yes"
#> 10 "yes" "yes"
#> 11 "yes" "yes"
trControl <- caret::trainControl(method = "LOOCV", allowParallel = TRUE)
system.time(
model <- R.utils::withTimeout({
caret::train(Ozone ~ .,
data = data,
method = "nnet",
trControl = trControl,
trace = FALSE, tuneLength = 10)
}, timeout = 5)
)
#> [2019-05-17 14:42:22] TimeoutException: la limite de temps est atteinte
#> [cpu=5s, elapsed=5s]
#> Timing stopped at: 1.5 0.04 5.04
doParallel::stopImplicitCluster()
showConnections()
#> description class mode text isopen can read can write
#> 4 "output" "textConnection" "wr" "text" "opened" "no" "yes"
# Session info ----------------------------------------------------------------
sessionInfo()
#> R version 3.6.0 (2019-04-26)
#> Platform: x86_64-w64-mingw32/x64 (64-bit)
#> Running under: Windows 10 x64 (build 17763)
#>
#> Matrix products: default
#>
#> locale:
#> [1] LC_COLLATE=French_France.1252 LC_CTYPE=French_France.1252
#> [3] LC_MONETARY=French_France.1252 LC_NUMERIC=C
#> [5] LC_TIME=French_France.1252
#>
#> attached base packages:
#> [1] stats graphics grDevices utils datasets methods base
#>
#> other attached packages:
#> [1] R.utils_2.8.0 R.oo_1.22.0 R.methodsS3_1.7.1 caret_6.0-84
#> [5] ggplot2_3.1.1 lattice_0.20-38 dplyr_0.8.1
#>
#> loaded via a namespace (and not attached):
#> [1] tidyselect_0.2.5 xfun_0.7 purrr_0.3.2
#> [4] reshape2_1.4.3 splines_3.6.0 colorspace_1.4-1
#> [7] generics_0.0.2 htmltools_0.3.6 stats4_3.6.0
#> [10] yaml_2.2.0 survival_2.44-1.1 prodlim_2018.04.18
#> [13] rlang_0.3.4 ModelMetrics_1.2.2 pillar_1.4.0
#> [16] glue_1.3.1 withr_2.1.2 foreach_1.4.4
#> [19] plyr_1.8.4 lava_1.6.5 stringr_1.4.0
#> [22] timeDate_3043.102 munsell_0.5.0 gtable_0.3.0
#> [25] recipes_0.1.5 codetools_0.2-16 evaluate_0.13
#> [28] knitr_1.22 doParallel_1.0.14 parallel_3.6.0
#> [31] class_7.3-15 highr_0.8 Rcpp_1.0.1
#> [34] scales_1.0.0 ipred_0.9-9 digest_0.6.18
#> [37] stringi_1.4.3 grid_3.6.0 tools_3.6.0
#> [40] magrittr_1.5 lazyeval_0.2.2 tibble_2.1.1
#> [43] crayon_1.3.4 pkgconfig_2.0.2 MASS_7.3-51.4
#> [46] Matrix_1.2-17 data.table_1.12.2 lubridate_1.7.4
#> [49] gower_0.2.1 assertthat_0.2.1 rmarkdown_1.12
#> [52] iterators_1.0.10 R6_2.4.0 rpart_4.1-15
#> [55] nnet_7.3-12 nlme_3.1-139 compiler_3.6.0
Results:
parallel backend |
timeout (5s) |
time |
connection |
no |
no |
66s |
none |
no |
yes |
67s |
none |
yes |
no |
21s |
7 |
yes |
yes |
5s |
7 |
So only when a parallel backend has been created the timeout works.
Nota:
- I use the function
showConnections()
in order to see if the workers are correctly closed.
- Next step for me is to make
caret::train()
works properly with a timeout inside a tryCatch()