Skip to content

delaunay walk: JAX assertion gate for the early-exit locator (PyAutoArray #530) - #306

Merged
Jammy2211 merged 1 commit into
mainfrom
feature/delaunay-walk-early-exit
Sep 7, 2026
Merged

Jammy2211 merged 1 commit into
mainfrom
feature/delaunay-walk-early-exit

Conversation

@Jammy2211

Copy link
Copy Markdown
Collaborator

Summary

Adds the JAX-assertion gate for PyAutoArray's Delaunay point-locator rewrite
(PyAutoArray issue #530, library PR PyAutoLabs/PyAutoArray#531), which replaces
the fixed-trip-count chunked walk in pix_indexes_delaunay_walk_from with an
early-exit lax.while_loop and chunks only the nearest-vertex seed argmin.

The walk is the exact algorithm scipy.spatial.Delaunay.find_simplex uses, so
"close enough" is not the contract: the located simplex must be the one qhull
reports, and an outside-hull query must fall back to the same nearest vertex
scipy_delaunay assigns through its KDTree. This script asserts that, plus the
jit/vmap/grad round-trips the early-exit rewrite is most likely to break.

Scripts Changed

  • scripts/misc/jax_assertions/delaunay_walk.py — new. Checks, in order:
    • parity vs find_simplex + cKDTree on uniform and blob-ring synthetic
      meshes and on production-like 1,500-vertex Hilbert-ordered lensing meshes
      ray-traced through full mass models, for both the data grid and the 4N split
      points; only shared-edge ties are allowed, and a tie must still contain the
      query;
    • jax.jit == eager on a query count that is not a multiple of the
      1,024-wide seed chunk (Q=15974, 614 past the boundary) and on an odd short
      set (Q=1023) — the padding the chunked argmin applies must never leak into
      the result — plus the return_simplex_indexes shapes/dtypes;
    • jitted vmap == per-member results over a batch of traced query sets,
      since the while_loop runs to the slowest lane in a batch;
    • jax.grad of a barycentric-weight scalar w.r.t. the query coordinates
      runs at all (lax.while_loop has no reverse-mode rule, so the locator
      stop_gradient-wraps its float inputs) and matches central finite
      differences;
    • the warm per-call time of the jitted locator on the lensing geometry,
      printed for the record — nothing gates on it.
  • smoke_tests.txt — registers misc/jax_assertions/delaunay_walk.py beside the
    delaunay_nn.py / delaunay_nn_caps.py siblings, so the gate runs on the PR
    and weekly/integrate channels.

The script declares ENV: jax full_datasets: every check gates a JAX code path,
and parity is measured on the 1,500-vertex mesh against the 1,024-wide seed
chunk, so the SMALL_DATASETS cap must stay off or neither the chunk boundary nor
the walk's step distribution is ever exercised. DELAUNAY_WALK_MESH_POINTS /
DELAUNAY_WALK_MASS_MODELS shorten it for a local probe.

Upstream PR

Library-first merge gate. This script imports the rewritten locator and its
DELAUNAY_LOCATE_CHUNK / _jax_delaunay_tables internals, and fails against
released or main autoarray until #531 merges
. Merge #531 first, and hold this
PR until the PyAutoArray release that carries it (pending-release).

Test Plan

  • python scripts/misc/jax_assertions/delaunay_walk.py against the worktree
    autoarray carrying the #531 change (commit 6152bdf0): 17/17 PASS in
    12.8 s
    — parity exact-row fraction 1.000000 with 0 shared-edge ties on
    all 9 geometries; jit == eager at the chunk boundary and on odd Q;
    jit(vmap) == per-member on a (3, 4421, 3) batch; jax.grad matches central
    FD to worst rel 1.6e-09; warm median 0.044 s for N=1500, Q=10421.
  • Same script through the shared smoke runner
    (autohands/run_python.py … --list … --report-dir …, the exact entry point
    the PR gate and Heart's workspace validation use): PASS (12.4 s),
    exit 0.
  • black --check clean.
  • Full workspace smoke suite — deferred to CI (this PR adds one entry; the
    rest of the list is untouched).

Heart context. pyauto-heart readiness is YELLOW for
workspace validation not passing (… cloud#34099198772: … autolens_test scripts/imaging/delaunay.py …). Those failing legs are unrelated to the walk
rewrite and are already fixed on this repo's main (078e445, 4103234); no RED
reasons are outstanding.

Generated by the PyAutoLabs agent workflow.

🤖 Generated with Claude Code

https://claude.ai/code/session_01B5HT8dp7sWc9qDhZp6moGr

Adds scripts/misc/jax_assertions/delaunay_walk.py, the correctness gate for
PyAutoArray's `pix_indexes_delaunay_walk_from` early-exit `lax.while_loop`
rewrite (PyAutoArray #530/#531), and registers it in `smoke_tests.txt` beside
the `delaunay_nn.py` siblings.

The script asserts parity against `scipy.spatial.Delaunay.find_simplex` +
`cKDTree` on uniform, blob-ring and production-like 1,500-vertex lensing
geometries (data grid and 4N split points), that `jax.jit` equals eager across
the 1,024-wide seed-chunk boundary and on odd query counts, that a jitted
`vmap` equals the per-member results, and that `jax.grad` through the
barycentric weights runs and matches central finite differences. The warm
per-call locator time is printed for the record and gates nothing.

Requires the PyAutoArray change in #531; it fails against released/main
autoarray until that merges (library-first gate).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B5HT8dp7sWc9qDhZp6moGr
@Jammy2211 Jammy2211 added the pending-release PR queued for the next release build label Sep 7, 2026
@Jammy2211
Jammy2211 merged commit d818cfb into main Sep 7, 2026
3 checks passed
@Jammy2211
Jammy2211 deleted the feature/delaunay-walk-early-exit branch September 7, 2026 23:07
@Jammy2211 Jammy2211 removed the pending-release PR queued for the next release build label Oct 7, 2026
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