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

Enable parallel tests #278

Merged
merged 4 commits into from Nov 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion DESCRIPTION
Expand Up @@ -53,11 +53,13 @@ Suggests:
mlr3pipelines,
nloptr,
rpart,
testthat
testthat (>= 3.0.0)
Remotes:
mlr-org/bbotk
Encoding: UTF-8
NeedsCompilation: no
Config/testthat/edition: 3
Config/testthat/parallel: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.1.1
Collate:
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/helper.R
Expand Up @@ -6,15 +6,15 @@ expect_tuner = function(tuner) {
public = c("optimize", "param_set"),
private = ".optimize"
)
expect_is(tuner$param_set, "ParamSet")
expect_class(tuner$param_set, "ParamSet")
expect_function(tuner$optimize, args = "inst")
}

expect_terminator = function(term) {
expect_r6(term, "Terminator",
public = c("is_terminated", "param_set")
)
expect_is(term$param_set, "ParamSet")
expect_class(term$param_set, "ParamSet")
}

#FIXME: This function should be exported so it can be used for tests in other packages
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/setup.R
@@ -1,4 +1,5 @@
library(mlr3)
attachNamespace("checkmate")
old_opts = options(
warnPartialMatchArgs = TRUE,
warnPartialMatchAttr = TRUE,
Expand Down
14 changes: 6 additions & 8 deletions tests/testthat/test_AutoTuner.R
@@ -1,5 +1,3 @@
context("AutoTuner")

test_that("AutoTuner / train+predict", {
te = trm("evals", n_evals = 4)
task = tsk("iris")
Expand All @@ -19,7 +17,7 @@ test_that("AutoTuner / train+predict", {
expect_equal(r$learner_param_vals[[1]], list(xval = 0, cp = 0.2))
prd = at$predict(task)
expect_prediction(prd)
expect_is(at$learner$model, "rpart")
expect_s3_class(at$learner$model, "rpart")
})

test_that("AutoTuner / resample", {
Expand Down Expand Up @@ -169,7 +167,7 @@ test_that("AutoTuner works with graphlearner", {
expect_equal(r$learner_param_vals[[1]]$classif.rpart.cp, 0.2)
prd = at$predict(task)
expect_prediction(prd)
expect_is(at$learner$model$classif.rpart$model, "rpart")
expect_s3_class(at$learner$model$classif.rpart$model, "rpart")
})

test_that("Nested resampling works with graphlearner", {
Expand Down Expand Up @@ -209,8 +207,8 @@ test_that("Nested resampling works with graphlearner", {
expect_data_table(tab$learner[[1]]$archive$data(), nrows = 3L)
expect_data_table(tab$learner[[2]]$archive$data(), nrows = 3L)

expect_is(tab$learner[[1]]$model$learner$model$classif.rpart$model, "rpart")
expect_is(tab$learner[[1]]$model$learner$model$classif.rpart$model, "rpart")
expect_s3_class(tab$learner[[1]]$model$learner$model$classif.rpart$model, "rpart")
expect_s3_class(tab$learner[[1]]$model$learner$model$classif.rpart$model, "rpart")
})

test_that("store_tuning_instance, store_benchmark_result and store_models flags work", {
Expand Down Expand Up @@ -283,10 +281,10 @@ test_that("predict_type works", {
tuner = tuner)

at$train(task)
expect_equal(at$predict_type, "response")
expect_equal(at$predict_type, "response")
expect_equal(at$model$learner$predict_type, "response")

at$predict_type = "prob"
expect_equal(at$predict_type, "prob")
expect_equal(at$predict_type, "prob")
expect_equal(at$model$learner$predict_type, "prob")
})
2 changes: 0 additions & 2 deletions tests/testthat/test_ObjectiveTuning.R
@@ -1,5 +1,3 @@
context("ObjectiveTuning")

test_that("ObjectiveTuning", {
task = tsk("iris")
learner = lrn("classif.rpart")
Expand Down
2 changes: 0 additions & 2 deletions tests/testthat/test_Tuner.R
@@ -1,5 +1,3 @@
context("Tuner")

test_that("API", {
for (n_evals in c(1, 5)) {
rs = TunerRandomSearch$new()
Expand Down
2 changes: 0 additions & 2 deletions tests/testthat/test_TunerCmaes.R
@@ -1,5 +1,3 @@
context("TunerCmaes")

test_that("TunerCmaes", {
test_tuner("cmaes", par = 0.3)
})
2 changes: 0 additions & 2 deletions tests/testthat/test_TunerDesignPoints.R
@@ -1,5 +1,3 @@
context("TunerDesignPoints")

test_that("TunerDesignPoints", {
d = data.table(cp = c(0.1, 0.3))
test_tuner("design_points", design = d, term_evals = 2L, real_evals = 2, n_dim = 1L)
Expand Down
2 changes: 0 additions & 2 deletions tests/testthat/test_TunerGenSA.R
@@ -1,5 +1,3 @@
context("TunerGenSA")

skip_if_not_installed("GenSA")

test_that("TunerGenSA", {
Expand Down
2 changes: 0 additions & 2 deletions tests/testthat/test_TunerGridSearch.R
@@ -1,5 +1,3 @@
context("TunerGridSearch")

test_that("TunerGridSearch", {
test_tuner("grid_search", resolution = 7, term_evals = 5L, real_evals = 5, n_dim = 1L)
test_tuner_dependencies("grid_search")
Expand Down
2 changes: 0 additions & 2 deletions tests/testthat/test_TunerNLoptr.R
@@ -1,5 +1,3 @@
context("TunerNLoptr")

test_that("TunerNLoptr", {
skip_on_os("windows")
test_tuner("nloptr", x0 = 0.3, algorithm = "NLOPT_LN_BOBYQA", term_evals = 4)
Expand Down
2 changes: 0 additions & 2 deletions tests/testthat/test_TunerRandomSearch.R
@@ -1,5 +1,3 @@
context("TunerRandomSearch")

test_that("TunerRandomSearch", {
test_tuner("random_search")
test_tuner_dependencies("random_search")
Expand Down
7 changes: 3 additions & 4 deletions tests/testthat/test_TuningInstanceMultiCrit.R
@@ -1,5 +1,3 @@
context("TuningInstanceMultiCrit")

test_that("tuning with multiple objectives", {
task = tsk("pima")
resampling = rsmp("holdout")
Expand Down Expand Up @@ -41,7 +39,8 @@ test_that("store_benchmark_result and store_models flag works", {
inst$eval_batch(data.table(cp = c(0.3, 0.25), minsplit = c(3, 4)))
expect_r6(inst$archive$benchmark_result, "BenchmarkResult")

expect_error(TEST_MAKE_INST1_2D(store_benchmark_result = FALSE,
expect_error(TEST_MAKE_INST1_2D(
store_benchmark_result = FALSE,
store_models = TRUE),
regexp = "Models can only be stored if store_benchmark_result is set to TRUE",
fixed = TRUE)
Expand Down Expand Up @@ -75,5 +74,5 @@ test_that("check_values flag with parameter set dependencies", {
rsmp("holdout"), msr("regr.mse"), search_space, terminator,
check_values = TRUE)
expect_error(tuner$optimize(inst),
fixed = "The parameter 'yy' can only be set")
regexp = "The parameter 'yy' can only be set")
})
4 changes: 1 addition & 3 deletions tests/testthat/test_TuningInstanceSingleCrit.R
@@ -1,5 +1,3 @@
context("TuningInstanceSingleCrit")

test_that("TuningInstanceSingleCrit", {
inst = TEST_MAKE_INST1(values = list(maxdepth = 10), folds = 2L, measure = msr("dummy.cp.classif", fun = function(pv) pv$cp), n_dim = 2)
# test empty inst
Expand Down Expand Up @@ -186,5 +184,5 @@ test_that("check_values flag with parameter set dependencies", {
rsmp("holdout"), msr("regr.mse"), search_space, terminator,
check_values = TRUE)
expect_error(tuner$optimize(inst),
fixed = "The parameter 'yy' can only be set")
regexp = "The parameter 'yy' can only be set")
})
2 changes: 0 additions & 2 deletions tests/testthat/test_error_handling.R
@@ -1,5 +1,3 @@
context("error handling")

test_that("failing learner", {
learner = lrn("classif.debug")
param_set = ParamSet$new(list(
Expand Down
2 changes: 0 additions & 2 deletions tests/testthat/test_mlr_tuners.R
@@ -1,5 +1,3 @@
context("mlr_tuners")

test_that("mlr_tuners", {
expect_dictionary(mlr_tuners)
for (key in mlr_tuners$keys()) {
Expand Down
2 changes: 0 additions & 2 deletions tests/testthat/test_trafos.R
@@ -1,5 +1,3 @@
context("trafos")

test_that("simple exp trafo works", {
ll = lrn("classif.rpart")
ps = ParamSet$new(params = list(
Expand Down