From aa8cdf8f305f21b1e57056602906d6372ac5eebd Mon Sep 17 00:00:00 2001 From: be-marc Date: Mon, 29 Jul 2024 13:10:03 +0200 Subject: [PATCH 1/2] compatibility: irace 4.0.0 --- DESCRIPTION | 4 +++- R/OptimizerBatchIrace.R | 21 +++++++++++++-------- tests/testthat/helper.R | 17 +++++++++++------ tests/testthat/test_OptimizerIrace.R | 4 ++-- 4 files changed, 29 insertions(+), 17 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 814e1d70..2a1a6351 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -36,7 +36,7 @@ Suggests: adagio, emoa, GenSA, - irace (>= 3.5), + irace (>= 3.9.0.9000), knitr, nloptr, progressr, @@ -45,6 +45,8 @@ Suggests: rmarkdown, testthat (>= 3.0.0), rush +Remotes: + MLopez-Ibanez/irace VignetteBuilder: knitr Config/testthat/edition: 3 diff --git a/R/OptimizerBatchIrace.R b/R/OptimizerBatchIrace.R index 68069373..418d5818 100644 --- a/R/OptimizerBatchIrace.R +++ b/R/OptimizerBatchIrace.R @@ -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) @@ -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 diff --git a/tests/testthat/helper.R b/tests/testthat/helper.R index 4b858960..c627bc84 100644 --- a/tests/testthat/helper.R +++ b/tests/testthat/helper.R @@ -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)) diff --git a/tests/testthat/test_OptimizerIrace.R b/tests/testthat/test_OptimizerIrace.R index a7a480c2..25f6f110 100644 --- a/tests/testthat/test_OptimizerIrace.R +++ b/tests/testthat/test_OptimizerIrace.R @@ -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]) @@ -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]) From 985caee3e8aa4023467a289712231c1a83753fe2 Mon Sep 17 00:00:00 2001 From: be-marc Date: Mon, 29 Jul 2024 13:11:27 +0200 Subject: [PATCH 2/2] chore: news --- NEWS.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS.md b/NEWS.md index 21b8c602..2d5e070d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # bbotk (development version) +compatibility: Work with new irace 4.0.0 + # bbotk 1.0.1 * refactor: extra columns in results.