Building a General PDE Solving Framework with Symbolic-Numeric Scientific Machine Learning
stazi3110
1,467 views
86 slides
Apr 25, 2024
Slide 1 of 86
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
About This Presentation
Wednesday April 3rd, 4:30pm, Room 2-255 at MIT Building a General PDE Solving Framework with Symbolic-Numeric Scientific Machine Learning The dream is to be able to write down a symbolic expression of a PDE and just get a solution. Not only get a solution, but get that solution efficiently. The ques...
Wednesday April 3rd, 4:30pm, Room 2-255 at MIT Building a General PDE Solving Framework with Symbolic-Numeric Scientific Machine Learning The dream is to be able to write down a symbolic expression of a PDE and just get a solution. Not only get a solution, but get that solution efficiently. The question is, how do we effectively build a software ecosystem to achieve this goal, and what are the remaining mathematical problems that are necessary to solve in order to fill the gaps? In this talk we will discuss the Julia SciML ecosystem's approach to a general PDE solving framework. We will focus on 5 aspects: (1) a symbolic structural hierarchical classification of PDEs for shuttling high level PDE descriptions to appropriate solution approaches, (2) new time-stepping methods for accelerating the solution of semi-discretized equations and generalizing approaches from PDEs to structured ODE forms, (3) symbolic-numeric approaches for automating the transformation of semi-discretizations to simpler and more numerically stable equations before solving, and (4) new improvements to adjoint methods to decrease the memory requirements for differentiation of PDE solutions, and (5) scientific machine learning approaches to generate accelerated approximations (surrogates) to PDE simulators. We will demonstrate these methods with open source software that starts from symbolic expressions and solves industrial-scale PDEs with minimal lines of code.
Size: 26.66 MB
Language: en
Added: Apr 25, 2024
Slides: 86 pages
Slide Content
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Machine Learning Chris Rackauckas VP of Modeling and Simulation, JuliaHub Research Affiliate, MIT CSAIL
Connect with SciML Follow on Twitter @ChrisRackauckas Follow on LinkedIn https://www.linkedin.com/in/chrisrackauckas/ Star the GitHub repositories https://github.com/SciML Join our community chatrooms julialang.org/slack Dr. Chris Rackauckas VP of Modeling and Simulation JuliaHub Research Affiliate MIT CSAIL Director of Scientific Research Pumas-AI
PDEs Done Wrong! Writing Loops for a Single PDE
Fast Simulation: Good Algorithms + Fast Implementation (“Fast” + Implicit Euler / Newmark Beta? Get Outta Here!)
All good PDE methods can be expressed as lower level primitives: Symbolic transformations to standard computable forms Numerical methods which exploit structure on standard computable forms ModelingToolkit PDE Hypothesis:
The SciML Organization
, Christopher, and Qing Nie. "Confederated modular differential equation APIs for accelerated algorithm development and benchmarking." Advances in Engineering Software 132 (2019): 1-6. SciML: Open Source Tooling For Modeling and Simulation https://github.com/SciML/SciMLBenchmarks.jl Rackauckas, Christopher, and Qing Nie. "Differentialequations.jl–a performant and feature-rich ecosystem for solving differential equations in julia." Journal of Open Research Software 5.1 (2017). Rackauckas, Christopher, and Qing Nie. "Confederated modular differential equation APIs for accelerated algorithm development and benchmarking." Advances in Engineering Software 132 (2019): 1-6. Speed Stability Stochasticity Adjoints and Inference Parallelism Non-Stiff ODE: Rigid Body System 8 Stiff ODEs: HIRES Chemical Reaction Network Generally: 50x faster than SciPy 50x faster than MATLAB 100x faster than R’s deSolve Methods that outperform classic C and Fortran methods (CVODE, DASSL) Specialized situational methods (IMEX, stage parallel, etc.) Active Developer Base: ~100 contributors in a month across SciML Paid summer programs training ~10 new devs MIT Lab (~20 people) driven development
NonlinearSolve.jl: Robust Nonlinear Root-Finding in Julia NonlinearSolve.jl outperforms standard softwares like Sundials & MINPACK by 10-100x. Built-In Sparsity Detection & Automatic Differentiation Support enables scaling to large systems. Pal, Avik, Holtorf, Larsson, Loman, Utkarsh, Schaefer, Qu, Alan Edelman, and Chris Rackauckas. "NonlinearSolve.jl: High-Performance and Robust Solvers for Systems of Nonlinear Equations in Julia." Manuscript in Preparation. MINPACK is the slowest NonlinearSolve.jl has the fastest solvers Sundials is also very slow! NonlinearSolve.jl successfully solves novel problems where other software fail.
Modeling and Simulation Tools Across the Spectrum of Mathematics https://scimlbase.sciml.ai/dev/ The SciML Common Interface for Julia Equation Solvers LinearSolve.jl: Unified Linear Solver Interface NonlinearSolve.jl: Unified Nonlinear Solver Interface DifferentialEquations.jl: Unified Interface for all Differential Equations Optimization.jl: Unified Optimization Interface Integrals.jl: Unified Quadrature Interface Unified Partial Differential Equation Interface
What is Scientific Machine Learning (SciML)? Scientific Computing ↔ Machine Learning Machine Learning Neural Nets Bayesian Modeling Automatic Differentiation Scientific Computing Scientific Machine Learning Model Building Robust Solvers Control Systems Differentiable Simulators Surrogates and ROM Inverse Problems & Calibration Automatic Equation Discovery Applicable to Small Data and more …. ‹#›
JuliaSim Model Discovery: Autocompleting Models with SciML
Universal Differential Equations Predict Chemical Processes UDEs in advection-diffusion transform the learning problem to low dimensional spaces where small data is sufficient
Universal Differential Equations Predict Chemical Processes Santana, V. V., Costa, E., Rebello, C. M., Ribeiro, A. M., Rackauckas, C., & Nogueira, I. B. (2023). Efficient hybrid modeling and sorption model discovery for non-linear advection-diffusion-sorption systems: A systematic scientific machine learning approach. arXiv preprint arXiv:2303.13555 . Recovers equations with the same 2nd order Taylor expansion
PDE Discretization via ModelingToolkit Is Transformaiton
modular differential equation APIs for accelerated algorithm development and benchmarking." Advances in Engineering Software 132 (2019): 1-6. SciML’s Modeling Ecosystem: ModelingToolkit’s Numerical Counterpart Every improvement by every package developer feeds into one pipeline Rackauckas, Christopher, and Qing Nie. "Confederated modular differential equation APIs for accelerated algorithm development and benchmarking." Advances in Engineering Software 132 (2019): 1-6. Youtube: Differential Equations in 2021 SciML’s Common Interface: One consistent interface for all numerics Symbolic modeling for all forms Automated inverse problems and adjoints Composes across the whole package ecosystem Fully embraces generic programming Uses and embraces the work of other developers
SciML/MethodOfLines.jl # Method of lines discretization dx = 0.1 order = 2 discretization = MOLFiniteDifference ([x => dx], t, approx_order = order) # Convert the PDE problem into an ODE problem prob = discretize (sys, discretization) using OrdinaryDiffEq # Solve ODE problem sol = solve (prob, Tsit5 (), saveat = 0.1 )
SciML/MethodOfLines.jl solu = sol[ u (t,x)] x_grid = sol[x] t_grid = sol[t] using Plots heatmap (t_grid, x_grid, transpose (solu), …)
SciML/MethodOfLines.jl
SciML/MethodOfLines.jl anim = @animate for i in 1 : length (t_grid) plot (x_grid, solu[i, :], …) end gif (anim, "heat.gif" , fps = 8 )
SciML/MethodOfLines.jl
SciML/MethodOfLines.jl Burger’s Equation
@parameters x t @variables u ( .. ) Dx = Differential (x) Dxx = Dx ^ 2 Dt = Differential (t) x_min = - 1.0 x_max = 1.0 t_min = 0.0 t_max = 3.0 v = 0.01 eq = Dt ( u (t, x)) ~ - u (t, x) * Dx ( u (t, x)) + v * Dxx ( u (t,x)) bcs = [ u ( , x) ~ 0.11 * cospi ( 4 x), u (t, x_min) ~ u (t, x_max)] domains = [t ∈ Interval (t_min, t_max), x ∈ Interval (x_min, x_max)] @named pdesys = PDESystem (eq, bcs, domains, [t, x], [ u (t, x)]) Burger’s Equation SciML/MethodOfLines.jl
Implemented schemes Centered difference scheme to arbitrary order, for even ordered spatial derivative terms. Upwind difference scheme (hardcoded to first order) for odd ordered spatial derivatives. WENO Scheme Integral schemes Nonlinear laplacian scheme. Spherical laplacian scheme. Discrete callbacks Staggered Grid SciML/MethodOfLines.jl
ModelingToolkit PDEs: Method Of Lines Finite Difference
ModelingToolkit PDEs : Physics-Informed Neural Networks Easy and Customizable PINN PDE Solving with NeuralPDE.jl, JuliaCon 2021
Modeling and Simulation Tools Across the Spectrum of Mathematics https://scimlbase.sciml.ai/dev/ The SciML Common Interface for Julia Equation Solvers LinearSolve.jl: Unified Linear Solver Interface NonlinearSolve.jl: Unified Nonlinear Solver Interface DifferentialEquations.jl: Unified Interface for all Differential Equations Optimization.jl: Unified Optimization Interface Integrals.jl: Unified Quadrature Interface Unified Partial Differential Equation Interface
ModelingToolkit PDEs : Extensible PDE Interface Many extra forms have partial implementations being productionized: Finite Volume methods (FiniteVolumeMethods.jl) Spectral methods (?) Finite element methods (via Ferrite.jl) Discrete Galerkin methods (via Trixi.jl) Exterior Calculus (via Decapodes.jl) … Attempting to unify the difference PDE discretization methods into a one interface compatible with component-based modeling!
But a general PDE solver interface means nothing if it’s slow. How we take a general PDE discretization engine and make it as fast as a code that is hand-optimized to specific PDEs?
ModelingToolkit Symbolic-Numeric Optimizations
, Christopher, and Qing Nie. "Confederated modular differential equation APIs for accelerated algorithm development and benchmarking." Advances in Engineering Software 132 (2019): 1-6. Symbolics.jl MTK DiffEq
Example of Tearing Nonlinear Systems
Example of Tearing Nonlinear Systems It automatically reduced your 5 equation system to 1!
Example of Tearing Nonlinear Systems Only solves one equation numerically But can generate the other variables
Inline Integration: Tearing of Internal Solves Perform tearing on the internal nonlinear solve of an implicit method
Structural Simplify Performance: DAE vs AE DAE AE Derivative Form Analytic Computational Analytic Computational Alias Elimination 18 20 18 18 Structural Simplify 6 12 4 8
Structural Simplify Performance: DAE vs AE Model Input Output Eqs/States DAE AE f4 x ddy 97 Alias Elimination: 52 Structural Simplify: 27 eqs/26 states 50 11
Inlined Linear Solver Optimization
ExactODEReduction.jl
Improving Automated Solvers with Sparsity Detection Symbolics.jl: Automated Sparsity Analysis on Code Will be a part of the automatic solver choice!
What Kinds of Transformations Do You Get? DAE Index Reduction Not solvable by standard numerical solvers! Differentiate the last equation twice, do a few substitutions… Easy to solve! If you don’t know the details about why this makes a better numerical simulation, then you should be using ModelingToolkit.
What Kinds of Transformations Do You Get? DAE Index Reduction Let me fix that for you… Structural_simplify: Pantelides algorithm For index reduction
But that form has numerical drift
Dummy Derivative: Include the Implicit Constraints
Many “specialized CFD” methods are simply a standard ODE solver after Pantelides transformation of discretized Navier-Stokes Inlined Linear Solver optimizations covers many simple semi-implicit schemes Tearing of nonlinear systems on finite difference is a generalization of ghost points While this already hits good runtimes, there’s compilation issues I’ve glossed over Some immediate consequences that would take too long to prove:
Interested in Symbolic-Numerics? Lots of starter projects! Get in touch
Implicit-Explicit schemes, ADI, etc. all handled by this aspect. We have yet to find a PDE scheme that cannot be expressed by some combination of the previous features Scaling and automatic parallelism scheduling are among the current ongoing research questions Some immediate consequences that would take too long to prove:
sys = structural_simplify(complete_motor) JuliaSimCompiler: Accelerated ModelingToolkit 2 lines of code to turn on, enables enormous scalability improvements Solves a major scaling problem in acasual systems Conclusion: ModelingToolkit is a widely used open modeling platform, and with JuliaSim it’s also the most scalable. using JuliaSimCompiler complete_motor_ir = IRSystem(complete_motor) sys_ir = structural_simplify(complete_motor_ir) MTK JuliaSimCompiler
Loop Rerolling systems = @named begin sine = Sine(frequency = 10 ) source = Voltage() resistors[ 1 :n] = Resistor() capacitors[ 1 :n] = Capacitor() ground = Ground() end;
Loop Rerolling for var "%33" = 1 : 97 var "%34" = var "%33" - var "%32" var "%35" = var "%29" + var "%34" var "%36" = Base.getindex( var "###in 1###" , var "%35" ) var "%37" = var "%30" + var "%34" var "%38" = Base.getindex( var "###in 1###" , var "%37" ) var "%39" = var "%31" + var "%34" var "%40" = Base.getindex( var "###in 1###" , var "%39" ) var "%41" = var "%24" * var "%38" var "%42" = var "%41" + var "%36" var "%43" = var "%40" + var "%42" var "%44" = var "%31" + var "%33" var "%45" = Base.setindex!( var "###out###" , var "%43" , var "%44" ) end
Loop Rerolling on JuliaSimBattery (Single-Particle Model (SPM), Lithium Nickel Manganese Cobalt Oxide (NMC))
Exploiting Structure in ODE Solvers
“Refinements” to ODE Problems can fall into different classes
Approximate Matrix Factorization = Generalized ADI
Preliminary results indicate upto 7x acceleration on PDE solutions with upto 2x lesser memory consumption** Idea: Non-linear solve is typically the most time consuming step in PDE simulations. Perform non-linear solves in mixed precision with GPUs and also without affecting convergence?* 32-bit precision non-linear solve can achieve machine precision accuracy! * Kelley, C. T. "Newton's Method in Mixed Precision." SIAM Review 64.1 (2022): 191-211. **Manuscript in preparation. GPU Accelerated Mixed Precision Methods for Semi-discretized PDEs
Side Note: Some Special Forms
Solving Semilinear Parabolic PDEs (Nonlinear Black-Scholes) by Learning Structured Stochastic Differential Equations Simplified: Transform the PDE into a Backwards SDE: a stochastic boundary value problem. The unknown is a function! Learn the unknown function via neural network . Once learned, the PDE solution is known. Solving high-dimensional partial differential equations using deep learning, 2018, PNAS, Han, Jentzen, E
Solving Semilinear Parabolic PDEs (Nonlinear Black-Scholes) by Learning Structured Stochastic Differential Equations Solving high-dimensional partial differential equations using deep learning, 2018, PNAS, Han, Jentzen, E
Solving Semilinear Parabolic PDEs (Nonlinear Black-Scholes) by Learning Structured Stochastic Differential Equations This is equivalent to training the universal SDE: Solves a 100 dimensional PDE in minutes on a laptop! As a universal SDE, we can solve this with high order (less neural network evaluations), adaptivity, etc. methods using DiffEqFlux.jl. Thus we automatically extend the deep BSDE method to better discretizations by using this interpretation!
Extending the Method: Learning Nonlinearities While Solving?
Differentiation for Inverse Problems: Issues with Adjoints
Advancements in Structural Identifiability Analysis of ODE control systems Novel autonomous algorithms based on differential algebra that uncover the source of non-identifiability Classic problem: impossible to deduce if we only measure and 𝑏 is unknown Also: first steps towards PDE identifiability in "Algebraic identifiability of partial differential equation models," arxiv 2024. Solution: model reparametrization. Fewer parameters. All new variables are identifiable. is not identifiable Reparametrization is already available in SciML/StructuralIdentifiability.jl : Fully automatic. Domain agnostic. Works with non-linear ODEs of dimensions around 20.
The adjoint equation is an ODE! How do you get z(t)? One suggestion: Reverse the ODE Timeseries is not stored, therefore O(1) in memory! Machine Learning Neural Ordinary Differential Equations Chen, Ricky TQ, et al. "Neural ordinary differential equations." Advances in neural information processing systems. 2018.
Rackauckas, Christopher, and Qing Nie. "Differentialequations. jl–a performant and feature-rich ecosystem for solving differential equations in julia." Journal of Open Research Software 5.1 (2017). Rackauckas, Christopher, and Qing Nie. "Confederated modular differential equation APIs for accelerated algorithm development and benchmarking." Advances in Engineering Software 132 (2019): 1-6. “Adjoints by reversing” also is unconditionally unstable on some problems! Advection Equation: Approximating the derivative in x has two choices: forwards or backwards If you discretize in the wrong direction you get unconditional instability You need to understand the engineering principles and the numerical simulation properties of domain to make ML stable on it. Result: the method in the PyTorch library is unconditionally unstable!!!
Problems With Naïve Adjoint Approaches On Stiff Equations Kim, Suyong, Weiqi Ji, Sili Deng, and Christopher Rackauckas. "Stiff neural ordinary differential equations." Chaos (2021). How do you get u(t) while solving backwards? 3 options! 1. 2. Store u(t) while solving forwards (dense output) 3. Checkpointing Unstable High memory More Compute Each choices has an engineering trade-off!
Problems With Naïve Adjoint Approaches On Stiff Equations Kim, Suyong, Weiqi Ji, Sili Deng, and Christopher Rackauckas. "Stiff neural ordinary differential equations." Chaos (2021).
Gives about a 10x performance improvement for adjoint calculations on PDEs “Adjoint” can mean many many different things… Ma, Yingbo, Vaibhav Dixit, Michael J. Innes, Xingjian Guo, and Chris Rackauckas. "A comparison of automatic differentiation and continuous sensitivity analysis for derivatives of differential equation solutions." In 2021 IEEE High Performance Extreme Computing Conference (HPEC) , pp. 1-9. IEEE, 2021.
The Test Problem
Julia Derivative Results All methods compute the same derivative to many digits
Jax Implementation of the Test Problem Jax requires a lot more code
Jax Derivative Results: BacksolveAdjoint BacksolveAdjoint works here, but it’s the unstable one!
Jax Derivative Results: RecursiveCheckpointingAdjoint and DirectAdjoint Jax’s other methods don’t converge, >60% error!
Memory-efficient Continuous Adjoint Sensitivity Method for Universal Ordinary Differential Equations In comparison to QuadratureAdjoint, GaussAdjoint is much more memory efficient! will work on GPUs will be compatible with SDEs Goal: compute the gradient of a loss function with respect to many parameters Sapienza et al. , "Differentiable Programming for Differential Equations: A Review" in preparation (2024). This gradient can be computed as follows Solve the differential equation to obtain u(t): Solve the adjoint differential equation to obtain λ(t): Solve the integral: Idea: GaussAdjoint computes the integral in a memory-efficient manner by accumulating the Gauss quadrature approximation of the integral over time! This circumvents the need of a continuous solution for λ(t)!
The PyTorch library uses a numerically unstable method The Jax library uses a non-convergent method. The Julia library is numerically stable and convergent. Calculating derivatives is hard. Conclusion:
SciML Surrogates for PDEs
ModelOrderReduction: Intrusive MOR done Nonintrusively
Using structural PDE information reduces the amount of data required for the surrogates to achieve 5% error by 100x! Pestourie, R., Mroueh, Y., Rackauckas, C. et al. Physics-enhanced deep surrogates for partial differential equations. Nat Mach Intell 5, 1458–1465 (2023). https://doi.org/10.1038/s42256-023-00761-y Physics-Enhanced Deep Neural Surrogates (PEDS)
Steady State Surrogate Jet Engine Pipeline C Binary Simulator Model Ingestion Parallel Data Generation using JuliaHub Simulator Simulator Simulator Sampled Config Mass Model Experimentation using JuliaHub Deployment
Surrogates which converge to a user-chosen accuracy Provisional patent filed JuliaSimSurrogates Auto-Train Fully automated training infrastructure for surrogates
JuliaSim Surrogates Cloud Deployment Automating the parallelization in SciML training Surrogates have multiple points of natural parallelization: Neural network training should take place on large GPU systems Surrogate data training is an embarrassingly-parallel process, generally on CPU Optimal parallelism thus requires different machines for different parts of the process, and expertise than can optimize the hardware choices automatically.
2D electrochemical model of a single battery 300 equations, 5 ms solve time Battery pack: repeat the model 200 times Very long simulation time Most tools cannot scale physically-accurate models to full packs JuliaSim Batteries overview
Digital Echo on Live Battery Models
Surrogate Validation App
Connect with SciML Follow on Twitter @ChrisRackauckas Follow on LinkedIn https://www.linkedin.com/in/chrisrackauckas/ Star the GitHub repositories https://github.com/SciML Join our community chatrooms julialang.org/slack Dr. Chris Rackauckas VP of Modeling and Simulation JuliaHub Research Affiliate MIT CSAIL Director of Scientific Research Pumas-AI