Skip to content

Return all-NaN from HPA* fallback when the goal cannot be reached#3638

Open
brendancol wants to merge 1 commit into
mainfrom
issue-3631
Open

Return all-NaN from HPA* fallback when the goal cannot be reached#3638
brendancol wants to merge 1 commit into
mainfrom
issue-3631

Conversation

@brendancol

Copy link
Copy Markdown
Contributor

Closes #3631

  • _hpa_star_search now 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, so np.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:

  • New test: wall-split 200x200 grid where the coarse route crosses the wall but refinement cannot; asserts the output has no finite pixels (previously 89)
  • pytest xrspatial/tests/test_pathfinding.py (52 passed on a CUDA host)

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 brendancol left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:520 a 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 in test_search_radius_too_small (all-NaN when the search bounds exclude the only route), and the partial trail was worse: it made np.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_search directly rather than through a_star_search with a mocked _available_memory_bytes and a >1000-pixel manhattan distance. Direct invocation keeps the test fast and deterministic; the public-API route to this code path is already covered by test_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_correctness still 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)

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.

HPA* fallback in a_star_search returns a partial cost trail when no path exists

1 participant