Abstract
$\Phi_{\text{ML}}$ is a high-level library designed to bridge the gap between deep learning frameworks and scientific computing. By introducing "dimension types" and named axes, it simplifies the development of differentiable simulations across multiple backends including Jax, PyTorch, TensorFlow, and NumPy. $\Phi_{\text{ML}}$ eliminates common indexing errors through automatic reshaping and broadcasting, provides first-class support for sparse matrices, and ensures numerical precision consistency. This paper describes the core innovations of $\Phi_{\text{ML}}$, its backend-agnostic architecture, and its application in complex physical modeling tasks such as fluid dynamics and PDE solving.
Introduction
While deep learning frameworks like PyTorch and TensorFlow have revolutionized artificial intelligence, they were not originally built for the "hard sciences." In computer vision, a tensor is often treated as a generic grid of numbers. In physics, however, dimensions have specific, immutable meanings—time, space, vector components, or particle indices. Standard frameworks often force researchers into "tensor gymnastics," using cryptic integer-based indexing (e.g., x[..., 0, :, :]) to perform operations. This leads to code that is difficult to read, fragile when moving between 2D and 3D simulations, and prone to silent bugs. $\Phi_{\text{ML}}$ addresses these challenges by introducing a named dimension system that prioritizes readability and physical context.
Methods
The core innovation of $\Phi_{\text{ML}}$ is its Dimension Type system. Instead of referring to dimensions by index (0, 1, 2), users define them by name and category:
- Spatial: For physical dimensions (x, y, z).
- Channel: For vector components or features (e.g., velocity, pressure).
- Batch: For parallel data processing.
- Instance: For collections of objects like particles.
- Dual: For degrees of freedom in linear systems.
Technical Features
Automatic Reshaping and Broadcasting: The library automatically transposes and broadcasts tensors based on their dimension names. This makes the simulation logic agnostic to the order of dimensions, allowing a 1D simulation and a 3D simulation to often use the exact same code.
Backend Agnosticism: $\Phi_{\text{ML}}$ acts as a sophisticated wrapper. Users can write their simulation once and execute it using Jax, PyTorch, TensorFlow, or NumPy without changing the underlying logic.
Numerical Precision and Sparsity: Unlike standard libraries where input data types dictate output precision, $\Phi_{\text{ML}}$ can determine the required floating-point precision based on the operation's context, facilitating 64-bit accuracy where essential. Furthermore, it treats sparsity as a first-class citizen, leveraging the local nature of physical interactions (e.g., fluid cell dependencies) to convert linear Python functions into efficient sparse matrix representations.
Lazy Stacking: To optimize performance, the library delays memory allocation for stacked tensors until absolutely necessary, reducing computational overhead.
Results and Applications
$\Phi_{\text{ML}}$ emphasizes both usability and performance. Code written in $\Phi_{\text{ML}}$ is significantly less verbose than native framework code for identical scientific tasks. Despite being a high-level wrapper, the library introduces zero overhead; completed code runs as fast as if it were written directly in the chosen backend.
The library has demonstrated its utility across various scientific domains:
- Fluid Dynamics: Enabling differentiable simulations of liquids and gases.
- Weather Prediction: Supporting research in meteorological modeling.
- PDE Modeling: Solving partial differential equations in open datasets like PDEBench.
- Molecular Science: Applications in chemistry and materials science.
It serves as the foundational engine for the PhiFlow project and has been successfully used in numerous peer-reviewed publications to train neural networks that "steer" physical simulations or learn corrections for low-resolution models.
Conclusion
$\Phi_{\text{ML}}$ provides a powerful, intuitive interface for scientific machine learning. By shifting the focus from index manipulation to physical dimension types, it enables researchers to write more robust, readable, and backend-independent code. While it currently relies on the underlying backends for core execution—meaning some specialized sparse operations may require custom kernels—its architecture significantly lowers the barrier to entry for high-performance differentiable physical modeling.
Summary updated