Skip to content

Commit

Permalink
Merge branch 'main' into irace
Browse files Browse the repository at this point in the history
  • Loading branch information
be-marc committed Nov 27, 2024
2 parents 985caee + d756e6e commit f7d89a1
Show file tree
Hide file tree
Showing 76 changed files with 2,455 additions and 713 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ jobs:

- uses: r-lib/actions/setup-r@v2

- uses: supercharge/redis-github-action@1.7.0
with:
redis-version: 7

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::pkgdown, local::.
Expand Down
14 changes: 6 additions & 8 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: bbotk
Title: Black-Box Optimization Toolkit
Version: 1.0.1.9000
Version: 1.4.0.9000
Authors@R: c(
person("Marc", "Becker", , "marcbecker@posteo.de", role = c("cre", "aut"),
comment = c(ORCID = "0000-0002-8115-0400")),
Expand Down Expand Up @@ -36,19 +36,14 @@ Suggests:
adagio,
emoa,
GenSA,
irace (>= 3.9.0.9000),
irace (>= 4.0.0),
knitr,
nloptr,
progressr,
processx,
redux,
rmarkdown,
testthat (>= 3.0.0),
rush
Remotes:
MLopez-Ibanez/irace
VignetteBuilder:
knitr
rush (>= 0.1.2)
Config/testthat/edition: 3
Config/testthat/parallel: false
Encoding: UTF-8
Expand Down Expand Up @@ -85,12 +80,14 @@ Collate:
'OptimizerAsyncGridSearch.R'
'OptimizerAsyncRandomSearch.R'
'OptimizerBatch.R'
'OptimizerBatchChain.R'
'OptimizerBatchCmaes.R'
'OptimizerBatchDesignPoints.R'
'OptimizerBatchFocusSearch.R'
'OptimizerBatchGenSA.R'
'OptimizerBatchGridSearch.R'
'OptimizerBatchIrace.R'
'OptimizerBatchLocalSearch.R'
'OptimizerBatchNLoptr.R'
'OptimizerBatchRandomSearch.R'
'Progressor.R'
Expand All @@ -104,6 +101,7 @@ Collate:
'TerminatorRunTime.R'
'TerminatorStagnation.R'
'TerminatorStagnationBatch.R'
'TerminatorStagnationHypervolume.R'
'as_terminator.R'
'assertions.R'
'bb_optimize.R'
Expand Down
5 changes: 4 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ export(OptimizerAsyncDesignPoints)
export(OptimizerAsyncGridSearch)
export(OptimizerAsyncRandomSearch)
export(OptimizerBatch)
export(OptimizerBatchChain)
export(OptimizerBatchCmaes)
export(OptimizerBatchDesignPoints)
export(OptimizerBatchFocusSearch)
export(OptimizerBatchGenSA)
export(OptimizerBatchGridSearch)
export(OptimizerBatchIrace)
export(OptimizerBatchLocalSearch)
export(OptimizerBatchNLoptr)
export(OptimizerBatchRandomSearch)
export(Terminator)
Expand All @@ -53,6 +55,7 @@ export(TerminatorPerfReached)
export(TerminatorRunTime)
export(TerminatorStagnation)
export(TerminatorStagnationBatch)
export(TerminatorStagnationHypervolume)
export(as_terminator)
export(as_terminators)
export(assert_archive)
Expand All @@ -78,7 +81,6 @@ export(callback_async)
export(callback_batch)
export(clbk)
export(clbks)
export(evaluate_queue_default)
export(is_dominated)
export(mlr_callbacks)
export(mlr_optimizers)
Expand All @@ -105,6 +107,7 @@ importFrom(methods,formalArgs)
importFrom(mlr3misc,clbk)
importFrom(mlr3misc,clbks)
importFrom(mlr3misc,mlr_callbacks)
importFrom(stats,setNames)
importFrom(utils,bibentry)
importFrom(utils,capture.output)
importFrom(utils,head)
Expand Down
30 changes: 29 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,34 @@
# bbotk (development version)

compatibility: Work with new irace 4.0.0
* compatibility: irace 4.0.0

# bbotk 1.4.0

* feat: Add `OptimizerBatchChain` that runs multiple optimizers sequentially.
* refactor: Only pass `extra` to `$assign_result()`.

# bbotk 1.3.0

* feat: Add new stage `on_result_begin` to `CallbackAsyncTuning` and `CallbackBatchTuning`.
* refactor: Rename stage `on_result` to `on_result_end` in `CallbackAsyncTuning` and `CallbackBatchTuning`.
* docs: Extend the `CallbackAsyncTuning` and `CallbackBatchTuning` documentation.

# bbotk 1.2.0

* feat: `ContextBatch` and `ContextAsync` have a `result_extra` field now to access additional results passed to the instance.
* refactor: Additional information are passed with `extra` to `OptimInstance$assign_result()`.

# bbotk 1.1.1

* feat: The optimizers passes additional information to `OptimInstance$assign_result()` method.

# bbotk 1.1.0

* docs: Move vignette to mlr3book.
* feat: Add hypervolume stagnation terminator `trm("stagnation_hypervolume")`.
* feat Add local search optimizer `opt("local_search")`.
* refactor: Remove unused fields from callbacks.
* fix: Add `"on_optimization_end_batch"` stage to `CallbackBatch`.

# bbotk 1.0.1

Expand Down
129 changes: 96 additions & 33 deletions R/CallbackAsync.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,39 @@ CallbackAsync = R6Class("CallbackAsync",
public = list(

#' @field on_optimization_begin (`function()`)\cr
#' Stage called at the beginning of the optimization in the main process.
#' Called in `Optimizer$optimize()`.
#' Stage called at the beginning of the optimization in the main process.
#' Called in `Optimizer$optimize()`.
on_optimization_begin = NULL,

#' @field on_worker_begin (`function()`)\cr
#' Stage called at the beginning of the optimization on the worker.
#' Called in the worker loop.
#' Stage called at the beginning of the optimization on the worker.
#' Called in the worker loop.
on_worker_begin = NULL,

#' @field on_optimizer_before_eval (`function()`)\cr
#' Stage called after the optimizer proposes points.
#' Called in `OptimInstance$.eval_point()`.
on_optimizer_before_eval = NULL,

#' @field on_optimizer_after_eval (`function()`)\cr
#' Stage called after points are evaluated.
#' Called in `OptimInstance$.eval_point()`.
on_optimizer_after_eval = NULL,

#' @field on_worker_end (`function()`)\cr
#' Stage called at the end of the optimization on the worker.
#' Called in the worker loop.
#' Stage called at the end of the optimization on the worker.
#' Called in the worker loop.
on_worker_end = NULL,

#' @field on_result (`function()`)\cr
#' Stage called after result are written.
#' @field on_result_begin (`function()`)\cr
#' Stage called before the results are written.
#' Called in `OptimInstance$assign_result()`.
on_result_begin = NULL,

#' @field on_result_end (`function()`)\cr
#' Stage called after the results are written.
#' Called in `OptimInstance$assign_result()`.
on_result = NULL,
on_result_end = NULL,

#' @field on_optimization_end (`function()`)\cr
#' Stage called at the end of the optimization in the main process.
Expand All @@ -52,9 +67,14 @@ CallbackAsync = R6Class("CallbackAsync",
#' - on_optimization_begin
#' Start Worker
#' - on_worker_begin
#' Start Optimization on Worker
#' - on_optimizer_before_eval
#' - on_optimizer_after_eval
#' End Optimization on Worker
#' - on_worker_end
#' End Worker
#' - on_result
#' - on_result_begin
#' - on_result_end
#' - on_optimization_end
#' End Optimization
#' ```
Expand All @@ -67,32 +87,56 @@ CallbackAsync = R6Class("CallbackAsync",
#' The [ContextAsync] allows to modify the instance, archive, optimizer and final result.
#'
#' @param id (`character(1)`)\cr
#' Identifier for the new instance.
#' Identifier for the new instance.
#' @param label (`character(1)`)\cr
#' Label for the new instance.
#' Label for the new instance.
#' @param man (`character(1)`)\cr
#' String in the format `[pkg]::[topic]` pointing to a manual page for this object.
#' The referenced help package can be opened via method `$help()`.
#' String in the format `[pkg]::[topic]` pointing to a manual page for this object.
#' The referenced help package can be opened via method `$help()`.
#'
#' @param on_optimization_begin (`function()`)\cr
#' Stage called at the beginning of the optimization in the main process.
#' Called in `Optimizer$optimize()`.
#' The functions must have two arguments named `callback` and `context`.
#' Stage called at the beginning of the optimization in the main process.
#' Called in `Optimizer$optimize()`.
#' The functions must have two arguments named `callback` and `context`.
#' @param on_worker_begin (`function()`)\cr
#' Stage called at the beginning of the optimization on the worker.
#' Called in the worker loop.
#' The functions must have two arguments named `callback` and `context`.
#' Stage called at the beginning of the optimization on the worker.
#' Called in the worker loop.
#' The functions must have two arguments named `callback` and `context`.
#' @param on_optimizer_before_eval (`function()`)\cr
#' Stage called after the optimizer proposes points.
#' Called in `OptimInstance$.eval_point()`.
#' The functions must have two arguments named `callback` and `context`.
#' The argument of `instance$.eval_point(xs)` and `xs_trafoed` and `extra` are available in the `context`.
#' Or `xs` and `xs_trafoed` of `instance$.eval_queue()` are available in the `context`.
#' @param on_optimizer_after_eval (`function()`)\cr
#' Stage called after points are evaluated.
#' Called in `OptimInstance$.eval_point()`.
#' The functions must have two arguments named `callback` and `context`.
#' The outcome `y` is available in the `context`.
#' @param on_worker_end (`function()`)\cr
#' Stage called at the end of the optimization on the worker.
#' Called in the worker loop.
#' The functions must have two arguments named `callback` and `context`.
#' Stage called at the end of the optimization on the worker.
#' Called in the worker loop.
#' The functions must have two arguments named `callback` and `context`.
#' @param on_result_begin (`function()`)\cr
#' Stage called before result are written.
#' Called in `OptimInstance$assign_result()`.
#' The functions must have two arguments named `callback` and `context`.
#' The arguments of `$.assign_result(xdt, y, extra)` are available in the `context`.
#' @param on_result_end (`function()`)\cr
#' Stage called after result are written.
#' Called in `OptimInstance$assign_result()`.
#' The functions must have two arguments named `callback` and `context`.
#' The final result `instance$result` is available in the `context`.
#' @param on_result (`function()`)\cr
#' Stage called after result are written.
#' Called in `OptimInstance$assign_result()`.
#' The functions must have two arguments named `callback` and `context`.
#' Deprecated.
#' Use `on_result_end` instead.
#' Stage called after result are written.
#' Called in `OptimInstance$assign_result()`.
#' The functions must have two arguments named `callback` and `context`.
#' @param on_optimization_end (`function()`)\cr
#' Stage called at the end of the optimization in the main process.
#' Called in `Optimizer$optimize()`.
#' The functions must have two arguments named `callback` and `context`.
#' Stage called at the end of the optimization in the main process.
#' Called in `Optimizer$optimize()`.
#' The functions must have two arguments named `callback` and `context`.
#'
#' @export
callback_async = function(
Expand All @@ -101,21 +145,40 @@ callback_async = function(
man = NA_character_,
on_optimization_begin = NULL,
on_worker_begin = NULL,
on_optimizer_before_eval = NULL,
on_optimizer_after_eval = NULL,
on_worker_end = NULL,
on_result_begin = NULL,
on_result_end = NULL,
on_result = NULL,
on_optimization_end = NULL
) {
stages = discard(set_names(list(
on_optimization_begin,
on_worker_begin,
on_optimizer_before_eval,
on_optimizer_after_eval,
on_worker_end,
on_result_begin,
on_result_end,
on_result,
on_optimization_end),
c("on_optimization_begin",
"on_worker_begin",
"on_worker_end",
"on_result",
"on_optimization_end")), is.null)
"on_worker_begin",
"on_optimizer_before_eval",
"on_optimizer_after_eval",
"on_worker_end",
"on_result_begin",
"on_result_end",
"on_result",
"on_optimization_end")), is.null)

if ("on_result" %in% names(stages)) {
.Deprecated(old = "on_result", new = "on_result_end")
stages$on_result_end = stages$on_result
stages$on_result = NULL
}

walk(stages, function(stage) assert_function(stage, args = c("callback", "context")))
callback = CallbackAsync$new(id, label, man)
iwalk(stages, function(stage, name) callback[[name]] = stage)
Expand Down
Loading

0 comments on commit f7d89a1

Please sign in to comment.