Repository navigation
refactor: vendor bessel_kve into autoarray and drop tfp-nightly - #695
Merged
Merged
Conversation
The JAX Matern-kernel path (kv_xp) needed tensorflow-probability only for the modified-Bessel K_v. Port tfp's bessel_kve K-branch (Temme series, Steed continued fraction, forward recurrence, Olver asymptotics) to plain jax.numpy/lax in autoarray/inversion/regularization/bessel.py, keeping the Apache-2.0 header and tfp's custom JVP (gradient in z; none in v). kv_xp's JAX branch now uses the vendored kv; tfp-nightly is removed from the optional extras. Adds a library spot check vs scipy.special.kv and a finite-difference-certified Matern scale gradient. Refs #694 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016nhQ8MuV8FPuFqiY6gLYLT
… and analytic dK/dz Addresses independent-review notes on #694: kv_xp and MaternKernel docstrings now agree that nu must be treated as static (the order derivative of K_v is zero, as in tfp), the scipy spot check reaches the nu >= 50 Olver regime, and reverse-mode dK/dz is checked against -(K_{nu-1} + K_{nu+1}) / 2. Refs #694 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016nhQ8MuV8FPuFqiY6gLYLT
Collaborator
Author
|
Workspace PRs for Phase 2:
Generated by Claude Code |
This was referenced Nov 15, 2026
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.
Summary
Closes #694 (phase 1, library). The JAX Matérn-kernel path (
kv_xp) needed tensorflow-probability only for the modified-BesselK_v. This PR vendors tfp'sbessel_kveK-branch — Temme power series (z ≤ 2), Steed continued fraction (z > 2), forward recurrence, Olver asymptotics (ν ≥ 50) — as plainjax.numpy/laxinautoarray/inversion/regularization/bessel.py(Apache-2.0 header + attribution preserved, list of modifications in the header), rewireskv_xp's JAX branch to it, and removestfp-nightly==0.26.0.dev20260713from theoptionalextras. This removes the whole tfp/JAX version-incompatibility class (PyAutoArray #385) and a heavy, prune-prone nightly dependency.Not ported (only feed
I_v, unused bykve):bessel_ive,bessel_iv_ratio,_bessel_ive_shared,_compute_general_continued_fraction, the log-space variants and the negative-orderivecorrections.API Changes
No public API change.
kv_xp(v, z, xp)keeps its signature and NumPy behaviour (scipy.special.kv); the JAX branch no longer raisesImportErrorasking for tfp. New internal moduleautoarray.inversion.regularization.bessel(bessel_kve,kv).tfp-nightlyis dropped fromautoarray[optional].See full details below.
Decision flagged (supervised
--auto)K_vin its order; the vendoredcustom_jvpkeeps that (behaviour-preserving refactor). Independent review measured thatgrad(matern_kernel)w.r.t. ν is therefore wrong, not zero (other ν terms still contribute: −0.803 vs FD +0.059 at r=0.7, l=1.3, ν=1.7). Docstrings now say so and that ν must be treated as static. A correct order-derivative is a candidate follow-up if ν is ever sampled with gradient-based samplers.galaxy-duplicate-pytree-registration(fix: duplicate Galaxy pytree registration after a JAX Fitness #693) on the human's explicit approval; file sets are disjoint.Test Plan
pytest test_autoarray— 2409 passed, 1 skipped (before the follow-up commit);test_autoarray/inversion/regularizations— 135 passed at head.kv_xpJAX vsscipy.special.kv(rtol 1e-10) either side of z=2, near half-integers and in the ν≥50 Olver regime; reverse-mode dK/dz vs-(K_{ν-1}+K_{ν+1})/2; Matérn covariancescalegradient through the Cholesky vs central FD.scipy.special.kve9e-14 over ν ∈ [0.5, 5.5], 1.5e-13 overall (ν up to 120, z 1e-6…500); review sweep 461 orders × 226 z: 2.3e-13; second derivatives in z 2.3e-13; no non-finite output where scipy is finite.autogalaxy_workspace_test/scripts/misc/jax_assertions/matern_regularization.pypasses withJAX_ENABLE_X64=True(the smoke profile).bessel_kve_parity.pygrid + grad-vs-FD script; retitle tfp prose inmatern_regularization.py,autolens_workspace_testjax_grad/regularization.py,knn.py, andsmoke_install.shcomments.Validation checklist (--auto run — plan was not pre-approved)
Full API Changes (for automation & release notes)
Removed
tfp-nightlyfromautoarray[optional];kv_xp's JAX-pathImportErrorfor missing tfp.Added
autoarray.inversion.regularization.bessel.bessel_kve(v, z)— exponentially scaledK_v(z)·e^{|z|}, pure JAX, differentiable inz.autoarray.inversion.regularization.bessel.kv(v, z)— unscaledK_v(z).Migration
tfp-nightlyonly for autoarray may uninstall it.Generated by the PyAutoLabs agent workflow.
Generated by Claude Code