Skip to content

Commit b0f74e2

Browse files
authored
compatibility: work with new irace 4.0.0 (#435)
* compatibility: work with new irace 4.0.0 * fix: irace * ... * ...
1 parent 218887e commit b0f74e2

File tree

4 files changed

+40
-18
lines changed

4 files changed

+40
-18
lines changed

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Depends:
2929
paradox (>= 1.0.1),
3030
R (>= 3.1.0)
3131
Imports:
32-
bbotk (>= 1.4.0),
32+
bbotk (>= 1.4.1),
3333
checkmate (>= 2.0.0),
3434
data.table,
3535
lgr,
@@ -39,7 +39,7 @@ Suggests:
3939
adagio,
4040
future,
4141
GenSA,
42-
irace,
42+
irace (>= 4.0.0),
4343
knitr,
4444
mlflow,
4545
mlr3learners (>= 0.7.0),

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ perf: save models on worker only when requested in `ObjectiveTuningAsync`.
1313
* refactor: Rename stage `on_result` to `on_result_end` in `CallbackAsyncTuning` and `CallbackBatchTuning`.
1414
* docs: Extend the `CallbackAsyncTuning` and `CallbackBatchTuning` documentation.
1515
* compatibility: mlr3 0.22.0
16+
* compatibility: Work with new irace 4.0.0
1617

1718
# mlr3tuning 1.1.0
1819

R/TunerBatchIrace.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,14 @@ TunerBatchIrace = R6Class("TunerBatchIrace",
132132
)
133133
)
134134

135-
target_runner_tuning = function(experiment, exec.target.runner, scenario, target.runner) {# nolint
135+
target_runner_tuning = function(experiment, exec_target_runner, scenario, target_runner) {# nolint
136136
tuning_instance = scenario$targetRunnerData$inst
137137

138138
xdt = map_dtr(experiment, function(e) {
139139
configuration = as.data.table(e$configuration)
140140
# add configuration and instance id to archive
141-
set(configuration, j = "configuration", value = e$id.configuration)
142-
set(configuration, j = "instance", value = e$id.instance)
141+
set(configuration, j = "configuration", value = e$id_configuration)
142+
set(configuration, j = "instance", value = e$id_instance)
143143
configuration
144144
})
145145
# fix logicals

tests/testthat/test_TunerBatchIrace.R

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
skip_if_not_installed("irace")
2-
skip_on_cran()
32

43
test_that("TunerIrace", {
5-
x = capture.output({z = test_tuner("irace", term_evals = 42, real_evals = 39)})
4+
z = test_tuner("irace", term_evals = 42)
65
instance = z$inst
76
archive = instance$archive$data
87
tuner = z$tuner
@@ -12,7 +11,7 @@ test_that("TunerIrace", {
1211

1312
# check optimization direction
1413
# first elite of the first race should have the lowest average performance
15-
load(tuner$param_set$values$logFile)
14+
iraceResults = irace::read_logfile(tuner$param_set$values$logFile)
1615
elites = iraceResults$allElites
1716
aggr = archive[race == 1, .(classif.ce = mean(classif.ce)), by = configuration]
1817
expect_equal(aggr[which.min(classif.ce), configuration], elites[[1]][1])
@@ -27,8 +26,13 @@ test_that("TunerIrace works with dependencies", {
2726
cp = p_dbl(lower = 0.001, upper = 0.1),
2827
minsplit = p_int(lower = 1, upper = 10, depends = cp == 0.005)
2928
)
30-
instance = TuningInstanceBatchSingleCrit$new(tsk("iris"), lrn("classif.rpart"), rsmp("holdout"), msr("classif.ce"),
31-
trm("evals", n_evals = 96), search_space)
29+
instance = ti(
30+
task = tsk("mtcars"),
31+
learner = lrn("regr.rpart"),
32+
resampling = rsmp("holdout"),
33+
measures = msr("regr.mse"),
34+
terminator = trm("evals", n_evals = 96),
35+
search_space = search_space)
3236
tuner = tnr("irace")
3337
x = capture.output({tuner$optimize(instance)})
3438

@@ -38,27 +42,44 @@ test_that("TunerIrace works with dependencies", {
3842
})
3943

4044
test_that("TunerIrace works with logical parameters", {
41-
search_space = ps(keep_model = p_lgl())
42-
instance = TuningInstanceBatchSingleCrit$new(tsk("mtcars"), lrn("regr.rpart"), rsmp("holdout"), msr("regr.mse"),
43-
trm("evals", n_evals = 42), search_space)
45+
search_space = ps(
46+
cp = p_dbl(lower = 0.001, upper = 0.1),
47+
keep_model = p_lgl())
48+
instance = ti(
49+
task = tsk("mtcars"),
50+
learner = lrn("regr.rpart"),
51+
resampling = rsmp("holdout"),
52+
measures = msr("regr.mse"),
53+
terminator = trm("evals", n_evals = 96),
54+
search_space = search_space)
4455
tuner = tnr("irace")
4556
x = capture.output({tuner$optimize(instance)})
4657
expect_logical(instance$archive$best()$keep_model)
4758
})
4859

4960
test_that("TunerIrace uses digits", {
5061
search_space = ps(cp = p_dbl(lower = pi * 1e-20, upper = 5.242e12 / 1e13))
51-
instance = TuningInstanceBatchSingleCrit$new(tsk("iris"), lrn("classif.rpart"), rsmp("holdout"), msr("classif.ce"),
52-
trm("evals", n_evals = 30), search_space)
62+
instance = ti(
63+
task = tsk("mtcars"),
64+
learner = lrn("regr.rpart"),
65+
resampling = rsmp("holdout"),
66+
measures = msr("regr.mse"),
67+
terminator = trm("evals", n_evals = 96),
68+
search_space = search_space)
5369
tuner = tnr("irace", nbIterations = 1L, minNbSurvival = 1)
5470
x = capture.output({expect_data_table(tuner$optimize(instance))})
5571
})
5672

5773
test_that("TunerIrace works with unnamed discrete values", {
5874
# we had a bug here, see (mlr) issue #627
5975
search_space = ps(minsplit = p_int(lower = 2L, upper = 7L))
60-
inst = TuningInstanceBatchSingleCrit$new(tsk("iris"), lrn("classif.rpart"), rsmp("holdout"), msr("classif.ce"),
61-
trm("evals", n_evals = 50), search_space)
76+
instance = ti(
77+
task = tsk("mtcars"),
78+
learner = lrn("regr.rpart"),
79+
resampling = rsmp("holdout"),
80+
measures = msr("regr.mse"),
81+
terminator = trm("evals", n_evals = 96),
82+
search_space = search_space)
6283
tuner = tnr("irace")
63-
x = capture.output({expect_data_table(tuner$optimize(inst))})
84+
x = capture.output({expect_data_table(tuner$optimize(instance))})
6485
})

0 commit comments

Comments
 (0)