Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compatibility: work with new irace 4.0.0 #243

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Suggests:
adagio,
emoa,
GenSA,
irace (>= 3.5),
irace (>= 3.9.0.9000),
knitr,
nloptr,
progressr,
Expand All @@ -45,6 +45,8 @@ Suggests:
rmarkdown,
testthat (>= 3.0.0),
rush
Remotes:
MLopez-Ibanez/irace
VignetteBuilder:
knitr
Config/testthat/edition: 3
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# bbotk (development version)

compatibility: Work with new irace 4.0.0

# bbotk 1.0.1

* refactor: extra columns in results.
Expand Down
21 changes: 13 additions & 8 deletions R/OptimizerBatchIrace.R
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,20 @@ OptimizerBatchIrace = R6Class("OptimizerBatchIrace",
}

# make scenario
scenario = c(list(maxExperiments = terminator$param_set$values$n_evals, targetRunnerData = list(inst = inst)), pv)
digits = pv$digits
pv$digits = NULL

scenario = c(list(
parameters = paradox_to_irace(inst$search_space, pv$digits),
maxExperiments = terminator$param_set$values$n_evals,
targetRunnerData = list(inst = inst)), pv)

# run irace
res = invoke(irace::irace, scenario = scenario, parameters = paradox_to_irace(inst$search_space, pv$digits), .opts = allow_partial_matching)
res = invoke(irace::irace, scenario = scenario, .opts = allow_partial_matching)

# add race and step to archive
iraceResults = NULL
load(self$param_set$values$logFile)
log = as.data.table(iraceResults$experimentLog)
iraceResults = irace::read_logfile(self$param_set$values$logFile)
log = iraceResults$state$experiment_log
log[, "step" := rleid("instance"), by = "iteration"]
set(inst$archive$data, j = "race", value = log$iteration)
set(inst$archive$data, j = "step", value = log$step)
Expand Down Expand Up @@ -220,14 +225,14 @@ OptimizerBatchIrace = R6Class("OptimizerBatchIrace",

mlr_optimizers$add("irace", OptimizerBatchIrace)

target_runner_default = function(experiment, exec.target.runner, scenario, target.runner) { # nolint
target_runner_default = function(experiment, exec_target_runner, scenario, target_runner) { # nolint
optim_instance = scenario$targetRunnerData$inst

xdt = map_dtr(experiment, function(e) {
configuration = as.data.table(e$configuration)
# add configuration and instance id to archive
set(configuration, j = "configuration", value = e$id.configuration)
set(configuration, j = "instance", value = e$id.instance)
set(configuration, j = "configuration", value = e$id_configuration)
set(configuration, j = "instance", value = e$id_instance)
configuration
})
# fix logicals
Expand Down
17 changes: 11 additions & 6 deletions tests/testthat/helper.R
Original file line number Diff line number Diff line change
Expand Up @@ -168,32 +168,37 @@ MAKE_OPT = function(param_set = ps(), param_classes = c("ParamDbl", "ParamInt"),
}

expect_irace_parameters = function(parameters, names, types, domain, conditions, depends, hierarchy) {
expect_list(parameters, len = 13, any.missing = FALSE)
expect_equal(names(parameters), c("names", "types", "switches", "domain", "conditions", "isFixed", "transform",
"isDependent", "depends", "hierarchy", "nbParameters", "nbFixed", "nbVariable"))
expect_class(parameters, "ParameterSpace")

expect_equal(parameters$names, names)
expect_equal(parameters$types, set_names(types, names))
expect_equal(parameters$switches, named_vector(names, ""))
expect_equal(parameters$domain, domain)
expect_equal(parameters$domains, domain)

if (missing(conditions)) {
expect_equal(parameters$conditions, named_list(names, TRUE))
} else {
# can't compare expressions directly
expect_equal(as.character(parameters$conditions), as.character(conditions))
}

expect_equal(parameters$isFixed, named_vector(names, FALSE))
expect_equal(parameters$transform, named_list(names, ""))
expect_equal(parameters$isDependent, named_vector(names, FALSE))

# expect_equal(parameters$transform, named_list(names, ""))
# expect_equal(parameters$is_dependent, named_vector(names, FALSE))

if (missing(depends)) {
expect_equal(parameters$depends, named_list(names, character(0)))
} else {
expect_equal(parameters$depends, depends)
}

if (missing(hierarchy)) {
expect_equal(parameters$hierarchy, named_vector(names, 1))
} else {
expect_equal(parameters$hierarchy, set_names(hierarchy, names))
}

expect_equal(parameters$nbParameters, length(names))
expect_equal(parameters$nbFixed, 0)
expect_equal(parameters$nbVariable, length(names))
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test_OptimizerIrace.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ test_that("OptimizerBatchIrace minimize works", {

# check optimization direction
# first elite of the first race should have the lowest average performance
load(optimizer$param_set$values$logFile)
iraceResults = irace::read_logfile(optimizer$param_set$values$logFile)
elites = iraceResults$allElites
aggr = instance$archive$data[race == 1, .(y = mean(y)), by = configuration]
expect_equal(aggr[which.min(y), configuration], elites[[1]][1])
Expand Down Expand Up @@ -68,7 +68,7 @@ test_that("OptimizerBatchIrace maximize works", {

# check optimization direction
# first elite of the first race should have the highest average performance
load(optimizer$param_set$values$logFile)
iraceResults = irace::read_logfile(optimizer$param_set$values$logFile)
elites = iraceResults$allElites
aggr = instance$archive$data[race == 1, .(y = mean(y)), by = configuration]
expect_equal(aggr[which.max(y), configuration], elites[[1]][1])
Expand Down
Loading