sandialabs/n2a

Python: Create pybind11 wrapper for C

frothga opened this issue · 0 comments

There are two general options for a Python backend: generate pure Python code or wrap compiled C code so it can be accessed from Python. It seems that pybind11 can provide access to nearly every variable and function of the generated C code, so this appears to be the better option. It may be a little more complicated to use, but will provide faster code and better parallelization. In this approach, the main use of Python is as a scripting wrapper, perhaps to integrate the simulation with other software. We should also add some callback hooks in the main simulator loop so that each step can controlled from the script interface.

The Python backend will include a code generator that extends the C generator. It will add the pybind11 statements, then compile a shared library. It will also generate a simple Python scripts that imports and runs the simulation. These files can go in a job directory, and the Python backend will support actually running the simulation as usual. The files could also be exported to an arbitrary location.