-
-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathupdateRegisty.R
More file actions
115 lines (102 loc) · 3.69 KB
/
updateRegisty.R
File metadata and controls
115 lines (102 loc) · 3.69 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# returns TRUE if the state possibly changed
updateRegistry = function(reg = getDefaultRegistry()) { # nocov start
"!DEBUG [updateRegistry]: Running updateRegistry"
pv = packageVersion("batchtools")
if (identical(pv, reg$version))
return(FALSE)
if (is.null(reg$version) || reg$version < "0.9.0")
stop("Your registry is too old.")
if (reg$version < "0.9.1-9000") {
### hotfix for timestamps
if (is.integer(reg$status$submitted)) {
info("Converting timestamps to numeric")
for (x in c("submitted", "started", "done"))
reg$status[[x]] = as.numeric(reg$status[[x]])
}
### hotfix for log.file column
if ("log.file" %chnin% names(reg$status)) {
info("Adding column 'log.file'")
reg$status[, ("log.file") := rep(NA_character_, .N)]
}
}
if (reg$version < "0.9.1-9001") {
### hotfix for base32 encoding of exports
fns = list.files(fs::path(reg$file.dir, "exports"), pattern = "\\.rds$", all.files = TRUE, no.. = TRUE)
if (length(fns)) {
info("Renaming export files")
fs::file_move(
fs::path(reg$file.dir, fns),
fs::path(reg$file.dir, mangle(stri_sub(fns, to = -5L)))
)
}
}
if (reg$version < "0.9.1-9002" && inherits(reg, "ExperimentRegistry")) {
info("Renaming problems and algorithm files")
getProblemIds = function(reg) levels(reg$defs$problem)
getAlgorithmIds = function(reg) levels(reg$defs$algorithm)
for (prob in getProblemIds(reg))
fs::file_move(fs::path(reg$file.dir, "problems", sprintf("%s.rds", digest(prob))), getProblemURI(reg, prob))
for (algo in getAlgorithmIds(reg))
fs::file_move(fs::path(reg$file.dir, "algorithms", sprintf("%s.rds", digest(algo))), getAlgorithmURI(reg, algo))
}
if (reg$version < "0.9.4-9001") {
if ("job.name" %chnin% names(reg$status)) {
info("Adding column 'job.name'")
reg$status[, ("job.name") := rep(NA_character_, .N)]
}
}
if (reg$version < "0.9.6-9001") {
info("Updating registry internals")
if (!inherits(reg, "ExperimentRegistry")) {
setnames(reg$defs, "pars", "job.pars")
} else {
alloc.col(reg$defs, ncol(reg$defs) + 1L)
reg$problems = levels(reg$defs$problem)
reg$algorithms = levels(reg$defs$algorithm)
reg$defs$problem = as.character(reg$defs$problem)
reg$defs$algorithm = as.character(reg$defs$algorithm)
reg$defs$prob.pars = lapply(reg$defs$pars, `[[`, "prob.pars")
reg$defs$algo.pars = lapply(reg$defs$pars, `[[`, "algo.pars")
reg$defs$pars = NULL
info("Recalculating job hashes")
reg$defs$pars.hash = calculateHash(reg$defs)
}
}
if (reg$version < "0.9.7-9001") {
if (inherits(reg, "ExperimentRegistry")) {
info("Updating problems")
for (id in reg$problems) {
uri = getProblemURI(reg, id)
p = readRDS(uri)
p$cache = FALSE
writeRDS(p, file = uri, compress = TRUE, wait = 0)
}
}
}
if (reg$version < "0.9.7-9002") {
if (hasName(reg$status, "memory")) {
info("Renaming memory column in data base")
setnames(reg$status, "memory", "mem.used")
}
fns = list.files(dir(reg, "updates"), pattern = "\\.rds$", full.names = TRUE)
if (length(fns) > 0L) {
info("Renaming memory column in update files")
updates = lapply(fns, function(fn) {
x = try(readRDS(fn), silent = TRUE)
if (is.error(x)) {
fs::file_delete(x)
} else {
if (hasName(x, "memory")) {
setnames(x, "memory", "mem.used")
writeRDS(x, file = fn, compress = TRUE, wait = 0)
}
}
})
}
}
if (is.null(reg$compress)) {
reg$compress = "gzip"
}
reg$version = pv
return(TRUE)
} # nocov end