E3SM icon indicating copy to clipboard operation
E3SM copied to clipboard

EAMxx: allow atmosphere processes to call python code

Open bartgol opened this issue 7 months ago • 3 comments

This PR adds the possibility for atm procs to create py bindings of their fields and call py code at runtime.


So far, I only added a test running a py impl of cldfrac instead of the C++ code.

Btw, I think the test is exposing the fact that the outputs of the test were all 0's, which I don't think was expected. I have to dig a bit.

bartgol avatar Jun 03 '25 04:06 bartgol

Good start, but I don't think we should integrate this as-is. Feel free to push back... I think we should be strive to unify our approach with the pyeamxx nanobind interfacing...

Unfortunately, I had to abandon nanobind, since it's not meant to be used for calling Python from C++. It's purpose is to wrap C++ code in a py module, so you can call from python. I asked this to both snl and google AI bots, and both came up with the same explanation (more or less what I said above). I spent a day trying to figure out why passing a nb::ndarray to python would segfault, and eventually tracked it down to that reasoning. Both AI bots suggested pybind11 for calling py from c++...

bartgol avatar Jun 03 '25 19:06 bartgol

Good start, but I don't think we should integrate this as-is. Feel free to push back... I think we should be strive to unify our approach with the pyeamxx nanobind interfacing...

Unfortunately, I had to abandon nanobind, since it's not meant to be used for calling Python from C++. It's purpose is to wrap C++ code in a py module, so you can call from python. I asked this to both snl and google AI bots, and both came up with the same explanation (more or less what I said above). I spent a day trying to figure out why passing a nb::ndarray to python would segfault, and eventually tracked it down to that reasoning. Both AI bots suggested pybind11 for calling py from c++...

That's surprising but ofc you're right: https://github.com/wjakob/nanobind/discussions/302

Ok, then the main objection is gone; we will move the pyeamxx stuff from nanobind to pybind11 later after seeing where this effort reaches...

mahf708 avatar Jun 03 '25 19:06 mahf708

Uhm, I realized that there is no test of this feature anywhere. Maybe I need to enable the py support in our CI.

Edit: I enabled it in our CPU ci machine file only.

bartgol avatar Jun 05 '25 18:06 bartgol

Closing for now. Will reopen when I fix a few things.

bartgol avatar Jul 04 '25 02:07 bartgol