Skip to content

spreadFitNP: a single number of cores is the population size - #137

Merged
eliotmcintire merged 2 commits into
developmentfrom
npFromCores
Nov 18, 2026
Merged

eliotmcintire merged 2 commits into
developmentfrom
npFromCores

Conversation

@eliotmcintire

@eliotmcintire eliotmcintire commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

A spread fit with few parameters, run with a fixed number of workers, stopped at its start. Its starting population had fewer members than there were workers.

Affects: fits with cores set to a number above 1 (e.g. cores = 40L) or to a host name repeated (e.g. rep("mega", 40)) now start; distinct host names, cores = 1L and fits whose start population already had enough rows are unchanged.

Depends-on: PredictiveEcology/clusters#72

Technical details

Defect: R/fitSpread.R spreadFitNP() (was lines 172-176) gave nCoresNeeded, else deoptimPopulationSize(length(lower)). clusters::clusterSetup() builds cores workers for a number above 1 or a repeated host, and .clusterNP() sets NP to them. With 3 parameters and cores = 40L the emulator and the start population had 30 rows, and .fitInitialpopToNP() stopped: "initialpop has 30 rows but the population (the number of workers) is 40" (GPSC 2026-11-17, null arm, ELFs 14.3, 11.3). The first version of this PR restated the numeric rule and missed repeated hosts (rep("mega", 40): 40 workers, spreadFitNP() gave 30).

Fix: spreadFitNP() returns clusters::requestedWorkers(P(sim)$cores, nCoresNeeded), with nCoresNeeded the parameter or deoptimPopulationSize(length(lower)). That function is the rule clusterSetup() uses (clusters PR #72), including the maxWorkersPerHost cap. NULL or NA cores (no cluster) gives nCoresNeeded as before. fitSpread()'s start-population size is max(10 * length(lower), spreadFitNP(sim)): clusters uses the first NP rows, so only "at least NP" matters, and the max keeps a fit's initialpop, and so its cache key, unchanged for current ELFs (10-12 parameters, 120 rows). reqdPkgs now has clusters@development (>= 0.0.95), the version after #72 is merged and bumped. fitSpread.R:122 still passes P(sim)$nCoresNeeded (not NP) to runDEoptim(); left as is because it is part of the fit's cache key, and clusters ignores it when cores fixes the count.

Reuses: clusters::requestedWorkers(), fireSenseUtils::deoptimPopulationSize(), startPopulation(), spreadFitNP() (the one source of NP for the fit, the emulator and profileLedgerFit()); new: none.

Tests: tests/testthat/test-nCoresNeeded.R has the existing cases plus cores = rep("hostA", 40) with 3 parameters (emulator NP 40, 40 rows, start population of at least 40 rows), spreadFitNP() for repeated hosts, NULL and NA cores. convertToPackage() + test_local() on a copy (BLAS/OMP threads 1, scratch library with clusters #72 built as 0.0.95 first, fireSenseUtils 0.2.3.9177 from a read-only run library): previous code with the new tests 4 failed, the new tests (the old code's other tests pass); branch 0 failed, 0 skipped, 1310 passed.

🤖 Generated with Claude Code

https://claude.ai/code/session_014G18Mik3fH4z5M5CyMSUS6

clusterSetup() builds `cores` workers for a numeric cores above 1 and sets NP to them, but
spreadFitNP() gave nCoresNeeded or the default, so with 3 parameters and cores = 40L the emulator
and the start population had 30 rows and the fit stopped at its start. fitSpread() now takes its
start-population rows from spreadFitNP() (at least NP, still at least 10 per parameter).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014G18Mik3fH4z5M5CyMSUS6
@eliotmcintire eliotmcintire added bug Something isn't working backwards compatible Existing code and results keep working unchanged labels Nov 18, 2026
@eliotmcintire
eliotmcintire merged commit ba2d229 into development Nov 18, 2026
9 of 10 checks passed
@eliotmcintire
eliotmcintire deleted the npFromCores branch November 18, 2026 16:54
eliotmcintire added a commit that referenced this pull request Nov 18, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014G18Mik3fH4z5M5CyMSUS6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backwards compatible Existing code and results keep working unchanged bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant