Multi-backend (JAX / PyTorch / array-API) support [integration branch]#892
Draft
jobovy wants to merge 18 commits into
Draft
Multi-backend (JAX / PyTorch / array-API) support [integration branch]#892jobovy wants to merge 18 commits into
jobovy wants to merge 18 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #892 +/- ##
========================================
Coverage 99.92% 99.92%
========================================
Files 225 243 +18
Lines 34224 35161 +937
Branches 709 709
========================================
+ Hits 34197 35136 +939
+ Misses 27 25 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This was referenced Jun 4, 2026
jobovy
added a commit
that referenced
this pull request
Jun 4, 2026
…e test, config docs - setup.py: remove the 'backend' extra (just array-api-compat — useless on its own); keep jax/torch extras (each pulls in array-api-compat). - _optional_deps.py: correct the array-api-compat comment — there is no vendored fallback (removed during coverage cleanup); it is required for the non-numpy backends (pulled in by the jax/torch extras) and not needed for numpy-only use. - Rename tests/test_backend_pilot.py -> tests/test_backend.py; fix the build.yml glob to tests/test_backend*.py so it still matches (old _*.py glob would have missed it). - Document the [backend] config section (default=numpy) in installation.rst + galpyrc. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add galpy.backend: a data-first array-namespace resolver (get_namespace; precedence explicit xp= > forced default > namespace of the array args > context/global default > numpy), a use()/set_default_backend() control with a force mode, and a [backend] config section. numpy/Python inputs resolve to plain numpy so the numpy path is byte-identical; jax/torch arrays select jax.numpy / array-api-compat torch. Migrate PlummerPotential and IsochronePotential to the private-layer dispatch convention (xp = get_namespace(R, z); numpy.<fn> -> xp.<fn>; numpy.pi -> math.pi) as the reference for the per-family migrations. Testing: tests/test_backend.py (resolver + reference potentials), tests/test_backend_ conventions.py (AST guard banning bare numpy.* in migrated compute methods), a --backend pytest option + autouse fixture to re-run under a forced backend, and a build.yml job running tests/test_backend*.py under jax+torch. jax/torch extras in setup.py; config docs for [backend]. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…unit parser (#903) Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
…ties (#913) Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
…#895) Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
…-swap (#896) Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
…906) Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
… router fixes) (#922) Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
…re) (#928) Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
…e evaluation (#929) Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
…on layer (#932) 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.
Long-lived integration branch for making all of galpy backend-agnostic and differentiable (numpy/scipy, JAX, PyTorch, array-API). This PR establishes the integration branch: the parallel potential-migration series and the autodiff / action-angle / df work all target
feat/backends, are reviewed individually as PRs into it, and the whole branch is merged tomainat the end (rebased onmainafter the variational feature branch #891 merges, since differentiable C orbit integration needs its state-transition matrix).Draft: integration branch, not for merge until the full stack lands.
Foundation (in this PR)
galpy.backendpackage: a data-first array-namespace resolver (get_namespace: explicitxp=> forced default > array namespace > context/global > numpy),use()context manager,set_default_backend(). numpy/Python inputs resolve to plain numpy (byte-identical path); jax/torch selectjax.numpy/ array-api-compat torch. Pilot-migratesPlummerPotential+IsochronePotentialto private-layer dispatch. 70 new tests green on numpy/jax/torch (parity, grad-vs-FD, thed(Φ)/dR == −Rforceidentity, jit/vmap, dtype, decorator pass-through, precedence).[backend]section, a force mode (use(..., force=True)) so a whole run can be pinned to a backend, a--backend {numpy|jax|torch}pytest option + autouse fixture (numpy = no-op), and an AST convention guard banning barenumpy.*in migrated compute methods. Verified--backend jaxre-runstest_energy_jacobi_conservation(Plummer/Isochrone) green.Series targeting this branch
Design:
galpy_backend_autodiff_discussion.md; project log in thegalpy-jaxrepo.🤖 Generated with Claude Code