Differentiable N-body code for Galactic Dynamics - Odisseo

Giuseppe Viterbo, Tobias BuckDiffSys @ EurIPS 2025

TL;DR

Researchers have developed ODISSEO, a new differentiable N-body simulation code written in JAX. This tool allows for the precise modeling of stellar streams to better understand the Milky Way's gravitational potential and dark matter distribution, enabling gradient-based inference for complex astrophysical problems.

What Problem Does This Paper Address?

Understanding the structure and evolution of our Milky Way galaxy is a monumental task. One key way astronomers probe this is by studying "stellar streams" – long trails of stars left behind by disrupted dwarf galaxies or globular clusters. These streams are incredibly sensitive to the Milky Way's gravitational field, including the distribution of dark matter. However, accurately modeling these streams and using them to infer galactic properties has been computationally challenging. Traditional N-body simulations, while accurate, are not easily integrated with modern machine learning techniques for parameter inference. Conversely, existing differentiable models often rely on approximations that limit their accuracy. This paper aims to bridge this gap by creating a highly accurate, differentiable N-body code that can be used for sophisticated inference tasks.

Methods

The core innovation is ODISSEO, an N-body code built entirely in Python using the JAX library. JAX is crucial because it provides:

  • Automatic Differentiation: This allows the code to compute gradients of simulation outputs (like particle positions) with respect to input parameters (like the galaxy's mass distribution or accretion times). This is the foundation for gradient-based optimization.
  • Just-In-Time (JIT) Compilation: This optimizes the Python code for performance, making it run much faster.
  • Hardware Acceleration: ODISSEO can leverage GPUs and TPUs for significant speedups.

ODISSEO uses a direct pairwise force calculation with softening, which ensures accuracy but can be computationally intensive for very large numbers of particles. The code is designed to be modular and functional, making it easier to extend and integrate with other tools.

Datasets

The paper uses a mock GD-1 stellar stream simulation for demonstration purposes. This mock dataset is generated based on known parameters, allowing the researchers to test how well ODISSEO can recover those parameters. They do not use real observational data for the primary demonstrations but refer to existing studies that have used real data (e.g., for error estimates).

Key Insights and Ideas

  • Differentiable N-body is Powerful: The ability to backpropagate gradients through a full N-body simulation opens up new avenues for inferring complex astrophysical parameters that were previously intractable with traditional methods.
  • JAX is a Game-Changer for Scientific Computing: The paper highlights how JAX's features (autodiff, JIT, hardware acceleration) can be effectively applied to computationally intensive scientific simulations, making them more accessible for machine learning-driven research.
  • Scalability is Achievable: Despite the complexity of N-body simulations, ODISSEO demonstrates near-linear scaling when distributing a single simulation across multiple GPUs, making it practical for large-scale inference.
  • Stellar Streams are Sensitive Probes: The successful recovery of parameters from a mock stellar stream underscores the value of these structures for mapping galactic potentials.

Key Results

  • ODISSEO successfully recovers four key physical parameters (accretion time, progenitor mass, host galaxy NFW halo mass, and Miyamoto-Nagai disk mass) from a mock GD-1 stellar stream simulation using gradient descent.
  • The code exhibits near-linear strong scaling when distributing a single simulation across multiple GPUs, achieving significant speedups. For example, with N > 10⁴ particles, the speedup closely follows the ideal linear trend as more GPUs are added.
  • Two inference methods are demonstrated: one using Maximum Mean Discrepancy (MMD) between simulated and observed point clouds, and another using a chi-squared fit to recover orbital parameters.

Limitations and Future Work

  • Computational Cost: While scalable, direct N-body simulations can still be computationally expensive for extremely large numbers of particles (N > 10⁶). The current implementation does not use tree or fast-multipole methods for force calculation.
  • Inference Method Limitations: The paper acknowledges that the demonstrated inference pipeline, particularly the grid search, is a proof of concept. The second method is limited by a Gaussian approximation and the dependency on the initial guess for the gradient descent.
  • Future Work: The authors plan to explore more robust uncertainty quantification methods (e.g., Hamiltonian Monte Carlo, simulation-based inference). They also aim to couple ODISSEO with neural networks to improve solver accuracy, similar to work on iterative PDE solvers. Incorporating more sophisticated force calculation methods (like tree codes) is also a likely future direction.

Summary updated

BibTeX
@inproceedings{viterbo2025differentiable,
  author = {Giuseppe Viterbo and Tobias Buck},
  title = {{Differentiable N-body code for Galactic Dynamics - Odisseo}},
  booktitle = {DiffSys @ EurIPS},
  year = {2025},
  url = {https://openreview.net/forum?id=CLvRgupDcG},
}
Figure