Skip to content

Commit

Permalink
refactor: revert cli
Browse files Browse the repository at this point in the history
  • Loading branch information
be-marc committed Jun 25, 2024
1 parent c374694 commit dd8251c
Show file tree
Hide file tree
Showing 29 changed files with 119 additions and 157 deletions.
1 change: 0 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ Depends:
R (>= 3.1.0)
Imports:
checkmate (>= 2.0.0),
cli,
data.table,
lgr,
methods,
Expand Down
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ export(transform_xdt_to_xss)
export(trm)
export(trms)
import(checkmate)
import(cli)
import(data.table)
import(mlr3misc)
import(paradox)
Expand Down
4 changes: 2 additions & 2 deletions R/Archive.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ Archive = R6Class("Archive",
#'
#' @param ... (ignored).
print = function() {
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)
catf(format(self))
print(self$data[, setdiff(names(self$data), "x_domain"), with = FALSE], digits = 2)
},

#' @description
Expand Down
14 changes: 7 additions & 7 deletions R/Objective.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@ Objective = R6Class("Objective",
#' Print method.
#' @return `character()`.
print = function() {
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])
catf(self$format())
catf("Domain:")
print(self$domain)
catf("Codomain:")
print(self$codomain)
if (length(self$constants$values) > 0) {
cli_li("Constants:")
print(as.data.table(self$constants)[, c("id", "class", "lower", "upper", "nlevels"), with = FALSE])
catf("Constants:")
print(self$constants)
}
},

Expand Down
25 changes: 14 additions & 11 deletions R/OptimInstance.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,22 @@ OptimInstance = R6Class("OptimInstance",
#'
#' @param ... (ignored).
print = function(...) {
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 ""))

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)))
if (!is.null(private$.result)) {
cli_li("Result:")
catf("* Result:")
print(self$result[, 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)
catf("* Archive:")
print(as.data.table(self$archive)[, c(self$archive$cols_x, self$archive$cols_y), with = FALSE])
}
},

Expand Down
2 changes: 1 addition & 1 deletion R/OptimInstanceAsync.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ OptimInstanceAsync = R6Class("OptimInstanceAsync",
#' @param ... (ignored).
print = function(...) {
super$print()
cli_li(sprintf("Workers: %i", self$rush$n_workers))
catf(str_indent("* Workers:", self$rush$n_workers))
},

#' @description
Expand Down
10 changes: 5 additions & 5 deletions R/Optimizer.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ Optimizer = R6Class("Optimizer",
#'
#' @return (`character()`).
print = function() {
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 = ", ")))
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))
},

#' @description
Expand Down
4 changes: 2 additions & 2 deletions R/Terminator.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ Terminator = R6Class("Terminator",
#'
#' @param ... (ignored).
print = function(...) {
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 "-"))
catn(format(self), if (is.na(self$label)) "" else paste0(": ", self$label))
catn(str_indent("* Parameters:", as_short_string(self$param_set$values)))
},

#' @description
Expand Down
1 change: 0 additions & 1 deletion R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#' @import checkmate
#' @import paradox
#' @import mlr3misc
#' @import cli
#' @importFrom R6 R6Class
#' @importFrom utils capture.output head tail
#' @importFrom methods formalArgs
Expand Down
3 changes: 3 additions & 0 deletions man/Codomain.Rd

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

4 changes: 1 addition & 3 deletions tests/testthat/_snaps/ArchiveBatch.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

Code
a
Message
-- ArchiveBatch - Data Table Storage -------------------------------------------
Output
<ArchiveBatch>
Null data.table (0 rows and 0 cols)

52 changes: 24 additions & 28 deletions tests/testthat/_snaps/Objective.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,35 @@

Code
obj
Message
-- ObjectiveTestEval -----------------------------------------------------------
* Domain:
Output
id class lower upper nlevels
<char> <char> <num> <num> <num>
1: x1 ParamDbl -1 1 Inf
2: x2 ParamDbl -1 1 Inf
Message
* Codomain:
Output
id class lower upper
<char> <char> <num> <num>
1: y ParamDbl -Inf Inf
<ObjectiveTestEval:f>
Domain:
<ParamSet(2)>
id class lower upper nlevels default value
<char> <char> <num> <num> <num> <list> <list>
1: x1 ParamDbl -1 1 Inf <NoDefault[0]>
2: x2 ParamDbl -1 1 Inf <NoDefault[0]>
Codomain:
<Codomain(1)>
id class lower upper nlevels default value
<char> <char> <num> <num> <num> <list> <list>
1: y ParamDbl -Inf Inf Inf <NoDefault[0]>

---

Code
obj
Message
-- ObjectiveTestEvalMany -------------------------------------------------------
* Domain:
Output
id class lower upper nlevels
<char> <char> <num> <num> <num>
1: x1 ParamDbl -1 1 Inf
2: x2 ParamDbl -1 1 Inf
Message
* Codomain:
Output
id class lower upper
<char> <char> <num> <num>
1: y ParamDbl -Inf Inf
<ObjectiveTestEvalMany:f>
Domain:
<ParamSet(2)>
id class lower upper nlevels default value
<char> <char> <num> <num> <num> <list> <list>
1: x1 ParamDbl -1 1 Inf <NoDefault[0]>
2: x2 ParamDbl -1 1 Inf <NoDefault[0]>
Codomain:
<Codomain(1)>
id class lower upper nlevels default value
<char> <char> <num> <num> <num> <list> <list>
1: y ParamDbl -Inf Inf Inf <NoDefault[0]>

