Skip to content

paramSets: cheap raster key, no copy on a surface hit; clearer errors - #42

Merged
eliotmcintire merged 1 commit into
developmentfrom
keycost
Nov 15, 2026
Merged

eliotmcintire merged 1 commit into
developmentfrom
keycost

Conversation

@eliotmcintire

Copy link
Copy Markdown
Collaborator

A follow-up to the change that lets a spread prediction use parameter sets from a file: reusing a set's result now costs less than half the time on large maps, and two bad inputs now give clear errors.

Affects: speed of replicates that reuse a set's result (0.9 s to 0.35 s on a 20-million-cell map); two new error messages; no change to results.

Reuses: paramSetsForRep(), the mod$surface cache, surfaceOutputs from the previous PR; new: rasterSample() and rasterVersion() (nothing existing detects a changed raster without reading all of it).

Technical details
  • The surface key read all values of flammableRTM and rasterToMatchLargeELF every rep, and a hit unwrapped each stored raster (fireSense_spreadPredict.R, key in spreadPredictRun()). Now rasterVersion() gives a number that changes with a new raster object or a change at up to 1000 sampled cells (rasterSample()); mod$rasterStamp keeps the last object so its address cannot be reused. Stored surfaces are a terra::deepcopy made on a miss and handed out as they are on a hit, after checking that the stored raster still has its sampled values (a changed one is recomputed).
  • Known limit: an in-place terra::set.values() on a raster input at a cell outside the 1000 sampled cells is not seen; terra's [<- and values<- make a new object and are seen.
  • paramSetsForRep(): stops if studyAreaWithSpreadParams has the simulated ELF in more than one row, and if a file of ledger rows has no row for it (before: paramSetIndex(0, ...) error).
  • Timing (4000 x 5000 cells, 1000 covariate pixels, one job, repsPerSet 6; seconds per spades() call): base 4.71 first rep, then 1.05 0.93 0.86 0.89 0.88; branch 1.65 first rep, then 0.48 0.37 0.35 0.35 0.35. A profile of the branch hits shows the rest is SpaDES and gc, not the module.
  • Tests (test-paramSets.R): duplicate ELF ids stop; ledger-rows file without the ELF stops (and with it works); rasterVersion() same object same number, new object and in-place edit a new number; a changed flammableRTM recomputes a set's surface; the reuse marker test now plants its marker consistently. On base the new tests give 2 failures and 2 errors.
  • Full suite (convertToPackage() + test_local(), fireSenseUtils 0.2.3.9165): branch 350 pass, 0 fail, 0 skip; base 340 pass, 0 fail, 0 skip.
  • Version not bumped; NEWS bullet added.

🤖 Generated with Claude Code

https://claude.ai/code/session_014G18Mik3fH4z5M5CyMSUS6

…licate ELF ids and on a ledger-rows file without the ELF

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014G18Mik3fH4z5M5CyMSUS6
@eliotmcintire eliotmcintire added enhancement New feature or request backwards compatible Existing code and results keep working unchanged labels Nov 15, 2026
@eliotmcintire
eliotmcintire merged commit 8fcb313 into development Nov 15, 2026
9 checks passed
@eliotmcintire
eliotmcintire deleted the keycost branch November 15, 2026 07:34
eliotmcintire added a commit that referenced this pull request Nov 15, 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 enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant