Skip to content

Commit

Permalink
fix: check version before passing extra results (#259)
Browse files Browse the repository at this point in the history
  • Loading branch information
be-marc authored Oct 25, 2024
1 parent 7cc177a commit df42632
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion R/OptimInstanceAsyncMultiCrit.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ OptimInstanceAsyncMultiCrit = R6Class("OptimInstanceAsyncMultiCrit",
#' Additional information.
#' @param ... (`any`)\cr
#' ignored.
assign_result = function(xdt, ydt, extra, ...) {
assign_result = function(xdt, ydt, extra = NULL, ...) {
# FIXME: We could have one way that just lets us put a 1xn DT as result directly.
assert_data_table(xdt)
assert_names(names(xdt), must.include = self$search_space$ids())
Expand Down
2 changes: 1 addition & 1 deletion R/OptimInstanceAsyncSingleCrit.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ OptimInstanceAsyncSingleCrit = R6Class("OptimInstanceAsyncSingleCrit",
#' Additional information.
#' @param ... (`any`)\cr
#' ignored.
assign_result = function(xdt, y, extra, ...) {
assign_result = function(xdt, y, extra = NULL, ...) {
# FIXME: We could have one way that just lets us put a 1xn DT as result directly.
assert_data_table(xdt)
assert_names(names(xdt), must.include = self$search_space$ids())
Expand Down
14 changes: 11 additions & 3 deletions R/Optimizer.R
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,20 @@ assign_result_default = function(inst) {

if (inherits(inst, "OptimInstanceBatchMultiCrit") || inherits(inst, "OptimInstanceAsyncMultiCrit")) {
ydt = xydt[, inst$archive$cols_y, with = FALSE]
# upstream packages might extract extra columns from xydt
inst$assign_result(xdt, ydt, xydt = xydt, extra = extra)
# workaround until extra is implemented in upstream packages
if ("extra" %in% formalArgs(inst$assign_result)) {
inst$assign_result(xdt, ydt, extra = extra)
} else {
inst$assign_result(xdt, ydt, xydt = xydt)
}
} else {
# unlist keeps name!
y = unlist(xydt[, inst$archive$cols_y, with = FALSE])
inst$assign_result(xdt, y, xydt = xydt, extra = extra)
if ("extra" %in% formalArgs(inst$assign_result)) {
inst$assign_result(xdt, y, extra = extra)
} else {
inst$assign_result(xdt, y, xydt = xydt)
}
}

invisible(NULL)
Expand Down
6 changes: 5 additions & 1 deletion R/OptimizerBatchIrace.R
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,11 @@ OptimizerBatchIrace = R6Class("OptimizerBatchIrace",
y = set_names(mean(unlist(res[, cols_y, with = FALSE])), cols_y)
extra = res[, !c(cols_x, cols_y), with = FALSE]

inst$assign_result(xdt, y, extra = extra)
if ("extra" %in% formalArgs(inst$assign_result)) {
inst$assign_result(xdt, y, extra = extra)
} else {
inst$assign_result(xdt, y)
}
},

.result_id = NULL
Expand Down

0 comments on commit df42632

Please sign in to comment.