One of the key features of Julia that we have used to great effect in AlgebraicJulia is the support for runtime code generation and evaluation of that generated code.
For instance, given a Petri net we can create a Julia Expr
which, when evaluated, computes the vector field associated with the mass-action semantics of the Petri net. This gives the opportunity for this code to pass through the Julia JIT (and thus through LLVM), so that the function that we pass to the ODE solver (which will be called many times) is as fast as possible.
If we did not have the ability to evaluate generated code at runtime, we would have to pass some generic function into the ODE solver which computed the vector field via inspecting the Petri net, which would be considerably slower.
This is one of the reasons why Julia is such a fantastic language.
But, Julia does have its downsides. Namely, the combination of static types and algebraic data types that make functional programming languages so attractive for compiler writing is missing in Julia. And furthermore, in the long run, we might want to do formal proofs of correctness of our scientific algorithms.
Fortunately, there has been a lot of research into well-typed code generation. The promise of well-typed code generation is to be able to express the pattern that I had at the beginning (from a Petri net, generate its vectorfield function and then eval that code and use it in an ODE solver), but without the necessity of eval
being typed Expr -> Any
.
I am particularly excited about some work in progress that I’ve snooped on in Andras Kovacs’ github: GitHub - AndrasKovacs/dtt-rtcg: Demo for dependent types + runtime code generation. You should read his summary of it: GitHub - AndrasKovacs/dtt-rtcg: Demo for dependent types + runtime code generation.
The TL;DR is that working in a dependently typed language makes some of the ergonomics around generating code (such as generating types, and generating code that refers to variables in your current scope) much better. The path to formally verified, general, high-performance scientific code just got shorter!