-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.R
68 lines (54 loc) · 1.93 KB
/
test.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
source("lib/function_library.R")
# Load other R source files in the lib directory.
load_all_code("lib")
# Load a bunch of required packages, installing missing ones as needed.
load_all_packages(auto_install = F)
# Set some standard settings.
conf = list(dir = ".",
data_dir = "data",
tex_dir = "tex",
verbose = T)
conf$cluster = ckTools::parallelize(allow_multinode = T, type="doSNOW")
conf$method = "method.NNLS"
# conf$outer_cv_folds = 10
conf$outer_cv_folds = 20
conf$cv_folds = 10
# If the cluster object is null it means we're setup for multicore (or nuthin).
if (is.null(conf$cluster) || is.na(conf$cluster)) {
# Use non-CV if we're running this in RStudio on a laptop.
if (T || .Platform$GUI == "RStudio") {
fn = "sl_fn"
} else {
fn = "cv_sl_fn"
}
if (T) {
# Multicore version.
conf$sl_fn = ckTools::gen_superlearner(parallel = "multicore",
outer_cv_folds = conf$outer_cv_folds)[[fn]]
} else {
# Sequential version.
conf$sl_fn = SuperLearner
}
rm(fn)
} else {
# Multinode version.
conf$sl_fn = ckTools::gen_superlearner(parallel = "snow",
cluster = conf$cluster,
outer_cv_folds = conf$outer_cv_folds)$cv_sl_fn
}
#test_fn = function() {
lib_obj = create_SL_lib(glmnet = T, glmnet_size = 5, xgb = "small")
names(lib_obj$sl_env)
snow::clusterExport(conf$cluster, "lib_obj")#, environment())
snow::clusterExport(conf$cluster, ls(lib_obj$sl_env), lib_obj$sl_env)#, environment())
# List the sl_env
snow::clusterEvalQ(conf$cluster, "ls(lib_obj$sl_env)")
# Now attach the sl_env environment in each worker.
snow::clusterEvalQ(conf$cluster, "attach(lib_obj$sl_env)")
snow::clusterEvalQ(conf$cluster, "ls()")
combined_ls = foreach(i = 1:foreach::getDoParWorkers()) %dopar% {
ls()
}
print(combined_ls)
# Close out the cluster.
stop_cluster(conf$cluster)