13 changes: 5 additions & 8 deletions tests/testthat/_snaps/OptimInstanceBatchMultiCrit.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@

Code
inst
Message
-- OptimInstanceBatchMultiCrit -------------------------------------------------
* State: Not optimized
* Objective: ObjectiveRFun
* Search Space:
Output
<OptimInstanceBatchMultiCrit>
* State: Not optimized
* Objective: <ObjectiveRFun:function>
* Search Space:
id class lower upper nlevels
<char> <char> <num> <num> <num>
1: x1 ParamDbl -1 1 Inf
2: x2 ParamDbl -1 1 Inf
Message
* Terminator: TerminatorEvals (n_evals=20, k=0)
* Terminator: <TerminatorEvals>

13 changes: 5 additions & 8 deletions tests/testthat/_snaps/OptimInstanceBatchSingleCrit.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@

Code
inst
Message
-- OptimInstanceBatchSingleCrit ------------------------------------------------
* State: Not optimized
* Objective: ObjectiveRFun
* Search Space:
Output
<OptimInstanceBatchSingleCrit>
* State: Not optimized
* Objective: <ObjectiveRFun:function>
* Search Space:
id class lower upper nlevels
<char> <char> <num> <num> <num>
1: x1 ParamDbl -1 1 Inf
2: x2 ParamDbl -1 1 Inf
Message
* Terminator: TerminatorEvals (n_evals=20, k=0)
* Terminator: <TerminatorEvals>

5 changes: 2 additions & 3 deletions tests/testthat/_snaps/OptimizerCmaes.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

Code
z$optimizer
Message
-- OptimizerBatchCmaes - Covariance Matrix Adaptation Evolution Strategy -------
Output
<OptimizerBatchCmaes>: Covariance Matrix Adaptation Evolution Strategy
* Parameters: start_values=random
* Parameter classes: ParamDbl
* Properties: single-crit
Expand Down
10 changes: 4 additions & 6 deletions tests/testthat/_snaps/OptimizerDesignPoints.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

Code
z$optimizer
Message
-- OptimizerBatchDesignPoints - Design Points ----------------------------------
Output
<OptimizerBatchDesignPoints>: Design Points
* Parameters: batch_size=1, design=<data.table>
* Parameter classes: ParamLgl, ParamInt, ParamDbl, ParamFct, ParamUty
* Properties: dependencies, single-crit, multi-crit
Expand All @@ -14,9 +13,8 @@

Code
z$optimizer
Message
-- OptimizerBatchDesignPoints - Design Points ----------------------------------
Output
<OptimizerBatchDesignPoints>: Design Points
* Parameters: batch_size=1, design=<data.table>
* Parameter classes: ParamLgl, ParamInt, ParamDbl, ParamFct, ParamUty
* Properties: dependencies, single-crit, multi-crit
Expand Down
10 changes: 4 additions & 6 deletions tests/testthat/_snaps/OptimizerFocusSearch.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

Code
z$optimizer
Message
-- OptimizerBatchFocusSearch - Focus Search ------------------------------------
Output
<OptimizerBatchFocusSearch>: Focus Search
* Parameters: n_points=1, maxit=10
* Parameter classes: ParamLgl, ParamInt, ParamDbl, ParamFct
* Properties: dependencies, single-crit
Expand All @@ -14,9 +13,8 @@

Code
z$optimizer
Message
-- OptimizerBatchFocusSearch - Focus Search ------------------------------------
Output
<OptimizerBatchFocusSearch>: Focus Search
* Parameters: n_points=10, maxit=10
* Parameter classes: ParamLgl, ParamInt, ParamDbl, ParamFct
* Properties: dependencies, single-crit
Expand Down
7 changes: 3 additions & 4 deletions tests/testthat/_snaps/OptimizerGenSA.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

Code
z$optimizer
Message
-- OptimizerBatchGenSA - Generalized Simulated Annealing -----------------------
* Parameters: -
Output
<OptimizerBatchGenSA>: Generalized Simulated Annealing
* Parameters: list()
* Parameter classes: ParamDbl
* Properties: single-crit
* Packages: bbotk, GenSA
Expand Down
10 changes: 4 additions & 6 deletions tests/testthat/_snaps/OptimizerGridSearch.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

Code
z$optimizer
Message
-- OptimizerBatchGridSearch - Grid Search --------------------------------------
Output
<OptimizerBatchGridSearch>: Grid Search
* Parameters: batch_size=1, resolution=10
* Parameter classes: ParamLgl, ParamInt, ParamDbl, ParamFct
* Properties: dependencies, single-crit, multi-crit
Expand All @@ -14,9 +13,8 @@

Code
z$optimizer
Message
-- OptimizerBatchGridSearch - Grid Search --------------------------------------
Output
<OptimizerBatchGridSearch>: Grid Search
* Parameters: batch_size=1, resolution=10
* Parameter classes: ParamLgl, ParamInt, ParamDbl, ParamFct
* Properties: dependencies, single-crit, multi-crit
Expand Down
9 changes: 4 additions & 5 deletions tests/testthat/_snaps/OptimizerNLoptr.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

Code
z$optimizer
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
Output
<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
Expand Down
Loading

0 comments on commit dd8251c

Please sign in to comment.