Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# finetune (development version)

* A bug was fixed where `NULL` results generated during simulated annealing would cause errors when logging.

# finetune 1.2.1

* Maintenance release required by CRAN.
Expand Down
19 changes: 15 additions & 4 deletions R/sim_anneal_helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -459,31 +459,42 @@ get_outcome_names <- function(x, rs) {
res
}

set_config <- function(x, config = NULL, prefix = NULL) {
if (!is.null(x)) {
if (!is.null(prefix)) {
x <- dplyr::mutate(x, .config = paste0(prefix, "_", .config))
} else {
x <- dplyr::mutate(x, .config = config)
}
}
x
}

update_config <- function(x, prefix = NULL, config = "new", save_pred) {
if (!is.null(prefix)) {
x$.metrics <-
purrr::map(
x$.metrics,
\(x) dplyr::mutate(x, .config = paste0(prefix, "_", .config))
\(x) set_config(x, prefix = prefix)
)
if (save_pred) {
x$.predictions <-
purrr::map(
x$.predictions,
\(x) dplyr::mutate(x, .config = paste0(prefix, "_", .config))
\(x) set_config(x, prefix = prefix)
)
}
} else {
x$.metrics <-
purrr::map(
x$.metrics,
\(x) dplyr::mutate(x, .config = config)
\(x) set_config(x, config = config)
)
if (save_pred) {
x$.predictions <-
purrr::map(
x$.predictions,
\(x) dplyr::mutate(x, .config = config)
\(x) set_config(x, config = config)
)
}
}
Expand Down
23 changes: 23 additions & 0 deletions tests/testthat/test-sa-misc.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,26 @@ test_that("tune_sim_anneal with wrong type", {
error = TRUE
)
})

# ------------------------------------------------------------------------------

test_that("tune_sim_anneal loggining doesn't error with failed model", {
# no failed results:
res_1 <- purrr::map_dfr(
ames_iter_search$.metrics,
finetune:::set_config,
config = "beratna"
)
expect_true(all(res_1$.config == "beratna"))

has_failure <- tune:::vec_list_rowwise(ames_iter_search$.metrics[[1]])[1:3]
has_failure[2] <- list(NULL)
res_2 <- purrr::map(
has_failure,
finetune:::set_config,
config = "sasa ke?"
)
expect_null(res_2[[2]])
expect_equal(res_2[[1]]$.config, "sasa ke?")
expect_equal(res_2[[3]]$.config, "sasa ke?")
})