Skip to content

Commit 49501c6

Browse files
mb706jakob-r
authored andcommitted
Return the optimization state to the user on successful finish. (#362)
* Return the optimization state to the user on successful finish. Give the user the option to continue a finished optimization run. This enables the user to handle the saving of backup states himself. * Apparently roxygenise doesnt happen automatically during build. * name save.state, final opt.state
1 parent e747989 commit 49501c6

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

R/MBOResult.R

+2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ makeMBOResult.OptState = function(opt.state) {
4949
resample.results = getOptResultResampleResults(opt.result),
5050
final.state = getOptStateState(opt.state),
5151
models = getOptResultStoredModels(opt.result),
52+
final.opt.state = opt.state,
5253
control = control
5354
)
5455
} else {
@@ -59,6 +60,7 @@ makeMBOResult.OptState = function(opt.state) {
5960
opt.path = getOptStateOptPath(opt.state),
6061
final.state = getOptStateState(opt.state),
6162
models = getOptResultStoredModels(opt.result),
63+
final.opt.state = opt.state,
6264
control = control
6365
)
6466
}

R/mboContinue.R

+9-5
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@
44
#' Useful if your optimization is likely to crash,
55
#' so you can continue from a save point and will not lose too much information and runtime.
66
#'
7-
#' @param file [\code{character(1)}]\cr
8-
#' File path of saved MBO state.
7+
#' @param opt.state [\code{OptState} | \code{character(1)}]\cr
8+
#' Either the \code{save.state} slot of an \code{MBOResult} object, or a file path of a saved MBO state.
99
#' See \code{save.on.disk.at} argument of \code{\link{MBOControl}} object.
1010
#' @return See \code{\link{mbo}}.
1111
#' @export
12-
mboContinue = function(file) {
13-
assertCharacter(file, len = 1L)
14-
opt.state = loadOptState(file)
12+
mboContinue = function(opt.state) {
13+
if (checkCharacter(opt.state, len = 1L)) {
14+
opt.state = loadOptState(opt.state)
15+
}
16+
if (!inherits(opt.state, "OptState")) {
17+
stop("opt.state must be either an OptState object, or a file path of a saved OptState.")
18+
}
1519
state = getOptStateState(opt.state)
1620
if (state %nin% c("init", "iter")) {
1721
warningf("Tuning ended with %s. No need to continue. Simply returning stored result.", state)

man/mboContinue.Rd

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)