Return all-NaN from HPA* fallback when the goal cannot be reached#3638
Merged
Conversation
A failed refinement used to return the partially written path image, so an unreachable goal produced a finite cost trail that dead-ends mid-grid while every other search path returns all NaN for no-path. Return a fresh all-NaN surface instead.
brendancol
commented
Jul 3, 2026
brendancol
left a comment
Contributor
Author
There was a problem hiding this comment.
PR Review: Return all-NaN from HPA* fallback when the goal cannot be reached
Blockers (must fix before merge)
- none
Suggestions (should fix, not blocking)
- none
Nits (optional improvements)
-
xrspatial/pathfinding.py:520a refinement failure now discards segments that were already connected, so a caller gets no hint of how far the search got. That matches the bounded-search behavior codified intest_search_radius_too_small(all-NaN when the search bounds exclude the only route), and the partial trail was worse: it madenp.isfinite(result).any()a false reachability signal. If partial progress ever matters, a warning would be the way to surface it, not finite pixels. - The test drives
_hpa_star_searchdirectly rather than througha_star_searchwith a mocked_available_memory_bytesand a >1000-pixel manhattan distance. Direct invocation keeps the test fast and deterministic; the public-API route to this code path is already covered bytest_auto_radius_selection.
What looks good
- One-line semantic fix with the reasoning in a comment at the return site.
- The new test constructs the exact failure geometry (thin NaN wall that coarse blocks see as passable) and asserts zero finite pixels, which fails on the old code with 89.
- No behavior change for reachable goals: the escalation loop and stitching are untouched, and the existing
test_hpa_star_correctnessstill passes.
Checklist
- Algorithm matches reference/paper (no-path contract now uniform across search paths)
- All implemented backends produce consistent results (HPA* runs on the numpy path and cupy CPU-fallback; dask uses sparse A*, unaffected)
- NaN handling is correct
- Edge cases are covered by tests
- Dask chunk boundaries handled correctly (not touched)
- No premature materialization or unnecessary copies
- Benchmark exists or is not needed (failure-path fix)
- README feature matrix updated (n/a)
- Docstrings present and accurate (internal function; public docstring already describes HPA* only at a high level)
brendancol
commented
Jul 7, 2026
brendancol
left a comment
Contributor
Author
There was a problem hiding this comment.
PR Review: Return all-NaN from HPA* fallback when the goal cannot be reached
Re-review after the branch was updated with main (picks up the libjxl=0.11.* CI pin from #3639, which clears the earlier cog-validator/geotiff-corpus red). The merge was clean, no conflicts, and it did not touch pathfinding.py.
Blockers
None.
Suggestions
None.
Nits
None.
What looks good
- The fallback at
xrspatial/pathfinding.py:527now returnsnp.full((h, w), np.nan, dtype=np.float64), the same value and dtype as the existing no-coarse-path return at line 476 and thepath_imgallocation at line 492. The two "no path" exits are now identical, sonp.isfinite(result).any()reads reachability the same way across the plain, bounded, and HPA* searches. - Fallback only fires when the segment goal stays non-finite after the radius sweep (1, 2, 4, 8), i.e. the segment genuinely cannot be connected. A partial cost trail there is misleading, so dropping it is the right call.
- Backend scope checks out: HPA* is numpy-only (with the cupy CPU fallback); the dask paths go through sparse A* and never hit this branch. No cross-backend parity concern.
test_hpa_star_unreachable_goal_all_nanbuilds a real unreachable case: a full NaN wall at column 100 with a factor-16 coarsening, so the coarse blocks straddling the wall stay passable and the coarse route crosses while refinement cannot. Asserting no finite pixels pins the exact regression (89 finite pixels before).
Verification
PYTHONPATH=<worktree> python -m pytest xrspatial/tests/test_pathfinding.py -x -q→ 52 passed.- Pushed as
a2e43fd4e8de44ac467c4b0c5c7bf34865ac62b7.
Checklist
- Algorithm/contract matches the other search paths
- NaN handling correct (all-NaN no-path result)
- Edge case (unreachable goal) covered by a new test
- Dask paths unaffected (numpy-only branch)
- No premature materialization or extra copies
- Benchmark not needed (edge-case return fix)
- Docstrings: private helper, no public API change
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #3631
_hpa_star_searchnow returns a fresh all-NaN surface when a segment cannot be refined at the largest retry radius, instead of the partially written path image. An unreachable goal no longer produces a finite cost trail that dead-ends mid-grid, sonp.isfinite(result).any()is a reliable reachability check in the HPA* regime, same as in the plain and bounded searches.Backend coverage: HPA* runs on the numpy path (and the cupy CPU-fallback path); the dask backends use the sparse A* and are unaffected.
Test plan:
pytest xrspatial/tests/test_pathfinding.py(52 passed on a CUDA host)