P2.5: SCFPotential backend-agnostic / jit-clean (jax/torch)#930
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## feat/backends #930 +/- ##
===============================================
Coverage 99.92% 99.92%
===============================================
Files 243 243
Lines 34651 34811 +160
Branches 719 714 -5
===============================================
+ Hits 34625 34785 +160
Misses 26 26 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
jobovy
added a commit
that referenced
this pull request
Jun 10, 2026
…anar sign fix #923, planar R2deriv fixes #899/#902/#912, orbit interp warning #924) Periodic main->feat/backends merge per the project plan, consuming the C/SCF work the backend migrations build on; lets #930 (SCF backend migration) drop its #921 cherry-pick on rebase. Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Migrate the SCF Hernquist-basis expansion to the namespace-swap pattern (get_namespace dispatch as in PowerSphericalPotentialwCutoff, #922): - _evaluate/_Rforce/_zforce/_phitorque, _dens, and the six analytic second derivatives all run under numpy/jax/torch; the radial helpers (_RToxi/_C/_dC/_d2C/_phiTilde/_dphiTilde/_d2phiTilde/_rhoTilde) and the per-point compute methods gain functional backend branches using the galpy.backend.special Gegenbauer + associated-Legendre router. - The numpy path keeps its legacy code verbatim (incl. the md5 force cache and the float()-keyed 2nd-derivative cache, which are trace-hostile and therefore numpy-only) and is verified bitwise-identical on a 195-array baseline spanning axi/non-axi/Hernquist cases, scalar/array inputs, all compute methods, the radial helpers (incl. r=0/inf), and the scf_compute_coeffs* integrals that share _C. - The numpy.roll + in-place CC[...]=0 idioms of _dC/_d2C become zero-row concatenations on the backend path; the r==0 / r==inf branches become xp.where with dead-branch guards so eager/traced AD is not NaN-poisoned. - SphericalHarmonicPotentialMixin (shared with MultipoleExpansionPotential, whose numpy tests still pass) gets the same treatment for the cylindrical force / second-derivative chain rule, and coords.cyl_to_spher dispatches arctan2 on the input namespace. - tests/test_backend_scf.py: value parity (scalar + array, rtol=1e-12) for Hernquist/axi/non-axi expansions over all eleven methods, grad-vs-FD in R/z/phi, the nine AD force/Hessian sign identities (rtol=1e-9, validating the hand-coded _dphiTilde/_d2phiTilde chain), jax.jit compatibility for forces and second derivatives, and centre/infinity guard parity. Cherry-picks the analytic-second-derivative commit (#921) from main, which feat/backends predates, as the base for the migrated Hessian path. Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
jobovy
added a commit
that referenced
this pull request
Jun 10, 2026
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
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.
Part of the P2.5 fan-out. Full namespace-swap of SCFPotential: radial Gegenbauer/Legendre helpers + forces + the analytic 2nd derivatives through
galpy.backend.special(gegenbauer + assoc_legendre); per-point Python caches bypassed for non-numpy namespaces (trace-hostile); in-placeCC[...]=0patterns rewritten functionally with numpy kept byte-identical.NOTE — includes a cherry-pick of #921 (
17f92302, analytic 2nd derivatives, already on main): feat/backends predates it. When feat/backends next merges main, the cherry-pick dedupes. Consequently the branch differs from base feat/backends exactly and only in the six 2nd-derivative methods (the user-approved #921 value change, ~1e-6 vs the old numerical mixin) — the migration itself is byte-identical on top of #921.Verification (adversarial): 522-key value grid — all non-2nd-deriv keys byte-identical; the 163 differing keys are exactly the #921 analytic-2nd-deriv change; backend tests pass.
🤖 Generated with Claude Code