galpy with differentiable, accelerated backends: galactic dynamics in jax and PyTorch
summary
The gist
We describe an extension of galpy, a Python library for galactic dynamics, that integrates JAX and PyTorch as computational backends alongside its existing NumPy and C implementation.
In short
This extension of galpy integrates JAX and PyTorch as computational backends alongside NumPy and C for galactic dynamics simulations. It allows gravitational potentials, orbit integrations, and distribution functions to run on GPUs while enabling differentiation with respect to inputs and parameters. The design prioritizes backward compatibility, ensuring NumPy paths yield identical results.
Key concepts
- Backend Selection
- The system automatically chooses the computational backend (NumPy, JAX, or PyTorch) based on the data type of the input array. This allows calculations to run on GPUs and enables differentiation from forces to sampled distribution functions.
- Differentiable Orbit Integration
- Orbit integration can occur either inside the chosen backend's ODE solver (like JAX's diffrax) or via galpy's compiled C integrators. This provides flexibility, allowing users to choose between automatic differentiation and high-speed C methods for integration.
- Gradient-Based Fitting
- The framework allows computing derivatives for all core functionalities, including potentials and DFs. This enables gradient-based optimization of dynamical models with many parameters at a cost comparable to the likelihood calculation itself, offering significant speedups on GPUs.
Terminology used across episodes
This episode discusses
- galpy with differentiable, accelerated backends: galactic dynamics in jax and PyTorch · Paper Radio
- A differentiable forward model for weakly perturbed stellar streams: substructure forecasts from density and kinematics spectra
- Automatic differentiation in machine learning: a survey
- Neural Ordinary Differential Equations · Paper Radio
- Euclid Quick Data Release (Q1): The geometry of dark matter halos from extragalactic streams · Paper Radio
- The No-U-Turn Sampler: Adaptively Setting Path Lengths in Hamiltonian Monte Carlo
- On Neural Differential Equations
- Equinox: neural networks in JAX via callable PyTrees and filtered transformations
- torchode: A Parallel ODE Solver for PyTorch
- PyTorch: An Imperative Style, High-Performance Deep Learning Library
- When Streams Curve Away: a Test of Dark Matter from Extragalactic Stellar Stream Populations · Paper Radio
- Differentiable N-body code for Galactic Dynamics -- Odisseo
- Potamides: Mapping Dark Matter Halo Shapes from Stellar Stream Tracks in the Local Universe
The paper
galpy with differentiable, accelerated backends: galactic dynamics in jax and PyTorch · Read on arXiv
Jo Bovy, David A. Dunlap
University of Toronto
Transcript
Introduction to the show: ident: Astrophysics. The day in astrophysics: observations, models and what the data forces.
Vera: We're looking at the paper: "galpy with differentiable, accelerated backends".
Jocelyn: Here's the gist of the paper. We describe an extension of galpy, a Python library for galactic dynamics, that integrates JAX and PyTorch as computational backends alongside its existing NumPy and C implementation.
Vera: This extension allows galpy's gravitational potentials, orbit integration routines, action–angle transformations and their inverses, and distribution functions (DFs), including those for tidal streams, to run on GPUs.
Jocelyn: Furthermore, these operations can be compiled as part of a user's program and differentiated with respect to their inputs and parameters.
Vera: The design philosophy prioritizes maintaining backward compatibility: the NumPy path produces results byte-for-byte identical to the previous version, with only a few approved exceptions, and the user-facing interface remains unchanged.
Title and authors: Vera: So we're looking at a paper called "galpy with differentiable, accelerated backends: galactic dynamics in jax and PyTorch". It’s about taking this existing Python library for galactic dynamics, galpy, and adding JAX and PyTorch as computational backends alongside the NumPy and C versions.
Jocelyn: Basically, the big idea is to let you run all of galpy's core stuff—like gravitational potentials, orbit integrations, action angle transformations—on a GPU using either JAX or PyTorch. And it lets you differentiate those operations with respect to things like the force at a point or the samples coming from a distribution function.
Subrahmanyan: It sounds like they're trying to give people who are doing complex modeling, especially those dealing with tidal streams or galactic bars, a way to do gradient-based fitting on these models. That’s important because it lets you optimize parameters directly from your data without having to rely on slow traditional fitting routines.
Vera: The paper describes a design philosophy focused on keeping things stable for existing users. They say the NumPy path produces results that are byte-for-byte identical to the previous version, with only a few approved exceptions, and the user interface stays exactly as it is.
Jocelyn: And they have this rule about backend selection being driven by what kind of array type you pass in—if you give it a JAX array or a PyTorch tensor, that framework handles the calculation and returns an output of the same kind. That’s supposed to let you compute things on GPUs and get those gradients.
Subrahmanyan: That backend selection based on data type sounds smart for portability, but the real power here seems to be that you can compile this code as part of your own program and differentiate it from any input or parameter, which means you can do gradient-based inference or optimization on these dynamical models.
Vera: It really lets you compute derivatives with respect to things like the potential itself, the distribution function, and even the orbits of objects. That should speed up model fitting significantly because computing those derivatives at a cost comparable to getting the likelihood is a big deal.
Jocelyn: And they handle orbit integration in three ways: using a solver built into the backend like JAX’s diffrax, using galpy’s existing compiled C integrators, or extending the variational equations to include those C integrators. They note that running ODE solvers inside the backend can have a limitation because it might not have a batching rule suitable for PyTorch unless you use something like torchode.
Subrahmanyan: The speedup they claim is one to five orders of magnitude faster than on a single CPU core when you're dealing with large batches, which is huge if you are trying to process millions of stars or simulating large volumes of space. But we have to remember the trade-off between that automatic differentiation path and using those compiled C integrators, because the C path can be much faster for small numbers of points.
Vera: They also made distribution functions differentiable for every model on these backends, and sampling becomes differentiable whenever it involves an inverse transformation, which is useful for deriving derivatives with respect to parameters in things like velocity dispersion models.
Jocelyn: For tidal stream models specifically—like Bovy's action-angle model or particle-spray models—they say the track computation is a pure function of the progenitor’s orbit and the potential that you can vectorize over segments of that track, and it remains differentiable from end to end with respect to a parameter in the potential.
Subrahmanyan: That differentiability for stream models means you can find how changing a parameter in your potential affects the stream construction directly, which is very powerful for understanding structure formation around galaxies. But they also flagged some limitations—for instance, the many-position velocity sampler of the quasiisothermal disk distribution function has exceptions where sampling isn't differentiable.
Vera: So to wrap up this paper on "galpy with differentiable, accelerated backends: galactic dynamics in jax and PyTorch," it’s essentially about making galpy run on GPUs via JAX or PyTorch while keeping the existing NumPy interface identical.
Jocelyn: The main implication is that you can now perform gradient-based fitting on a huge range of galactic dynamics models, from potentials to distribution functions, with significant speedups for large datasets and the ability to differentiate through the whole pipeline.
Subrahmanyan: It opens up new ways to test cosmological structure formation models by allowing us to fit these complex dynamical components directly against observational data in a differentiable way. That kind of capability should help constrain parameters in halo models much more tightly than before, provided we can handle those computational costs on large scales.
Vera: Yeah, it’s a powerful tool for making our current modeling frameworks more flexible and faster when dealing with the sheer size of modern astronomical surveys. We'll keep an eye on how this capability plays out as we start fitting more complex models to real data sets.
Jocelyn: And for us, it means we can push these time-domain simulations and stream analyses further into the GPU acceleration space, which should help settle those lingering questions about the dynamics of stellar populations in nearby galaxies.
Subrahmanyan: It’s a solid step toward making our theoretical predictions more computationally accessible for actual data analysis, but we have to keep an eye on how stable those backend choices remain as array frameworks evolve.
The paper's summary: Vera: So, to recap, this paper is about taking galpy, which is this existing Python library for galactic dynamics, and adding JAX and PyTorch as new computational engines on top of NumPy and C.
Jocelyn: Right, so they're making all the core stuff—the potentials, the orbit solvers—run on GPUs using these new backends.
Vera: And they are making it differentiable so we can calculate how small changes in our inputs affect the final results, which is huge for fitting models.
Jocelyn: They’re focused on keeping things compatible with NumPy so existing code still works perfectly, but they use a smart system where the type of data you give it decides whether to use JAX or PyTorch for that specific calculation.
Vera: That backend switching based on the array type is key because it lets you get those GPU speeds and those gradients when you need them most.
Jocelyn: And they’re giving us options for orbit integration, so you can either use the solver built into the backend, or use galpy's older compiled C code for speed.
Vera: The real win here is that you can do gradient-based fitting on dynamical models—like those distribution functions—at a speed that lets you check many parameters in your potential or your distribution function very quickly.
Jocelyn: It means instead of spending days running slow NumPy fits, you can test different versions of a model much faster, and find the optimal parameters more directly.
Vera: The paper also details how they’ve made sampling from those distribution functions differentiable, which lets us calculate derivatives with respect to things like the scale radius of a disk.
Jocelyn: That's important because it means we can check if our theoretical predictions for velocity dispersion match what we see in observations by seeing how sensitive that prediction is to a specific parameter.
Vera: They also look at tidal stream models, showing that you can track those streams and calculate derivatives with respect to potential parameters right from the start of the construction.
Jocelyn: It’s about connecting the theory on structure formation, which is what Subrahmanyan works on, directly to high-speed computational tools that can handle large datasets.
Vera: The main implication is that we can start doing much more sophisticated model testing and parameter estimation for galactic dynamics right now, with a massive speed boost and the ability to get gradients.
Jocelyn: This opens up new avenues for how we test cosmological models by fitting these complex dynamical components against real observational data in a differentiable way.
Vera: It’s about making the tools we use to model the sky much more powerful when it comes to finding the right parameters for galaxies and streams.
The paper's improvements: Vera: So, we're looking at what the authors suggest to do next with this galpy extension—it’s about making specific tweaks to how they handle different parts of their system.
Jocelyn: They are focusing on those orbit integration methods, where they have three choices: using the solver built into the backend, or using those older compiled C integrators.
Vera: The authors suggest that for small numbers of points, sticking with the C integrators is still better because it’s just way faster than running a full automatic differentiation solver every time.
Jocelyn: That makes sense if you're only doing a quick test run, but they are also pointing out the trade-off where using the backend’s internal solver has a problem with batching in PyTorch unless you use that specific torchode tool.
Vera: That limitation is real for people trying to do large simulations on a GPU, so they acknowledge that if you need massive parallel processing, you might have to stick closer to the C path for those specific integration routines.
Jocelyn: Another big suggestion is around the distribution functions where sampling isn't differentiable everywhere—they flag the velocity sampler for quasiisothermal disks as a place where it just stops working smoothly.
Vera: That’s a clear limitation on what you can derive mathematically from those specific models right now, which means if you need to work with that specific velocity dispersion model, you can’t get gradients with respect to its parameters.
Jocelyn: But they are pushing for making the other DF models differentiable so that we keep gaining that ability to optimize things based on data.
Vera: The big idea is they want a framework where the user can choose their tool—the fast C path or the differentiable backend solver—based on whether they need maximum speed or maximum mathematical flexibility.
Jocelyn: It’s about giving the user control over which method to employ for orbit integration and distribution sampling, rather than just having one single path that does everything.
Vera: This modular approach means that if a specific component, like the stream model construction you mentioned earlier, has a better differentiable way to run on JAX versus PyTorch, the framework supports it without breaking the whole thing.
Jocelyn: So they are essentially building an engine that lets people plug in their preferred computational backend for different tasks within galpy.
Vera: It’s about future-proofing the library so that as JAX and PyTorch keep changing, this structure won't force everyone to rewrite the core physics modules again.
Jocelyn: That way, we can keep adding new acceleration methods without having to worry about losing compatibility with the NumPy version of galpy.
Vera: It sounds like they’re aiming for a system that is both extremely fast when you need it and mathematically rigorous when you need to check parameter sensitivity.
Conclusion: Vera: So we're wrapping up on "galpy with differentiable, accelerated backends: galactic dynamics in jax and PyTorch." Basically, this paper shows how they’ve integrated JAX and PyTorch as new ways to run galpy calculations on GPUs while keeping the NumPy version exactly the same.
Jocelyn: Right, so it’s about giving astronomers a way to use these high-speed accelerators for complex galactic dynamics work without having to start from scratch.
Vera: The main thing is that they’ve made everything differentiable, which means we can finally get gradients back from things like gravitational potentials and distribution functions.
Jocelyn: So you can do gradient-based fitting on these models much faster than before, which helps us find the right parameters for galaxies and streams more efficiently.
Vera: It’s about making our existing modeling tools much more powerful when we need to test many different scenarios quickly and accurately.
Jocelyn: And they show how you can choose your integration path—whether you want the fast backend solver or the older C code—so it's flexible for different types of jobs.
Vera: It’s a neat way to manage those trade-offs between raw speed and mathematical accuracy for specific simulations.
Jocelyn: This is huge because it lets us push our time-domain simulations further into the GPU acceleration space, which should help settle those lingering questions about stellar populations in nearby galaxies.
Vera: We’ve seen how this capability helps us constrain parameters in halo models much tighter when we can run these complex tests at scale.
Jocelyn: It’s a solid step toward making our theoretical predictions more computationally accessible for actual data analysis, but we still have those caveats about where the sampling isn't differentiable.
Vera: So, it’s not a magic bullet, but it is definitely a very strong tool for researchers who are working with massive datasets and need to check model sensitivity.
Jocelyn: Indeed, so this work on "galpy with differentiable, accelerated backends: galactic dynamics in jax and PyTorch" sets a new standard for how we can accelerate these kinds of scientific computations.
Vera: Next week, we’re going to look at some papers focusing on how observational pipelines are handling the massive amount of data from next-generation surveys.
Jocelyn: We'll see what tools are being developed to make that data reduction process much faster and more robust.
Subrahmanyan: I think this paper is important because it shows the physics side of things can actually scale up with these new computational methods, which is what we need to do for structure formation models.
More episodes
- 2607.17929-gevolution 2.0: GPU-accelerated relativistic N-body simulations for cosmology
- The day in conversation for 2026-11-19
- Daily Summary for 2026-11-19
- 2509.02657-On the synergetic use of Ariel and JWST for exoplanet atmospheric science
- 2609.10042-Modelling Fourier filtering wavefront sensors for PSD-based methods: the AOPERA tool
- 2511.05639-Performance of the AstroPix Prototype Module for the Barrel Imaging Calorimeter at the ePIC Detector and in Space-Based Payloads
- 2610.19909-RPCA: a Resolved PSF reconstruction method for undersampled images
- 2512.03440-An Analysis of LIGO Glitches Using t-SNE During the First Part of the Fourth LIGO-Virgo-KAGRA Observing Run
- 2608.10284-Lunar Reflective Interferometry
- 2610.16633-Institutional broadening of the Japanese astronomy and astrophysics research community during 1996-2025