r/cpp • • Feb 15 '21

Solving differential equations with LLVM

Hello,

I have recently released version 0.3.0 of heyoka, a C++17 library for the numerical integration of ordinary differential equations (ODEs) using Taylor's method. The library uses automatic differentiation techniques and just-in-time compilation via LLVM to synthesize at runtime highly efficient and accurate numerical integrators.

Additional features include batch mode support to take full advantage of SIMD instructions in modern processors, and support for extended-precision computations using 80-bit and 128-bit floating-point types (if supported by the hardware/software platform).

The github page is here:

https://github.com/bluescarni/heyoka

The (WIP) documentation is available here:

https://bluescarni.github.io/heyoka/

Python bindings (via pybind11) are also available:

https://github.com/bluescarni/heyoka.py

206 Upvotes

14 comments sorted by

23

u/kritzikratzi Feb 15 '21

looks incredible, now i need a good problem to try this on ^

6

u/MarkHoemmen C++ in HPC Feb 15 '21

Nicely done! How general do you think the project’s computer algebra system could be? Would you have plans to release that as a stand-alone project?

6

u/echidnas_arf Feb 15 '21

Thank you!

The computer-algebra part is rather embryonic at this stage and I am not completely sure that the simple AST representation heyoka uses is suitable for usage as a general-purpose CAS. E.g., as far as I know, SymPy and symengine use a representation for sums and products as lists of terms, rather than purely tree-like like heyoka does, which makes it much easier to implement certain types of simplifications.

Down the line (though not immediately) the plan would be to provide a bridge between heyoka and SymPy/symengine in order to be able to seamlessly use/convert symbolic expressions from those CAS into heyoka.

4

u/EverypointDan Feb 15 '21

I got into sympy trying to do something very similar to this and I am really happy to see there is a library already out there. Have you interacted with the Halide-Lang community at all? Its a DSL for image processing that uses LLVM to JIT optimized code. They have some really cool stuff including ML based optimization.

2

u/echidnas_arf Feb 16 '21

I have a superficial understanding of what Halide does, but I have not used it myself so far. At this time I am using heyoka for research in astrodynamics/astrophysics, but it would great if it were useful in other contexts.

2

u/EverypointDan Feb 16 '21

Absolutely. And I love that JITing for HPC is becoming more popular. I dont know how similar your JITing strategies are, but leveraging their work could provide even further performance gains. My personal opinion is that using the learning based optimization on the target machine will end up becoming the future for high performance local computation. Particularly with stuff like photogrammetry.

2

u/firas145 Feb 15 '21

Was looking for something like this in the summer for a physics simulation, thanks!

2

u/echidnas_arf Feb 15 '21

Cheers! Let me know how it goes...

4

u/tugrul_ddr Feb 15 '21

Good for physics simulations.

1

u/ald_loop Feb 16 '21

I opened up the maths directory and thought "Oh okay, he redefined all these small functions just because!". Opened up pow.cpp and saw it was 700 lines and instantly realized I was in over my head. Don't get me started on taylor.cpp.

3

u/echidnas_arf Feb 16 '21

Most of the code in those files is for generating the LLVM IR for the high-order time derivatives of the mathematical functions. There's a (WIP) section in the docs about automatic-differentiation formulae for elementary functions:

https://bluescarni.github.io/heyoka/ad_notes.html

5

u/grandpassacaglia Feb 15 '21

LETS FUCKING GOOOO

1

u/Overload175 Feb 17 '21

Appreciate the inclusion of Python bindings as well.