From 6aa94b810d4c8c9cd9b054600fc76efb8795c324 Mon Sep 17 00:00:00 2001 From: be-marc Date: Tue, 28 May 2024 13:25:36 +0200 Subject: [PATCH] refactor: add deprecated message to instances --- DESCRIPTION | 4 +- NAMESPACE | 2 + R/OptimInstanceMultiCrit.R | 39 ++++++++++++++ R/OptimInstanceSingleCrit.R | 39 ++++++++++++++ man/OptimInstanceMultiCrit.Rd | 92 ++++++++++++++++++++++++++++++++ man/OptimInstanceSingleCrit.Rd | 92 ++++++++++++++++++++++++++++++++ tests/testthat/test_deprecated.R | 21 ++++++++ 7 files changed, 288 insertions(+), 1 deletion(-) create mode 100644 R/OptimInstanceMultiCrit.R create mode 100644 R/OptimInstanceSingleCrit.R create mode 100644 man/OptimInstanceMultiCrit.Rd create mode 100644 man/OptimInstanceSingleCrit.Rd create mode 100644 tests/testthat/test_deprecated.R diff --git a/DESCRIPTION b/DESCRIPTION index 85c18e5e..35e9b381 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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", , "marcbecker@posteo.de", role = c("cre", "aut"), comment = c(ORCID = "0000-0002-8115-0400")), person("Jakob", "Richter", , "jakob1richter@gmail.com", role = "aut", @@ -77,6 +77,8 @@ Collate: 'OptimInstanceBatch.R' 'OptimInstanceBatchMultiCrit.R' 'OptimInstanceBatchSingleCrit.R' + 'OptimInstanceMultiCrit.R' + 'OptimInstanceSingleCrit.R' 'mlr_optimizers.R' 'Optimizer.R' 'OptimizerAsync.R' diff --git a/NAMESPACE b/NAMESPACE index 6ef7131d..690d19ad 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -28,6 +28,8 @@ export(OptimInstanceAsyncSingleCrit) export(OptimInstanceBatch) export(OptimInstanceBatchMultiCrit) export(OptimInstanceBatchSingleCrit) +export(OptimInstanceMultiCrit) +export(OptimInstanceSingleCrit) export(Optimizer) export(OptimizerAsync) export(OptimizerAsyncDesignPoints) diff --git a/R/OptimInstanceMultiCrit.R b/R/OptimInstanceMultiCrit.R new file mode 100644 index 00000000..fe3ada25 --- /dev/null +++ b/R/OptimInstanceMultiCrit.R @@ -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) + } + ) +) diff --git a/R/OptimInstanceSingleCrit.R b/R/OptimInstanceSingleCrit.R new file mode 100644 index 00000000..4eb15418 --- /dev/null +++ b/R/OptimInstanceSingleCrit.R @@ -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) + } + ) +) diff --git a/man/OptimInstanceMultiCrit.Rd b/man/OptimInstanceMultiCrit.Rd new file mode 100644 index 00000000..0304c80f --- /dev/null +++ b/man/OptimInstanceMultiCrit.Rd @@ -0,0 +1,92 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/OptimInstanceMultiCrit.R +\name{OptimInstanceMultiCrit} +\alias{OptimInstanceMultiCrit} +\title{Multi Criteria Optimization Instance for Batch Optimization} +\description{ +\code{OptimInstanceMultiCrit} is a deprecated class that is now a wrapper around \link{OptimInstanceBatchMultiCrit}. +} +\section{Super classes}{ +\code{\link[bbotk:OptimInstance]{bbotk::OptimInstance}} -> \code{\link[bbotk:OptimInstanceBatch]{bbotk::OptimInstanceBatch}} -> \code{\link[bbotk:OptimInstanceBatchMultiCrit]{bbotk::OptimInstanceBatchMultiCrit}} -> \code{OptimInstanceMultiCrit} +} +\section{Methods}{ +\subsection{Public methods}{ +\itemize{ +\item \href{#method-OptimInstanceMultiCrit-new}{\code{OptimInstanceMultiCrit$new()}} +\item \href{#method-OptimInstanceMultiCrit-clone}{\code{OptimInstanceMultiCrit$clone()}} +} +} +\if{html}{\out{ +
Inherited methods + +
+}} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-OptimInstanceMultiCrit-new}{}}} +\subsection{Method \code{new()}}{ +Creates a new instance of this \link[R6:R6Class]{R6} class. +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{OptimInstanceMultiCrit$new( + objective, + search_space = NULL, + terminator, + keep_evals = "all", + check_values = TRUE, + callbacks = NULL +)}\if{html}{\out{
}} +} + +\subsection{Arguments}{ +\if{html}{\out{
}} +\describe{ +\item{\code{objective}}{(\link{Objective})\cr +Objective function.} + +\item{\code{search_space}}{(\link[paradox:ParamSet]{paradox::ParamSet})\cr +Specifies the search space for the \link{Optimizer}. The \link[paradox:ParamSet]{paradox::ParamSet} +describes either a subset of the \code{domain} of the \link{Objective} or it describes +a set of parameters together with a \code{trafo} function that transforms values +from the search space to values of the domain. Depending on the context, this +value defaults to the domain of the objective.} + +\item{\code{terminator}}{\link{Terminator}\cr +Termination criterion.} + +\item{\code{keep_evals}}{(\code{character(1)})\cr +Keep \code{all} or only \code{best} evaluations in archive?} + +\item{\code{check_values}}{(\code{logical(1)})\cr +Should points before the evaluation and the results be checked for validity?} + +\item{\code{callbacks}}{(list of \link[mlr3misc:Callback]{mlr3misc::Callback})\cr +List of callbacks.} +} +\if{html}{\out{
}} +} +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-OptimInstanceMultiCrit-clone}{}}} +\subsection{Method \code{clone()}}{ +The objects of this class are cloneable with this method. +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{OptimInstanceMultiCrit$clone(deep = FALSE)}\if{html}{\out{
}} +} + +\subsection{Arguments}{ +\if{html}{\out{
}} +\describe{ +\item{\code{deep}}{Whether to make a deep clone.} +} +\if{html}{\out{
}} +} +} +} diff --git a/man/OptimInstanceSingleCrit.Rd b/man/OptimInstanceSingleCrit.Rd new file mode 100644 index 00000000..2dacfc33 --- /dev/null +++ b/man/OptimInstanceSingleCrit.Rd @@ -0,0 +1,92 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/OptimInstanceSingleCrit.R +\name{OptimInstanceSingleCrit} +\alias{OptimInstanceSingleCrit} +\title{Single Criterion Optimization Instance for Batch Optimization} +\description{ +\code{OptimInstanceSingleCrit} is a deprecated class that is now a wrapper around \code{OptimInstanceBatchSingleCrit}. +} +\section{Super classes}{ +\code{\link[bbotk:OptimInstance]{bbotk::OptimInstance}} -> \code{\link[bbotk:OptimInstanceBatch]{bbotk::OptimInstanceBatch}} -> \code{\link[bbotk:OptimInstanceBatchSingleCrit]{bbotk::OptimInstanceBatchSingleCrit}} -> \code{OptimInstanceSingleCrit} +} +\section{Methods}{ +\subsection{Public methods}{ +\itemize{ +\item \href{#method-OptimInstanceSingleCrit-new}{\code{OptimInstanceSingleCrit$new()}} +\item \href{#method-OptimInstanceSingleCrit-clone}{\code{OptimInstanceSingleCrit$clone()}} +} +} +\if{html}{\out{ +
Inherited methods + +
+}} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-OptimInstanceSingleCrit-new}{}}} +\subsection{Method \code{new()}}{ +Creates a new instance of this \link[R6:R6Class]{R6} class. +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{OptimInstanceSingleCrit$new( + objective, + search_space = NULL, + terminator, + keep_evals = "all", + check_values = TRUE, + callbacks = NULL +)}\if{html}{\out{
}} +} + +\subsection{Arguments}{ +\if{html}{\out{
}} +\describe{ +\item{\code{objective}}{(\link{Objective})\cr +Objective function.} + +\item{\code{search_space}}{(\link[paradox:ParamSet]{paradox::ParamSet})\cr +Specifies the search space for the \link{Optimizer}. The \link[paradox:ParamSet]{paradox::ParamSet} +describes either a subset of the \code{domain} of the \link{Objective} or it describes +a set of parameters together with a \code{trafo} function that transforms values +from the search space to values of the domain. Depending on the context, this +value defaults to the domain of the objective.} + +\item{\code{terminator}}{\link{Terminator}\cr +Termination criterion.} + +\item{\code{keep_evals}}{(\code{character(1)})\cr +Keep \code{all} or only \code{best} evaluations in archive?} + +\item{\code{check_values}}{(\code{logical(1)})\cr +Should points before the evaluation and the results be checked for validity?} + +\item{\code{callbacks}}{(list of \link[mlr3misc:Callback]{mlr3misc::Callback})\cr +List of callbacks.} +} +\if{html}{\out{
}} +} +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-OptimInstanceSingleCrit-clone}{}}} +\subsection{Method \code{clone()}}{ +The objects of this class are cloneable with this method. +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{OptimInstanceSingleCrit$clone(deep = FALSE)}\if{html}{\out{
}} +} + +\subsection{Arguments}{ +\if{html}{\out{
}} +\describe{ +\item{\code{deep}}{Whether to make a deep clone.} +} +\if{html}{\out{
}} +} +} +} diff --git a/tests/testthat/test_deprecated.R b/tests/testthat/test_deprecated.R new file mode 100644 index 00000000..f2981b09 --- /dev/null +++ b/tests/testthat/test_deprecated.R @@ -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") +})