Skip to content

fix: build the adjacency graph with planar geometry and release 0.1.4 - #11

Merged
ivargr merged 2 commits into
mainfrom
fix/planar-adjacency-graph
Oct 15, 2026
Merged

ivargr merged 2 commits into
mainfrom
fix/planar-adjacency-graph

Conversation

@ivargr

@ivargr ivargr commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Prediction failed on the Vietnam provinces dataset on the chap benchmarking server:

Error in wk_handle.wk_wkb(wkb, s2_geography_writer(oriented = oriented, :
  Loop 0 is not valid: Edge 95 crosses edge 97
Calls: build_graph ... s2_geog_from_wkb -> <Anonymous> -> wk_handle.wk_wkb

spdep::poly2nb in build_graph uses sf's spherical s2 engine by default. s2 rejects the Ho Chi Minh City polygon, although every one of the 63 polygons is valid in the plane (GEOS). The adjacency graph only needs shared borders, so build_graph now turns s2 off around poly2nb and restores the caller's setting afterwards. Nothing else changes; datasets that worked before get the same graph.

  • scripts/lib.R: sf::sf_use_s2(FALSE) before poly2nb, restored with on.exit.

  • tools/test_lib.R: checks that s2 rejects the fixture, that build_graph still finds the two provinces are neighbours, and that the s2 setting is restored.

  • tools/fixtures/s2_invalid_geo.json: Ho Chi Minh City and Binh Duong from the Vietnam boundaries (geoBoundaries, via dhis2/climate-health-data).

  • main.py: version 0.1.4, so the fix can be released and installed on its own. Draft PR feat: add an MLproject generated from main.py and bump the version to 0.1.5 #10 also bumps to 0.1.4 and will need 0.1.5 after this.

Test plan

  • tools/test_lib.R passes in the 0.1.3 image (ghcr.io/chap-models/chapkit_ghr_model:sha-dfb2e3f). The old build_graph fails on the fixture with the same s2 error.
  • Reproduced the server failure locally with the 0.1.3 image on the Vietnam dataset (63 provinces, 1998-01 to 2010-09, forecasting 2010-10 to 2010-12, with the server's monthly_climate options).
  • The same run with this branch's scripts/ mounted into that image trains and predicts: 189 rows x 1000 samples, all finite. 87% of the observed values fall inside the 10-90% interval; Ho Chi Minh City gets its six neighbouring provinces.

@ivargr
ivargr marked this pull request as ready for review October 15, 2026 11:19
@ivargr ivargr changed the title fix: build the adjacency graph with planar geometry so s2 does not reject valid boundaries fix: build the adjacency graph with planar geometry and release 0.1.4 Oct 15, 2026
@ivargr
ivargr merged commit 2480a15 into main Oct 15, 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.

1 participant