Skip to content

Commit

Permalink
refactor: add deprecated message to instances
Browse files Browse the repository at this point in the history
  • Loading branch information
be-marc committed May 28, 2024
1 parent 094641d commit 6aa94b8
Show file tree
Hide file tree
Showing 7 changed files with 288 additions and 1 deletion.
4 changes: 3 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: bbotk
Title: Black-Box Optimization Toolkit
Version: 0.8.0.9000
Authors@R:c(
Authors@R: c(
person("Marc", "Becker", , "[email protected]", role = c("cre", "aut"),
comment = c(ORCID = "0000-0002-8115-0400")),
person("Jakob", "Richter", , "[email protected]", role = "aut",
Expand Down Expand Up @@ -77,6 +77,8 @@ Collate:
'OptimInstanceBatch.R'
'OptimInstanceBatchMultiCrit.R'
'OptimInstanceBatchSingleCrit.R'
'OptimInstanceMultiCrit.R'
'OptimInstanceSingleCrit.R'
'mlr_optimizers.R'
'Optimizer.R'
'OptimizerAsync.R'
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export(OptimInstanceAsyncSingleCrit)
export(OptimInstanceBatch)
export(OptimInstanceBatchMultiCrit)
export(OptimInstanceBatchSingleCrit)
export(OptimInstanceMultiCrit)
export(OptimInstanceSingleCrit)
export(Optimizer)
export(OptimizerAsync)
export(OptimizerAsyncDesignPoints)
Expand Down
39 changes: 39 additions & 0 deletions R/OptimInstanceMultiCrit.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#' @title Multi Criteria Optimization Instance for Batch Optimization
#'
#' @description
#' `OptimInstanceMultiCrit` is a deprecated class that is now a wrapper around [OptimInstanceBatchMultiCrit].
#'
#' @template param_objective
#' @template param_search_space
#' @template param_terminator
#' @template param_check_values
#' @template param_callbacks
#' @template param_keep_evals
#'
#' @export
OptimInstanceMultiCrit = R6Class("OptimInstanceMultiCrit",
inherit = OptimInstanceBatchMultiCrit,
public = list(

#' @description
#' Creates a new instance of this [R6][R6::R6Class] class.
initialize = function(
objective,
search_space = NULL,
terminator,
keep_evals = "all",
check_values = TRUE,
callbacks = NULL
) {

message("OptimInstanceMultiCrit is deprecated. Use OptimInstanceBatchMultiCrit instead.")

super$initialize(
objective = objective,
search_space = search_space,
terminator = terminator,
check_values = check_values,
callbacks = callbacks)
}
)
)
39 changes: 39 additions & 0 deletions R/OptimInstanceSingleCrit.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#' @title Single Criterion Optimization Instance for Batch Optimization
#'
#' @description
#' `OptimInstanceSingleCrit` is a deprecated class that is now a wrapper around `OptimInstanceBatchSingleCrit`.
#'
#' @template param_objective
#' @template param_search_space
#' @template param_terminator
#' @template param_check_values
#' @template param_callbacks
#' @template param_keep_evals
#'
#' @export
OptimInstanceSingleCrit = R6Class("OptimInstanceSingleCrit",
inherit = OptimInstanceBatchSingleCrit,
public = list(

#' @description
#' Creates a new instance of this [R6][R6::R6Class] class.
initialize = function(
objective,
search_space = NULL,
terminator,
keep_evals = "all",
check_values = TRUE,
callbacks = NULL
) {

message("OptimInstanceSingleCrit is deprecated. Use OptimInstanceBatchSingleCrit instead.")

super$initialize(
objective = objective,
search_space = search_space,
terminator = terminator,
check_values = check_values,
callbacks = callbacks)
}
)
)
92 changes: 92 additions & 0 deletions man/OptimInstanceMultiCrit.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

92 changes: 92 additions & 0 deletions man/OptimInstanceSingleCrit.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions tests/testthat/test_deprecated.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
test_that("OptimInstanceSingleCrit deprecated works", {

expect_message({instance = OptimInstanceSingleCrit$new(
objective = OBJ_2D,
search_space = PS_2D,
terminator = trm("evals", n_evals = 5L),
)}, "OptimInstanceSingleCrit is deprecated")

expect_class(instance, "OptimInstanceSingleCrit")
})

test_that("OptimInstanceMultiCrit deprecated works", {

expect_message({instance = OptimInstanceMultiCrit$new(
objective = OBJ_2D,
search_space = PS_2D,
terminator = trm("evals", n_evals = 5L),
)}, "OptimInstanceMultiCrit is deprecated")

expect_class(instance, "OptimInstanceMultiCrit")
})

0 comments on commit 6aa94b8

Please sign in to comment.