TLDR: diffSPH is a new open-source framework built in PyTorch that makes Smoothed Particle Hydrodynamics (SPH) simulations fully differentiable. This allows for advanced applications in Computational Fluid Dynamics (CFD) and machine learning, such as optimizing physical parameters, designing shapes, training neural networks to correct simulations, and developing new methods for particle distribution. It addresses traditional challenges in SPH by enabling seamless integration of physics with AI, offering a powerful tool for researchers.
A new open-source framework called diffSPH is set to transform how we approach fluid dynamics simulations, especially when combined with machine learning. Developed entirely in PyTorch with GPU acceleration, diffSPH makes Smoothed Particle Hydrodynamics (SPH) simulations fully differentiable. This means that the framework can automatically calculate how changes in input parameters affect the simulation’s outcome, which is incredibly powerful for optimization and AI applications.
Traditionally, connecting complex fluid simulations with machine learning has been challenging. Existing SPH solvers weren’t built with differentiability in mind, making it difficult to use gradient-based optimization techniques or train neural networks that interact directly with the simulation. diffSPH addresses this by being designed from the ground up for differentiation, enabling seamless integration of physics and AI.
The framework supports a wide range of fluid physics, including compressible flows (with shock capturing and multi-phase flows), weakly compressible flows (with boundary handling and free-surface flows), and incompressible physics. This versatility allows it to be applied to many different scenarios in Computational Fluid Dynamics (CFD).
One of the key innovations in diffSPH is its ability to handle complex problems that were previously difficult or impossible with traditional solvers. For instance, it can optimize initial conditions and physical parameters to match desired outcomes, perform shape optimization, and even implement a ‘solver-in-the-loop’ setup where neural networks learn to improve simulation accuracy. It can also propagate gradients through hundreds of simulation steps, a crucial feature for deep learning applications.
To overcome the significant memory and computational challenges of applying automatic differentiation to complex simulations, diffSPH uses optimized building blocks and a technique similar to gradient checkpointing. Instead of storing all intermediate values, it recomputes necessary data during the backward pass, drastically reducing memory usage while maintaining efficiency. The framework also features an efficient neighborhood search algorithm, essential for SPH, and supports custom C++ and CUDA components for performance-critical operations, all while maintaining differentiability.
The paper demonstrates diffSPH’s unique capabilities through several compelling applications. It shows how the framework can solve inverse problems, such as denoising initial conditions or finding an unknown physical parameter (like the adiabatic constant) by matching a target simulation trajectory. It also illustrates geometry optimization, where the shape of a wave source is optimized to maximize wave intensity at a specific location.
Furthermore, diffSPH facilitates the development of hybrid machine learning models. For example, it can train neural network ‘correctors’ that work alongside a simple numerical solver to achieve the accuracy of a more complex, higher-order scheme. This ‘solver-in-the-loop’ approach benefits significantly from the framework’s differentiability, allowing for advanced training techniques like temporal unrolling.
Perhaps one of the most exciting new applications is differentiable particle shifting. Particle shifting is vital for maintaining the accuracy and stability of SPH simulations, but traditional methods can be complex and require extensive tuning. With diffSPH, this problem can be framed as an optimization task, minimizing physical loss terms to find optimal particle distributions. This approach has shown promising results, even outperforming traditional methods in some cases, and can easily incorporate boundary conditions.
Also Read:
- Dimer-Enhanced Optimization: Stabilizing Neural Network Training by Escaping Saddle Points
- Iterative AI Training Enhances Accuracy and Efficiency in Atomic Simulations
In terms of performance, diffSPH scales efficiently, handling millions of particles with GPU acceleration. The overhead of automatic differentiation is kept low, often similar to the forward pass, making it practical for long simulation trajectories. This robust performance, combined with its user-friendly PyTorch interface, positions diffSPH as a foundational platform for researchers at the intersection of machine learning and CFD. You can learn more about this innovative framework by reading the full research paper: diffSPH: Differentiable Smoothed Particle Hydrodynamics for Adjoint Optimization and Machine Learning.


