Skip to content

Build ignition and spread covariates once per year (hindcast reps) - #44

Merged
eliotmcintire merged 3 commits into
developmentfrom
fastHc-stamp
Nov 15, 2026
Merged

eliotmcintire merged 3 commits into
developmentfrom
fastHc-stamp

Conversation

@eliotmcintire

@eliotmcintire eliotmcintire commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator

A hindcast year runs 20 repetitions, and each one rebuilt the same land and climate tables, about 12 seconds each. They are now built once per year and reused while their inputs stay the same.

Affects: hindcast speed (about 4 minutes per hindcast year); the tables are unchanged.

Reuses: vegetationStamp() (the stamp of fuelClassTablesThisYear(), lifted out so both use it), useOwnELFRows(), prepare_IgnitionAndEscapePredict(), prepare_SpreadPredict(), rlang::hash(); new: covariatesBuilt() and inputDigest() (nothing existing tells whether the covariates match their inputs).

Technical details

Defect: the prepIgAndEscPredictData and prepSpreadPredictData events (fireSense_dataPrepPredict.R:327-337) call the builders at every fireTimeStep, although nothing they read changes inside a year. A second defect, found while testing a land-cover change: ELFfuelSets() kept mod$ELFrstLCC and mod$ELFlandcoverDTs from the first call for the whole run, so a changed rstLCC_RTM or flammableRTM was never seen.

Fix: covariatesBuilt(sim, what) skips the build when a stamp of the inputs and the output are unchanged. The stamp is rlang::hash() digests (not sums, which miss swapped pixels) of the year, cohortData, pixelGroupMap, flammableRTM, the climate layers used, time since disturbance, landcoverDT, rstLCC_RTM (and lightningDays for ignition), plus the fitted rows after useOwnELFRows(): .ELFind, polygon IDs and the column names of each params (from which the fuel-class roles are read, and which spreadFit rewrites). ELFfuelSets() now makes the per-ELF land cover again when the digests of rstLCC_RTM or flammableRTM change. rlang is added to reqdPkgs. The inputs both events read are hashed once per step (sharedInputStamp(), kept in mod by time(sim)): hashing five 20M-cell rasters and a 20M-row table twice with digest took 6.4 s, once with rlang::hash() 2.0 s. The year column of the tables carries the first step's time (nothing reads it).

Tests (tests/testthat/test-covariatesOncePerYear.R): four steps of one year build once and equal one step (ignition alone, spread alone, and both together as in a hindcast); a cohortData change rebuilds once; two swapped pixels rebuild; a land-cover change rebuilds with several ELFs (fails without the ELFfuelSets() fix); a change of .ELFind rebuilds; a new year rebuilds. Full suite: branch 339 passed, 0 failed, 0 skipped.

🤖 Generated with Claude Code

https://claude.ai/code/session_014G18Mik3fH4z5M5CyMSUS6

…same-year step

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 and others added 2 commits November 15, 2026 00:17
… when it changes

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014G18Mik3fH4z5M5CyMSUS6
@eliotmcintire
eliotmcintire merged commit 73ac6bd into development Nov 15, 2026
9 checks passed
@eliotmcintire
eliotmcintire deleted the fastHc-stamp branch November 15, 2026 07:58
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