Skip to content

P2.5: SCFPotential backend-agnostic / jit-clean (jax/torch)#930

Merged
jobovy merged 1 commit into
feat/backendsfrom
feat/P2.5-scf
Jun 10, 2026
Merged

P2.5: SCFPotential backend-agnostic / jit-clean (jax/torch)#930
jobovy merged 1 commit into
feat/backendsfrom
feat/P2.5-scf

Conversation

@jobovy

@jobovy jobovy commented Jun 9, 2026

Copy link
Copy Markdown
Owner

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-place CC[...]=0 patterns 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

@codecov

codecov Bot commented Jun 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.92%. Comparing base (3fbc16c) to head (7ee79cd).
⚠️ Report is 3 commits behind head on feat/backends.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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 jobovy merged commit dbf2ee4 into feat/backends Jun 10, 2026
119 of 130 checks passed
@jobovy jobovy deleted the feat/P2.5-scf branch June 10, 2026 13:10
jobovy added a commit that referenced this pull request Jun 10, 2026
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
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