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: 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.95
Version: 0.0.96
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)

* 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.

* Inside a Slurm job (`.slurmAllocation()` non-NULL) the host headroom is not applied: no `options(clusters.memoryHeadroom)`, no `options(clusters.keepFreeCores)` and none of `freeCores()`'s `fraction` (all the job's CPUs are free, whether or not it is the whole node). A job whose memory limit cannot be read keeps the headroom, since its memory is then the node's. The job owns its allocation, so the headroom only wasted it (GPSC 2026-11-14: a 64-CPU, 454G whole-node job with 437 GB free capped 10 GB workers at 39, and a 40-worker fit waited over an hour). `.limitToJob()` flags the probe (`in_slurm_job`, not a ledger column), which `.fitCapacity()` reads, so `reserveCapacity()` follows too. Outside Slurm nothing changes.
Expand Down
6 changes: 4 additions & 2 deletions R/DEoptim.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@
if (!is.null(seed)) assign(".Random.seed", seed, envir = globalenv())
invisible(.deoptimRecordTakeAll(cl)) # nothing left over from an interrupted chunk
if (!is.null(cl)) control$cluster <- cl
## quote = TRUE: an argument that is code (e.g. a quote({...})) reaches fn as is, not run here
out <- do.call(DEoptim::DEoptim,
c(list(fn = memoFn, lower = lower, upper = upper, control = control), dotsList))
c(list(fn = memoFn, lower = lower, upper = upper, control = control), dotsList),
quote = TRUE)
list(out = out, recs = .deoptimRecordTakeAll(cl))
}
ran <- .runWithRebuild(control$cluster, attempt)
Expand Down Expand Up @@ -185,7 +187,7 @@
## .memoObjFun is, because it is sent to the workers.
.rescoreFn <- function(fn, args, parNames) {
force(fn); force(args); force(parNames)
function(par) do.call(fn, c(list(stats::setNames(par, parNames)), args))
function(par) do.call(fn, c(list(stats::setNames(par, parNames)), args), quote = TRUE)
}
.rescorePopulation <- function(fn, pop, args, parNames, cl) {
## apply() and parApply() on a matrix with no rows call `f` ONCE, in this process, on a vector of
Expand Down
27 changes: 27 additions & 0 deletions tests/testthat/test-DEoptimLanguageArgs.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
## An objective's arguments can be code, e.g. mpbRedTopSpread's `quotedSpread`, a quote({...}) that
## the objective evaluates in its own frame. The chunk and the re-scoring must pass it as is, not run it.
##
## MPB, 2026-12-04: .DEoptimChunk's do.call(DEoptim, c(..., dotsList)) put the quoted spread into the
## call as code, so DEoptim ran it in the main process: "object 'massAttackRasStart' not found".

skip_if_not_installed("DEoptim")

objFn <- function(par, quotedSpread) {
stopifnot(is.language(quotedSpread))
sum((par - 0.3)^2)
}
code <- quote({ stop("the quoted argument was evaluated") })

test_that(".DEoptimChunk() passes a language argument to the objective unevaluated", {
out <- clusters:::.DEoptimChunk(
objFn, lower = c(a = 0, b = 0), upper = c(a = 1, b = 1),
control = DEoptim::DEoptim.control(NP = 20L, itermax = 2L, trace = FALSE),
known = list(keys = character(0), vals = numeric(0)),
dotsList = list(quotedSpread = code))
expect_true(is.finite(out$optim$bestval))
})

test_that(".rescoreFn() passes a language argument to the objective unevaluated", {
f <- clusters:::.rescoreFn(objFn, args = list(quotedSpread = code), parNames = c("a", "b"))
expect_equal(f(c(0.3, 0.3)), 0)
})
Loading