|
| 1 | +# Comparison of Julia's ModelingToolkit vs SymPy for Symbolic Computation |
| 2 | + |
| 3 | +ModelingToolkit.jl is a symbolic modeling language for Julia built in |
| 4 | +Julia. Its goal is very different from Sympy: it was made to support |
| 5 | +symbolic-numerics, the combination of symbolic computing with numerical |
| 6 | +methods to allow for extreme performance computing that would not be |
| 7 | +possible without modifying the model. Because of this, ModelingToolkit.jl |
| 8 | +excels in many areas due to purposeful design decisions: |
| 9 | + |
| 10 | +- Performance: ModelingToolkit.jl is built in Julia, whereas SymPy was |
| 11 | + built in Python. Thus the performance bar for ModelingToolkit.jl is |
| 12 | + much higher. ModelingToolkit.jl started because SymPy was far too |
| 13 | + slow and SymEngine was far too inflexible for the projects they were |
| 14 | + doing. Performance is key to ModelingToolkit.jl. If you find any |
| 15 | + performance issues, please file an issue. |
| 16 | +- build_function: `lambdify` is "fine" for some people, but if you're building |
| 17 | + a super fast MPI-enabled Julia/C/Fortran simulation code, having a |
| 18 | + function that hits the Python interpreter is less than optimal. By |
| 19 | + default, `build_function` builds fast JIT-compiled functions due |
| 20 | + to being in Julia. However, it has support for things like static |
| 21 | + arrays, non-allocating functions via mutation, fast functions on |
| 22 | + sparse matrices and arrays of arrays, etc.: all core details of |
| 23 | + doing high performance computing. |
| 24 | +- Parallelism: ModelingToolkit.jl has pervasive parallelism. The |
| 25 | + symbolic simplification via [SymbolicUtils.jl](https://github.com/JuliaSymbolics/SymbolicUtils.jl) |
| 26 | + has built-in parallelism, ModelingToolkit.jl builds functions that |
| 27 | + parallelizes across threads and multiprocesses across clusters, |
| 28 | + and it has dynamic scheduling through tools like [Dagger.jl](https://github.com/JuliaParallel/Dagger.jl). |
| 29 | + ModelingToolkit.jl is compatible with GPU libraries like CUDA.jl. |
| 30 | +- Scientific Machine Learning (SciML): ModelingToolkit.jl is made to synergize |
| 31 | + with the high performance Julia SciML ecosystem in many ways. At a |
| 32 | + base level, all expressions and built functions are compatible with |
| 33 | + automatic differentiation like ForwardDiff.jl and Zygote.jl, meaning |
| 34 | + that it can be used in and with neural networks. Tools like |
| 35 | + [DataDrivenDiffEq.jl](https://datadriven.sciml.ai/dev/) can reconstruct |
| 36 | + symbolic expressions from neural networks and data while |
| 37 | + [NeuralNetDiffEq.jl](https://github.com/SciML/NeuralNetDiffEq.jl) |
| 38 | + can automatically solve partial differential equations from symbolic |
| 39 | + descriptions using physics-informed neural networks. |
| 40 | +- Primitives for high-performance numerics. Features like `ODESystem` |
| 41 | + can be used to easily generate automatically parallelized ODE solver |
| 42 | + code with sparse Jacobians and all of the pieces required to get |
| 43 | + the most optimal solves. Support for differential-algebraic equations, |
| 44 | + chemical reaction networks, and generation of code for nonlinear |
| 45 | + optimization tools makes ModelingToolkit.jl a tool for, well, |
| 46 | + building, generating, and analyzing models. |
| 47 | +- Deep integration with the Julia ecosystem: ModelingToolkit.jl's integration |
| 48 | + with neural networks is not the only thing that's deep. ModelingToolkit.jl |
| 49 | + is built with the same philosophy as other SciML packages, eschewing |
| 50 | + "monorepos" for a distributed development approach that ties together |
| 51 | + the work of many developers. The differentiation parts utilize tools |
| 52 | + from automatic differentiation libraries, all linear algebra functionality |
| 53 | + comes from tracing Julia Base itself, symbolic rewriting (simplification |
| 54 | + and substitution) comes from |
| 55 | + [SymbolicUtils.jl](https://github.com/JuliaSymbolics/SymbolicUtils.jl), |
| 56 | + parallelism comes from Julia Base libraries and Dagger.jl, and etc. |
| 57 | + The list keeps going. All told, by design ModelingToolkit.jl's development |
| 58 | + moves fast because it's effectively using the work of hundreds of |
| 59 | + Julia developers, allowing it to grow fast. |
0 commit comments