diff --git a/DESCRIPTION b/DESCRIPTION index 8dd48771..f396edea 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -27,6 +27,7 @@ Depends: R (>= 3.1.0) Imports: checkmate (>= 2.0.0), + cli, data.table, lgr, methods, diff --git a/NAMESPACE b/NAMESPACE index 7ea851ab..e2cc425b 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -98,6 +98,7 @@ export(transform_xdt_to_xss) export(trm) export(trms) import(checkmate) +import(cli) import(data.table) import(mlr3misc) import(paradox) diff --git a/R/Archive.R b/R/Archive.R index e5adf1cc..4ed8df1f 100644 --- a/R/Archive.R +++ b/R/Archive.R @@ -67,8 +67,8 @@ Archive = R6Class("Archive", #' #' @param ... (ignored). print = function() { - catf(format(self)) - print(self$data[, setdiff(names(self$data), "x_domain"), with = FALSE], digits = 2) + cli_h1(sprintf("%s %s", class(self)[1L], if (is.na(self$label)) "" else paste0("- ", self$label))) + print(as.data.table(self, unnest = "x_domain"), digits = 1) }, #' @description diff --git a/R/Objective.R b/R/Objective.R index 076a2ff9..fb590c4d 100644 --- a/R/Objective.R +++ b/R/Objective.R @@ -94,14 +94,14 @@ Objective = R6Class("Objective", #' Print method. #' @return `character()`. print = function() { - catf(self$format()) - catf("Domain:") - print(self$domain) - catf("Codomain:") - print(self$codomain) + cli_h1(class(self)[1L]) + cli_li("Domain:") + print(as.data.table(self$domain)[, c("id", "class", "lower", "upper", "nlevels"), with = FALSE]) + cli_li("Codomain:") + print(as.data.table(self$codomain)[, c("id", "class", "lower", "upper"), with = FALSE]) if (length(self$constants$values) > 0) { - catf("Constants:") - print(self$constants) + cli_li("Constants:") + print(as.data.table(self$constants)[, c("id", "class", "lower", "upper", "nlevels"), with = FALSE]) } }, diff --git a/R/OptimInstance.R b/R/OptimInstance.R index 0ff08c8d..87f7d3ec 100644 --- a/R/OptimInstance.R +++ b/R/OptimInstance.R @@ -78,22 +78,19 @@ OptimInstance = R6Class("OptimInstance", #' #' @param ... (ignored). print = function(...) { - - catf(format(self)) - catf(str_indent("* State: ", if (is.null(private$.result)) "Not optimized" else "Optimized")) - catf(str_indent("* Objective:", format(self$objective))) - if (!self$search_space$length) { - catf("* Search Space: Empty") - } else { - catf("* Search Space:") - print(as.data.table(self$search_space)[, c("id", "class", "lower", "upper", "nlevels"), with = FALSE]) - } - catf(str_indent("* Terminator:", format(self$terminator))) + cli_h1(class(self)[1L]) + cli_li(sprintf("State: %s", if (is.null(private$.result)) "Not optimized" else "Optimized")) + cli_li(sprintf("Objective: %s", class(self$objective)[1])) + cli_li("Search Space:") + print(as.data.table(self$search_space)[, c("id", "class", "lower", "upper", "nlevels"), with = FALSE]) + cli_li(sprintf("Terminator: %s %s", class(self$terminator)[1], if (length(self$terminator$param_set$values)) paste0("(", as_short_string(self$terminator$param_set$values), ")") else "")) if (!is.null(private$.result)) { - catf("* Result:") + cli_li("Result:") print(self$result[, c(self$archive$cols_x, self$archive$cols_y), with = FALSE]) - catf("* Archive:") - print(as.data.table(self$archive)[, c(self$archive$cols_x, self$archive$cols_y), with = FALSE]) + cli_li("Archive:") + tab = as.data.table(self$archive) + x_domain_ids = names(tab)[grepl("x_domain_" , names(tab))] + print(tab[, c(self$archive$cols_y, self$archive$cols_x, x_domain_ids), with = FALSE], digits = 1) } }, diff --git a/R/OptimInstanceAsync.R b/R/OptimInstanceAsync.R index 343cbcc8..c777eddc 100644 --- a/R/OptimInstanceAsync.R +++ b/R/OptimInstanceAsync.R @@ -74,7 +74,7 @@ OptimInstanceAsync = R6Class("OptimInstanceAsync", #' @param ... (ignored). print = function(...) { super$print() - catf(str_indent("* Workers:", self$rush$n_workers)) + cli_li(sprintf("Workers: %i", self$rush$n_workers)) }, #' @description diff --git a/R/Optimizer.R b/R/Optimizer.R index b81db536..0966ffa6 100644 --- a/R/Optimizer.R +++ b/R/Optimizer.R @@ -74,11 +74,11 @@ Optimizer = R6Class("Optimizer", #' #' @return (`character()`). print = function() { - catn(format(self), if (is.na(self$label)) "" else paste0(": ", self$label)) - catn(str_indent("* Parameters:", as_short_string(self$param_set$values))) - catn(str_indent("* Parameter classes:", self$param_classes)) - catn(str_indent("* Properties:", self$properties)) - catn(str_indent("* Packages:", self$packages)) + cli_h1(sprintf("%s %s", class(self)[1L], if (is.na(self$label)) "" else paste0("- ", self$label))) + cli_li(sprintf("Parameters: %s", if (length(self$param_set$values)) as_short_string(self$param_set$values) else "-")) + cli_li(sprintf("Parameter classes: %s", paste(self$param_classes, collapse = ", "))) + cli_li(sprintf("Properties: %s", paste(self$properties, collapse = ", "))) + cli_li(sprintf("Packages: %s", paste(self$packages, collapse = ", "))) }, #' @description diff --git a/R/Terminator.R b/R/Terminator.R index ce2f063c..f16101c7 100644 --- a/R/Terminator.R +++ b/R/Terminator.R @@ -74,8 +74,8 @@ Terminator = R6Class("Terminator", #' #' @param ... (ignored). print = function(...) { - catn(format(self), if (is.na(self$label)) "" else paste0(": ", self$label)) - catn(str_indent("* Parameters:", as_short_string(self$param_set$values))) + cli_h1(sprintf("%s %s", class(self)[1L], if (is.na(self$label)) "" else paste0("- ", self$label))) + cli_li(sprintf("Parameters: %s", if(length(self$param_set$values)) as_short_string(self$param_set$values) else "-")) }, #' @description diff --git a/R/TerminatorCombo.R b/R/TerminatorCombo.R index 684b7876..79b5fcfd 100644 --- a/R/TerminatorCombo.R +++ b/R/TerminatorCombo.R @@ -76,8 +76,7 @@ TerminatorCombo = R6Class("TerminatorCombo", #' @param ... (ignored). print = function(...) { super$print(...) - catf(str_indent("* Terminators:", paste(map_chr(self$terminators, format), - collapse = ","))) + cli_li(sprintf("Terminators: %s", paste(map_chr(self$terminators, format), collapse = ", "))) }, #' @description diff --git a/R/zzz.R b/R/zzz.R index fd9120ca..de3c719e 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -2,6 +2,7 @@ #' @import checkmate #' @import paradox #' @import mlr3misc +#' @import cli #' @importFrom R6 R6Class #' @importFrom utils capture.output head tail #' @importFrom methods formalArgs diff --git a/tests/testthat/_snaps/ArchiveBatch.md b/tests/testthat/_snaps/ArchiveBatch.md index 11dbdfcc..56a915f8 100644 --- a/tests/testthat/_snaps/ArchiveBatch.md +++ b/tests/testthat/_snaps/ArchiveBatch.md @@ -2,7 +2,9 @@ Code a + Message + + -- ArchiveBatch - Data Table Storage ------------------------------------------- Output - Null data.table (0 rows and 0 cols) diff --git a/tests/testthat/_snaps/Objective.md b/tests/testthat/_snaps/Objective.md index 48915577..6e50350f 100644 --- a/tests/testthat/_snaps/Objective.md +++ b/tests/testthat/_snaps/Objective.md @@ -2,35 +2,39 @@ Code obj + Message + + -- ObjectiveTestEval ----------------------------------------------------------- + * Domain: Output - - Domain: - - id class lower upper nlevels default value - - 1: x1 ParamDbl -1 1 Inf [NULL] - 2: x2 ParamDbl -1 1 Inf [NULL] - Codomain: - - id class lower upper nlevels default value - - 1: y ParamDbl -Inf Inf Inf [NULL] + id class lower upper nlevels + + 1: x1 ParamDbl -1 1 Inf + 2: x2 ParamDbl -1 1 Inf + Message + * Codomain: + Output + id class lower upper + + 1: y ParamDbl -Inf Inf --- Code obj + Message + + -- ObjectiveTestEvalMany ------------------------------------------------------- + * Domain: + Output + id class lower upper nlevels + + 1: x1 ParamDbl -1 1 Inf + 2: x2 ParamDbl -1 1 Inf + Message + * Codomain: Output - - Domain: - - id class lower upper nlevels default value - - 1: x1 ParamDbl -1 1 Inf [NULL] - 2: x2 ParamDbl -1 1 Inf [NULL] - Codomain: - - id class lower upper nlevels default value - - 1: y ParamDbl -Inf Inf Inf [NULL] + id class lower upper + + 1: y ParamDbl -Inf Inf diff --git a/tests/testthat/_snaps/OptimInstanceBatchMultiCrit.md b/tests/testthat/_snaps/OptimInstanceBatchMultiCrit.md index 68f10622..e8ba879c 100644 --- a/tests/testthat/_snaps/OptimInstanceBatchMultiCrit.md +++ b/tests/testthat/_snaps/OptimInstanceBatchMultiCrit.md @@ -2,14 +2,17 @@ Code inst - Output - - * State: Not optimized - * Objective: + Message + + -- OptimInstanceBatchMultiCrit ------------------------------------------------- + * State: Not optimized + * Objective: ObjectiveRFun * Search Space: + Output id class lower upper nlevels 1: x1 ParamDbl -1 1 Inf 2: x2 ParamDbl -1 1 Inf - * Terminator: + Message + * Terminator: TerminatorEvals (n_evals=20, k=0) diff --git a/tests/testthat/_snaps/OptimInstanceBatchSingleCrit.md b/tests/testthat/_snaps/OptimInstanceBatchSingleCrit.md index 386cacab..0d347056 100644 --- a/tests/testthat/_snaps/OptimInstanceBatchSingleCrit.md +++ b/tests/testthat/_snaps/OptimInstanceBatchSingleCrit.md @@ -2,14 +2,17 @@ Code inst - Output - - * State: Not optimized - * Objective: + Message + + -- OptimInstanceBatchSingleCrit ------------------------------------------------ + * State: Not optimized + * Objective: ObjectiveRFun * Search Space: + Output id class lower upper nlevels 1: x1 ParamDbl -1 1 Inf 2: x2 ParamDbl -1 1 Inf - * Terminator: + Message + * Terminator: TerminatorEvals (n_evals=20, k=0) diff --git a/tests/testthat/_snaps/OptimizerCmaes.md b/tests/testthat/_snaps/OptimizerCmaes.md index ee0aacb1..7e7b663c 100644 --- a/tests/testthat/_snaps/OptimizerCmaes.md +++ b/tests/testthat/_snaps/OptimizerCmaes.md @@ -2,8 +2,9 @@ Code z$optimizer - Output - : Covariance Matrix Adaptation Evolution Strategy + Message + + -- OptimizerBatchCmaes - Covariance Matrix Adaptation Evolution Strategy ------- * Parameters: start_values=random * Parameter classes: ParamDbl * Properties: single-crit diff --git a/tests/testthat/_snaps/OptimizerDesignPoints.md b/tests/testthat/_snaps/OptimizerDesignPoints.md index f8fc902a..475a8e8c 100644 --- a/tests/testthat/_snaps/OptimizerDesignPoints.md +++ b/tests/testthat/_snaps/OptimizerDesignPoints.md @@ -2,8 +2,9 @@ Code z$optimizer - Output - : Design Points + Message + + -- OptimizerBatchDesignPoints - Design Points ---------------------------------- * Parameters: batch_size=1, design= * Parameter classes: ParamLgl, ParamInt, ParamDbl, ParamFct, ParamUty * Properties: dependencies, single-crit, multi-crit @@ -13,8 +14,9 @@ Code z$optimizer - Output - : Design Points + Message + + -- OptimizerBatchDesignPoints - Design Points ---------------------------------- * Parameters: batch_size=1, design= * Parameter classes: ParamLgl, ParamInt, ParamDbl, ParamFct, ParamUty * Properties: dependencies, single-crit, multi-crit diff --git a/tests/testthat/_snaps/OptimizerFocusSearch.md b/tests/testthat/_snaps/OptimizerFocusSearch.md index 4129de14..22203aa4 100644 --- a/tests/testthat/_snaps/OptimizerFocusSearch.md +++ b/tests/testthat/_snaps/OptimizerFocusSearch.md @@ -2,8 +2,9 @@ Code z$optimizer - Output - : Focus Search + Message + + -- OptimizerBatchFocusSearch - Focus Search ------------------------------------ * Parameters: n_points=1, maxit=10 * Parameter classes: ParamLgl, ParamInt, ParamDbl, ParamFct * Properties: dependencies, single-crit @@ -13,8 +14,9 @@ Code z$optimizer - Output - : Focus Search + Message + + -- OptimizerBatchFocusSearch - Focus Search ------------------------------------ * Parameters: n_points=10, maxit=10 * Parameter classes: ParamLgl, ParamInt, ParamDbl, ParamFct * Properties: dependencies, single-crit diff --git a/tests/testthat/_snaps/OptimizerGenSA.md b/tests/testthat/_snaps/OptimizerGenSA.md index 56f9d450..bda76f13 100644 --- a/tests/testthat/_snaps/OptimizerGenSA.md +++ b/tests/testthat/_snaps/OptimizerGenSA.md @@ -2,9 +2,10 @@ Code z$optimizer - Output - : Generalized Simulated Annealing - * Parameters: list() + Message + + -- OptimizerBatchGenSA - Generalized Simulated Annealing ----------------------- + * Parameters: - * Parameter classes: ParamDbl * Properties: single-crit * Packages: bbotk, GenSA diff --git a/tests/testthat/_snaps/OptimizerGridSearch.md b/tests/testthat/_snaps/OptimizerGridSearch.md index 664cdc56..20af1f60 100644 --- a/tests/testthat/_snaps/OptimizerGridSearch.md +++ b/tests/testthat/_snaps/OptimizerGridSearch.md @@ -2,8 +2,9 @@ Code z$optimizer - Output - : Grid Search + Message + + -- OptimizerBatchGridSearch - Grid Search -------------------------------------- * Parameters: batch_size=1, resolution=10 * Parameter classes: ParamLgl, ParamInt, ParamDbl, ParamFct * Properties: dependencies, single-crit, multi-crit @@ -13,8 +14,9 @@ Code z$optimizer - Output - : Grid Search + Message + + -- OptimizerBatchGridSearch - Grid Search -------------------------------------- * Parameters: batch_size=1, resolution=10 * Parameter classes: ParamLgl, ParamInt, ParamDbl, ParamFct * Properties: dependencies, single-crit, multi-crit diff --git a/tests/testthat/_snaps/OptimizerLocalSearch.md b/tests/testthat/_snaps/OptimizerLocalSearch.md index 34b8af83..d7bd816b 100644 --- a/tests/testthat/_snaps/OptimizerLocalSearch.md +++ b/tests/testthat/_snaps/OptimizerLocalSearch.md @@ -2,10 +2,11 @@ Code z$optimizer - Output - : Local Search + Message + + -- OptimizerBatchLocalSearch - Local Search ------------------------------------ * Parameters: n_initial_points=3, initial_random_sample_size=100, - neighbors_per_point=10, mutation_sd=0.1 + neighbors_per_point=10, mutation_sd=0.1 * Parameter classes: ParamLgl, ParamInt, ParamDbl, ParamFct * Properties: dependencies, single-crit * Packages: bbotk @@ -14,10 +15,11 @@ Code optimizer - Output - : Local Search + Message + + -- OptimizerBatchLocalSearch - Local Search ------------------------------------ * Parameters: n_initial_points=3, initial_random_sample_size=100, - neighbors_per_point=10, mutation_sd=0.1 + neighbors_per_point=10, mutation_sd=0.1 * Parameter classes: ParamLgl, ParamInt, ParamDbl, ParamFct * Properties: dependencies, single-crit * Packages: bbotk @@ -26,10 +28,11 @@ Code optimizer - Output - : Local Search + Message + + -- OptimizerBatchLocalSearch - Local Search ------------------------------------ * Parameters: n_initial_points=3, initial_random_sample_size=100, - neighbors_per_point=10, mutation_sd=0.1 + neighbors_per_point=10, mutation_sd=0.1 * Parameter classes: ParamLgl, ParamInt, ParamDbl, ParamFct * Properties: dependencies, single-crit * Packages: bbotk diff --git a/tests/testthat/_snaps/OptimizerNLoptr.md b/tests/testthat/_snaps/OptimizerNLoptr.md index b49aa021..96dea2c2 100644 --- a/tests/testthat/_snaps/OptimizerNLoptr.md +++ b/tests/testthat/_snaps/OptimizerNLoptr.md @@ -2,10 +2,11 @@ Code z$optimizer - Output - : Non-linear Optimization - * Parameters: algorithm=NLOPT_LN_BOBYQA, xtol_rel=-1, xtol_abs=-1, - ftol_rel=-1, ftol_abs=-1, start_values=random + Message + + -- OptimizerBatchNLoptr - Non-linear Optimization ------------------------------ + * Parameters: algorithm=NLOPT_LN_BOBYQA, xtol_rel=-1, xtol_abs=-1, ftol_rel=-1, + ftol_abs=-1, start_values=random * Parameter classes: ParamDbl * Properties: single-crit * Packages: bbotk, nloptr diff --git a/tests/testthat/_snaps/OptimizerRandomSearch.md b/tests/testthat/_snaps/OptimizerRandomSearch.md index 0bb24a28..686a696e 100644 --- a/tests/testthat/_snaps/OptimizerRandomSearch.md +++ b/tests/testthat/_snaps/OptimizerRandomSearch.md @@ -2,8 +2,9 @@ Code z$optimizer - Output - : Random Search + Message + + -- OptimizerBatchRandomSearch - Random Search ---------------------------------- * Parameters: batch_size=1 * Parameter classes: ParamLgl, ParamInt, ParamDbl, ParamFct * Properties: dependencies, single-crit, multi-crit @@ -13,8 +14,9 @@ Code z$optimizer - Output - : Random Search + Message + + -- OptimizerBatchRandomSearch - Random Search ---------------------------------- * Parameters: batch_size=1 * Parameter classes: ParamLgl, ParamInt, ParamDbl, ParamFct * Properties: dependencies, single-crit, multi-crit @@ -24,8 +26,9 @@ Code z$optimizer - Output - : Random Search + Message + + -- OptimizerBatchRandomSearch - Random Search ---------------------------------- * Parameters: batch_size=10 * Parameter classes: ParamLgl, ParamInt, ParamDbl, ParamFct * Properties: dependencies, single-crit, multi-crit diff --git a/tests/testthat/_snaps/TerminatorClockTime.md b/tests/testthat/_snaps/TerminatorClockTime.md index 7a876845..8b619ffe 100644 --- a/tests/testthat/_snaps/TerminatorClockTime.md +++ b/tests/testthat/_snaps/TerminatorClockTime.md @@ -2,7 +2,8 @@ Code terminator - Output - : Clock Time + Message + + -- TerminatorClockTime - Clock Time -------------------------------------------- * Parameters: stop_time= diff --git a/tests/testthat/_snaps/TerminatorCombo.md b/tests/testthat/_snaps/TerminatorCombo.md index 449f1a5d..4a7ff954 100644 --- a/tests/testthat/_snaps/TerminatorCombo.md +++ b/tests/testthat/_snaps/TerminatorCombo.md @@ -2,8 +2,9 @@ Code terminator - Output - : Combination + Message + + -- TerminatorCombo - Combination ----------------------------------------------- * Parameters: any=TRUE - * Terminators: , + * Terminators: , diff --git a/tests/testthat/_snaps/TerminatorEvals.md b/tests/testthat/_snaps/TerminatorEvals.md index 89c17446..81c6c900 100644 --- a/tests/testthat/_snaps/TerminatorEvals.md +++ b/tests/testthat/_snaps/TerminatorEvals.md @@ -2,23 +2,26 @@ Code inst$terminator - Output - : Number of Evaluation + Message + + -- TerminatorEvals - Number of Evaluation -------------------------------------- * Parameters: n_evals=7, k=0 --- Code inst$terminator - Output - : Number of Evaluation + Message + + -- TerminatorEvals - Number of Evaluation -------------------------------------- * Parameters: n_evals=7, k=2 --- Code inst$terminator - Output - : Number of Evaluation + Message + + -- TerminatorEvals - Number of Evaluation -------------------------------------- * Parameters: n_evals=0, k=2 diff --git a/tests/testthat/_snaps/TerminatorNone.md b/tests/testthat/_snaps/TerminatorNone.md index da57bfa7..53bac051 100644 --- a/tests/testthat/_snaps/TerminatorNone.md +++ b/tests/testthat/_snaps/TerminatorNone.md @@ -4,11 +4,17 @@ terminators Output $evals - : Number of Evaluation + Message + + -- TerminatorEvals - Number of Evaluation -------------------------------------- * Parameters: n_evals=10, k=0 + Output $none - : None - * Parameters: list() + Message + + -- TerminatorNone - None ------------------------------------------------------- + * Parameters: - + Output diff --git a/tests/testthat/_snaps/TerminatorPerfReached.md b/tests/testthat/_snaps/TerminatorPerfReached.md index e6280a3e..32073c23 100644 --- a/tests/testthat/_snaps/TerminatorPerfReached.md +++ b/tests/testthat/_snaps/TerminatorPerfReached.md @@ -2,7 +2,8 @@ Code terminator - Output - : Performance Level + Message + + -- TerminatorPerfReached - Performance Level ----------------------------------- * Parameters: level=0.2 diff --git a/tests/testthat/_snaps/TerminatorRunTime.md b/tests/testthat/_snaps/TerminatorRunTime.md index bf918c02..73d966b6 100644 --- a/tests/testthat/_snaps/TerminatorRunTime.md +++ b/tests/testthat/_snaps/TerminatorRunTime.md @@ -2,7 +2,8 @@ Code terminator - Output - : Run Time + Message + + -- TerminatorRunTime - Run Time ------------------------------------------------ * Parameters: secs=1 diff --git a/tests/testthat/_snaps/TerminatorStagnation.md b/tests/testthat/_snaps/TerminatorStagnation.md index b54af3e1..d9b3bc2a 100644 --- a/tests/testthat/_snaps/TerminatorStagnation.md +++ b/tests/testthat/_snaps/TerminatorStagnation.md @@ -2,7 +2,8 @@ Code terminator - Output - : Stagnation + Message + + -- TerminatorStagnation - Stagnation ------------------------------------------- * Parameters: iters=10, threshold=100 diff --git a/tests/testthat/_snaps/TerminatorStagnationBatch.md b/tests/testthat/_snaps/TerminatorStagnationBatch.md index 596fa32b..a805ddb2 100644 --- a/tests/testthat/_snaps/TerminatorStagnationBatch.md +++ b/tests/testthat/_snaps/TerminatorStagnationBatch.md @@ -2,15 +2,17 @@ Code terminator - Output - : Stagnation Batch + Message + + -- TerminatorStagnationBatch - Stagnation Batch -------------------------------- * Parameters: n=1, threshold=0 # TerminatorStagnationBatch works with single objective and n = 2 Code terminator - Output - : Stagnation Batch + Message + + -- TerminatorStagnationBatch - Stagnation Batch -------------------------------- * Parameters: n=2, threshold=0