From 25a7b5ca49b7437851f89a91f54ad61249ce7e5c Mon Sep 17 00:00:00 2001 From: be-marc Date: Thu, 7 Nov 2024 19:29:31 +0100 Subject: [PATCH 1/2] chore: add async property to optimizer --- R/OptimizerAsyncDesignPoints.R | 2 +- R/OptimizerAsyncGridSearch.R | 2 +- R/OptimizerAsyncRandomSearch.R | 2 +- R/bbotk_reflections.R | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/R/OptimizerAsyncDesignPoints.R b/R/OptimizerAsyncDesignPoints.R index eb5f1b76..36d35d86 100644 --- a/R/OptimizerAsyncDesignPoints.R +++ b/R/OptimizerAsyncDesignPoints.R @@ -32,7 +32,7 @@ OptimizerAsyncDesignPoints = R6Class("OptimizerAsyncDesignPoints", id = "design_points", param_set = param_set, param_classes = c("ParamLgl", "ParamInt", "ParamDbl", "ParamFct", "ParamUty"), - properties = c("dependencies", "single-crit", "multi-crit"), + properties = c("dependencies", "single-crit", "multi-crit", "async"), packages = "rush", label = "Asynchronous Design Points", man = "bbotk::mlr_optimizers_async_design_points" diff --git a/R/OptimizerAsyncGridSearch.R b/R/OptimizerAsyncGridSearch.R index b3a771f0..d443e78d 100644 --- a/R/OptimizerAsyncGridSearch.R +++ b/R/OptimizerAsyncGridSearch.R @@ -40,7 +40,7 @@ OptimizerAsyncGridSearch = R6Class("OptimizerAsyncGridSearch", id = "async_grid_search", param_set = param_set, param_classes = c("ParamLgl", "ParamInt", "ParamDbl", "ParamFct"), - properties = c("dependencies", "single-crit", "multi-crit"), + properties = c("dependencies", "single-crit", "multi-crit", "async"), packages = "rush", label = "Asynchronous Grid Search", man = "bbotk::mlr_optimizers_async_grid_search" diff --git a/R/OptimizerAsyncRandomSearch.R b/R/OptimizerAsyncRandomSearch.R index 266c2066..27d6e409 100644 --- a/R/OptimizerAsyncRandomSearch.R +++ b/R/OptimizerAsyncRandomSearch.R @@ -25,7 +25,7 @@ OptimizerAsyncRandomSearch = R6Class("OptimizerAsyncRandomSearch", id = "async_random_search", param_set = ps(), param_classes = c("ParamLgl", "ParamInt", "ParamDbl", "ParamFct"), - properties = c("dependencies", "single-crit", "multi-crit"), + properties = c("dependencies", "single-crit", "multi-crit", "async"), packages = "rush", label = "Asynchronous Random Search", man = "bbotk::mlr_optimizers_random_search" diff --git a/R/bbotk_reflections.R b/R/bbotk_reflections.R index 56d9ac76..19a7651c 100644 --- a/R/bbotk_reflections.R +++ b/R/bbotk_reflections.R @@ -24,7 +24,7 @@ bbotk_reflections = new.env(parent = emptyenv()) ### optimizer_properties bbotk_reflections$optimizer_properties = c( - "dependencies", "single-crit", "multi-crit" + "dependencies", "single-crit", "multi-crit", "async" ) ### objective_properties From c9d4ee1286c0727a71b936bbc71ba35a1f4032f4 Mon Sep 17 00:00:00 2001 From: be-marc Date: Thu, 7 Nov 2024 19:51:52 +0100 Subject: [PATCH 2/2] tests: restarting the optimization works --- tests/testthat/test_OptimizerAsync.R | 29 ++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/testthat/test_OptimizerAsync.R b/tests/testthat/test_OptimizerAsync.R index ad0ee3d0..cfcce997 100644 --- a/tests/testthat/test_OptimizerAsync.R +++ b/tests/testthat/test_OptimizerAsync.R @@ -105,3 +105,32 @@ test_that("OptimizerAsync throws an error when all workers are lost", { expect_rush_reset(instance$rush) }) + +test_that("restarting the optimization works", { + skip_on_cran() + skip_if_not_installed("rush") + flush_redis() + library(rush) + + rush_plan(n_workers = 2) + + instance = oi_async( + objective = OBJ_2D, + search_space = PS_2D, + terminator = trm("evals", n_evals = 5L), + ) + + optimizer = opt("async_random_search") + optimizer$optimize(instance) + + expect_data_table(instance$archive$data, min.rows = 5L) + + Sys.sleep(1) + + instance$terminator$param_set$values$n_evals = 30L + + optimizer = opt("async_random_search") + optimizer$optimize(instance) + + expect_data_table(instance$archive$data, min.rows = 30L) +})