Skip to content

fix: fit rows in time order to avoid an INLA crash, and release 0.1.7 - #12

Merged
ivargr merged 1 commit into
mainfrom
fix/sort-rows-before-fit
Oct 16, 2026
Merged

ivargr merged 1 commit into
mainfrom
fix/sort-rows-before-fit

Conversation

@ivargr

@ivargr ivargr commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

Summary

With the s2 fix in 0.1.4, the model gets past the adjacency graph on the Vietnam benchmark dataset, but one backtest window (training to 2010-06, forecasting 2010-07 to 2010-09) then crashes inside INLA:

inla.mkl: idxval.c:905: GMRFLib_idxval_nsort_x_core: Assertion `0 == 1' failed.
The inla program failed and the maximum number of tries has been reached.

The crash is an INLA problem (25.10.19), triggered by the iid year effect and dependent on row order and thread count. disease_cases ~ 1 + f(year_id, model = "iid") alone crashes on those rows in the order predict.R builds them (by location, forecast rows appended), with 1 or 4 threads; the same rows sorted by year, shuffled, or fitted with 16 threads work. Investigation, reproduction script and data: https://dhis2.atlassian.net/browse/CLIM-1444

The rows are independent observations in the likelihood, so their order does not change the model. predict.R now puts them in time, then location order just before the fit, with the forecast flag carried along, so the forecast rows are still the ones sampled and written out.

This sidesteps the INLA bug rather than fixing it; a newer INLA or an upstream report is followed up in the Jira issue above.

Test plan

  • tools/test_lib.R passes.
  • All six Vietnam windows the benchmarking server uses (training ending 2010-04 to 2010-09, 3 months forecast each), with the server's monthly_climate options in the 0.1.4 image with this branch's scripts/ mounted: all six train and predict. Before, the 2010-06 window crashed. The output rows match the forecast input.
  • Forecasts compared with the unsorted code on the five windows that worked before: MAE against the observed cases and 10-90% coverage are practically unchanged (for example 104.2 vs 103.8 and 0.87 vs 0.87 on the first window). The medians differ by about 3.5%, against 2.8% between two runs of the unchanged code, so the difference is mostly sampling noise.
  • The example data (make test-local inputs) still trains and predicts.

@mortenoh
mortenoh force-pushed the fix/sort-rows-before-fit branch from 01b4194 to d1185ac Compare October 15, 2026 15:02
@mortenoh mortenoh changed the title fix: fit rows in time order to avoid an INLA crash, and release 0.1.5 fix: fit rows in time order to avoid an INLA crash, and release 0.1.7 Oct 15, 2026
@mortenoh

Copy link
Copy Markdown
Contributor

Rebased onto main (1a7f8e4), which now has #10 (MLproject, chapkit 2.4.0, 0.1.5) and #13 (scripts/ renamed to ghr/, 0.1.6). Still one commit, d1185ac.

  • The changes to scripts/lib.R and scripts/predict.R now sit in ghr/lib.R and ghr/predict.R; the tools/test_lib.R checks merged cleanly.
  • Version is now 0.1.7 (the title is updated), and MLproject is regenerated with chapkit mlproject export to match.
  • The description's file paths and the note about feat: add an MLproject generated from main.py and bump the version to 0.1.5 #10 needing 0.1.6 predate this; left as written.

After the rebase, all local targets pass: make lint (including chapkit mlproject export --check), test-unit (including the new row-order checks), test-local, test-contract, test-api and test-mlproject (33 rows x 100 samples through both main.py and chapkit mlproject run). The Vietnam backtest windows from the test plan were not re-run.

@ivargr
ivargr marked this pull request as ready for review October 16, 2026 07:20
@ivargr
ivargr merged commit 1748a64 into main Oct 16, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants