Skip to content

P2.2 Analytic disk potentials: backend-agnostic namespace-swap#894

Merged
jobovy merged 2 commits into
feat/backendsfrom
feat/P2.2-disk
Jun 6, 2026
Merged

P2.2 Analytic disk potentials: backend-agnostic namespace-swap#894
jobovy merged 2 commits into
feat/backendsfrom
feat/P2.2-disk

Conversation

@jobovy

@jobovy jobovy commented Jun 4, 2026

Copy link
Copy Markdown
Owner

Part of the P2.x potential namespace-swap series (→ #892).

Migrated: MiyamotoNagai, KuzminDisk, FlattenedPower, IsothermalDisk, KGPotential, RazorThinExponentialDisk (_surfdens). MN3ExponentialDisk is backend-agnostic transitively (delegates to MN).
Deferred: KuzminKutuzovStaeckel (coords transform — out of family scope), RingPotential (ellipk/ellipe), RazorThin forces (Bessel), DoubleExponentialDisk (scipy).
Hazards fixed: MN isinstance(R,float) a==0 fast-path gated on xp is numpy (numpy byte-identical; tracers always take the general autodiff-safe formula); numpy.fabsxp.abs (torch); numpy.pimath.pi.
Tests: tests/test_backend_disk.py — 138 passed (numpy/jax/torch parity + grad-vs-FD). Numpy path byte-identical.

🤖 Generated with Claude Code

@codecov

codecov Bot commented Jun 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.92%. Comparing base (141ebfe) to head (ac12174).
⚠️ Report is 1 commits behind head on feat/backends.

Additional details and impacted files
@@               Coverage Diff               @@
##           feat/backends     #894    +/-   ##
===============================================
  Coverage          99.92%   99.92%            
===============================================
  Files                228      228            
  Lines              34213    34405   +192     
  Branches             712      708     -4     
===============================================
+ Hits               34186    34379   +193     
+ Misses                27       26     -1     

☔ 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 jobovy marked this pull request as ready for review June 6, 2026 01:08
Complete the backend-agnostic migration of the analytic disk family so the
entire files (not just the main compute methods) are free of numpy. in the
compute path:

- KuzminDiskPotential._mass: numpy.sqrt -> xp.sqrt; drop unused numpy import.
- RazorThinExponentialDiskPotential._mass: numpy.pi/numpy.exp -> math.pi/xp.exp.
  _z2deriv: numpy.infty (deprecated) -> math.inf. Bessel/quadrature methods
  (_evaluate, _Rforce, _zforce, _R2deriv) remain scipy.special-blocked
  (i0/i1/k0/k1/kn/iv) and are left as-is.
- MiyamotoNagaiPotential: replace the numpy-only scalar fast-paths
  (`xp is numpy and isinstance(R, float) and sqrtbz == asqrtbz`) in _zforce,
  _dens, _z2deriv, _Rzderiv with a backend-agnostic config branch on
  `self._a == 0.0`. This is the a==0 simplification; it equals the general
  formula to ULP for b>0 and avoids the general formula's 0/0
  (asqrtbz/sqrtbz) at the a==0, b==0, z==0 singular point under all backends
  (previously NaN for arrays, finite only for numpy scalars).

Leftover numpy. in these files is config-time-only (leggauss nodes, astropy
unit parsing, scalar setup constants) or genuinely scipy.special.

Tests (tests/test_backend_disk.py): add numpy/jax/torch parity + grad-vs-FD
for the migrated _mass methods, z==0 kink parity for Kuzmin
_zforce/_Rzderiv/_z2deriv, MiyamotoNagai a==0 branch parity, and finite-value
parity at the MiyamotoNagai a==0,b==0,z==0 singular point. Full module: 181
passed (numpy+jax+torch); numpy potential sanity (forceAsDeriv, 2ndDeriv,
mass_axi, mass_axi_negz, poisson_surfdens) all pass with the C ext built.

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
@jobovy jobovy merged commit 7aefed3 into feat/backends Jun 6, 2026
108 checks passed
@jobovy jobovy deleted the feat/P2.2-disk branch June 6, 2026 20:20
jobovy added a commit that referenced this pull request Jun 10, 2026
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
jobovy added a commit that referenced this pull request Jun 12, 2026
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
jobovy added a commit that referenced this pull request Jun 13, 2026
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
jobovy added a commit that referenced this pull request Jun 15, 2026
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
jobovy added a commit that referenced this pull request Jun 17, 2026
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
jobovy added a commit that referenced this pull request Jun 19, 2026
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
jobovy added a commit that referenced this pull request Jun 19, 2026
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
jobovy added a commit that referenced this pull request Jun 25, 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