Return all-NaN from HPA* fallback when the goal cannot be reached#3638
Open
brendancol wants to merge 1 commit into
Open
Return all-NaN from HPA* fallback when the goal cannot be reached#3638brendancol wants to merge 1 commit into
brendancol wants to merge 1 commit into
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)
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)