Conversation
…rids GraphWeatherForecaster._create_grid_mapping divided by (max(unique_lats) - min(unique_lats)) and the same for longitudes, with no guard for the degenerate case where all lat_lons share one latitude or one longitude. That range hits zero and raises ZeroDivisionError, so any 1D grid crashes right in __init__. Fall back to row/col 0 when the axis has no spread to normalize against. Normal 2D grids are unaffected.
|
Same failing checks as #230, so I compared notes. pytest (macos + ubuntu): both crash during collection before any test body runs - pre-commit.ci: the Verified the fix itself works: extracted Neither failing check here is caused by this branch - it's the same upstream CI breakage as #230. |
|
Filed #232 for the segfault so it's tracked separately from this PR. |
|
Checked this before pushing further changes. Both pytest jobs die during collection, before any test in this diff runs: Same crash on macOS and Ubuntu, and it happens just importing Confirmed against main: identical segfault, same frame, on the latest push to main (run https://github.com/openclimatefix/graph_weather/actions/runs/28750434951). Looks like a torch_scatter/torch/pyg_lib ABI mismatch in the pixi-resolved CPU environment, not something introduced here. pre-commit.ci is the same situation. I ran Flagging so this isn't read as a problem with the fix itself — will rebase once the pytest/torch_scatter breakage is sorted upstream. |
|
The failures here are inherited from main: pytest has segfaulted on every main run since early June (#232, same |
GraphWeatherForecaster.__init__calls_create_grid_mappingunconditionally, which divides bymax(unique_lats) - min(unique_lats)andmax(unique_lons) - min(unique_lons)with no guard for the degenerate case where every node shares one latitude or one longitude. When that happens the range is zero and it raisesZeroDivisionErrorbefore the model even finishes constructing.Repro:
Same thing happens with a single unique longitude, or a single point (both axes degenerate at once).
Fix: when an axis has no spread to normalize against, every node on that axis maps to row/col 0 instead of dividing by zero. Normal 2D grids go through the same math as before, so nothing changes for the common case.
Added two tests,
test_forecaster_single_latandtest_forecaster_single_lon, covering both degenerate axes and confirming the model still runs a forward pass without producing NaNs.I don't have a GPU/full env set up locally to run the whole suite, so I verified the fixed arithmetic in isolation against a range of inputs (single-lat, single-lon, single-point, and a regular grid checked against the original formula for equivalence) and ran ruff/black against the touched files, both clean.