Skip to content
Open
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: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ URL:
http://clusters.predictiveecology.org,
https://github.com/PredictiveEcology/clusters
Date: 2026-10-16
Version: 0.0.96
Version: 0.0.97
Authors@R: c(
person("Eliot J B", "McIntire", email = "eliot.mcintire@nrcan-rncan.gc.ca",
role = c("aut", "cre"), comment=c(ORCID = "0000-0002-6914-8316")),
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# clusters (development version)

* Fits whose `control` went through `controlSet()` now get their own cache keys. `controlSet()` rebuilt `control` with `DEoptim.control()` and dropped `clusterSetup()`'s digest of the shipped data, so every such fit had the same key and loaded the first fit cached (MPB 2026-12-04: every training window of three study areas got one fit). It also calls `DEoptim::DEoptim.control()`, so DEoptim need not be attached.

* An objective's argument that is code, such as mpbRedTopSpread's `quotedSpread` (a `quote({...})`), now reaches the objective as is. `.DEoptimChunk()` and `.rescoreFn()` passed it through `do.call()` without `quote = TRUE`, so it was run in the main process before the objective was called (MPB 2026-12-04: "object 'massAttackRasStart' not found").

* New `requestedWorkers(cores, nCoresNeeded)`: the number of workers `clusterSetup()` asks the planner for (a number of `cores` is that many `"localhost"`; a host named more than once is its count; else `nCoresNeeded`; each host cut to `options(clusters.maxWorkersPerHost)` first). A caller that needs the population size before the cluster exists (fireSense_spreadFit's emulator and start population) calls it, so the rule is no longer copied. `clusterSetup()` calls it; nothing changes in what it builds.
Expand Down
6 changes: 5 additions & 1 deletion R/DEoptim.R
Original file line number Diff line number Diff line change
Expand Up @@ -674,8 +674,11 @@ DEoptimIterative <- function(fn, lower, upper, control, ...,
}

controlSet <- function(control, ...) {
## DEoptim.control() and modifyList2() build a new list and drop clusterSetup()'s digest of the
## shipped data; without it every fit through here had the same cache key (mpbRedTopSpread, 2026-12-04)
objsDigest <- shippedObjectsDigest(control)
if (length(names(control)) < 20)
control <- do.call("DEoptim.control", control)
control <- do.call(DEoptim::DEoptim.control, control)
missingElements <- ...names() %in% names(control)
if (any(missingElements)) {
control <- Require::modifyList2(control, list(...))
Expand All @@ -686,6 +689,7 @@ controlSet <- function(control, ...) {
# control$c <- .c
#
}
attr(control, "objsDigest") <- objsDigest
control

}
Expand Down
21 changes: 20 additions & 1 deletion tests/testthat/test-DEoptimShippedDataKey.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ upper <- c(a = 1, b = 1)
## objects for a local run -- the same way the workers see them.
fn <- function(par) sum((par - target)^2)

fitWith <- function(target, cachePath) {
fitWith <- function(target, cachePath, viaControlSet = FALSE) {
assign("target", target, envir = .GlobalEnv)
withr::defer(rm("target", envir = .GlobalEnv))
control <- clusters::clusterSetup(cores = NULL, objsNeeded = "target", envir = environment(), logPath = tempfile(),
itermax = 6, strategy = 2L, NP = 8L, trace = FALSE)
if (viaControlSet) control <- clusters:::controlSet(control) # as mpbRedTopSpread does
withr::local_options(reproducible.cachePath = cachePath, clusters.cacheDEoptimIterations = TRUE)
set.seed(1) # the same starting population for both fits, as two folds of one ELF have
DE <- suppressMessages(suppressWarnings(
Expand Down Expand Up @@ -53,3 +54,21 @@ test_that("two fits that differ only in the shipped data do not share cached gen
expect_equal(fitWith(c(0.2, 0.2), cp), best1)
expect_identical(entries(), n)
})

## 2026-12-04, mpbRedTopSpread: the module passes clusterSetup()'s control through controlSet(), which
## rebuilt it with DEoptim.control() and dropped the digest. Every training window of every study area
## then had the same key, and all of them loaded the first fit made.
test_that("controlSet() keeps the shipped-data digest", {
target <- c(0.2, 0.2)
c1 <- clusters::clusterSetup(cores = NULL, objsNeeded = "target", envir = environment(), logPath = tempfile(), trace = FALSE)
rm("target", envir = .GlobalEnv)
expect_identical(shippedObjectsDigest(clusters:::controlSet(c1)), shippedObjectsDigest(c1))
expect_identical(shippedObjectsDigest(clusters:::controlSet(c1, itermax = 3)), shippedObjectsDigest(c1))
})

test_that("fits through controlSet() that differ only in the shipped data do not share generations", {
cp <- withr::local_tempdir()
best1 <- fitWith(c(0.2, 0.2), cp, viaControlSet = TRUE)
best2 <- fitWith(c(0.8, 0.8), cp, viaControlSet = TRUE)
expect_true(all(abs(best2 - 0.8) < abs(best2 - 0.2)))
})
Loading