Closed claresinger closed 2 years ago
@claresinger please try using sigma.py_func() instead of sigma() to actually use the underlying Python function HTH
BTW, we've updated the arXiv e-print of the PySDM JOSS paper: https://arxiv.org/abs/2103.17238.pdf
Stale issue message
@slayoo I'm getting another funny error when I try to use the Ruehl surface tension. Error is that it doesn't recognize the scipy
module.
I'm trying to run this notebook with the 4 different versions of surface tension to make 4 kohler curves. https://github.com/claresinger/PySDM-examples/blob/cf_ruehl/PySDM_examples/Singer/kohler.ipynb
please try importing scipy within the function
Thanks @slayoo. Importing within the function works, but only if I call sigma.py_func(...)
. What's the problem with importing outside the class like in this file? e.g. https://github.com/atmos-cloud-sim-uj/PySDM/blob/c2a5615484242b7f7a1d3560557f51fe2adb4e2d/PySDM/physics/coalescence_kernels/golovin.py#L5
Or how can I avoid needing the py_func()
? I guess this turns off the numba compilation?
In general, whatever is within the formulae is supposed to have a form of a one-liner that can be interpreted as C code on GPU. Whatever needs more than one-line logic would go to the backend API and have a separate implementation for CPU and GPU.
Having the above as a starting point, and aiming at tackling the Numba global caching problem, there is now an eval
statement used within Formulae to implement constants substitution. This eval statement makes the outer imports "disappear". For use with parcel model, anyhow Numba is slowing things down rather than speeding up, and we do not use here the GPU backend, so I'd say that using py_func is OK?
Sorry, it's exec
not eval
, here:
https://github.com/atmos-cloud-sim-uj/PySDM/blob/master/PySDM/formulae.py#L130
Just to be clear, does that mean the golovin kernel also will error *because scipy
is not imported? **edit
And numpy
still works because it's explicitly included in that exec
call, right?
For now, I can definitely just add the py_func
, but it might be preferable to have a way of importing modules that still allows numba to be used, no?
The kernels are not part of the Formulae
"infrastructure", hence no code there is automagically njitted or converted to C.
Numpy works indeed because it is explicitly included in that exec.
The point is that all what is handled by the Formulae class is supposed to be njittable and best if C-convertible. Nothing besides numpy is available in Numba njitted code, same for translation to C.
I've just noted here: https://github.com/atmos-cloud-sim-uj/PySDM/issues/726 that it would be best to move the kernels code out of "physics" not to mislead that it shares the logic with things handled from within Formulae class
In other words (I'm aware this is puzzling):
Formulae
class automates njitting and C translation of code in physics folder which is simple enough (i.e., one-liners using numpy only) that can be automatedIs the solution to this that
scipy
, orFormulae
, orIs there something else smarter/easier that can be done?
Let's first make it work with py_func, have it test covered and merged, then we can think of refactoring.
I opened 2 PRs to try to add tests. It's working well with py_func in my notebooks.
https://github.com/atmos-cloud-sim-uj/PySDM/pull/727 https://github.com/atmos-cloud-sim-uj/PySDM-examples/pull/118
Error in PySDM Ruehl surface tension implementation in the step where
f_surf
is found iteratively. @slayoo I'm not familiar with this numba error. Any help?https://github.com/claresinger/PySDM-examples/blob/cf_ruehl/PySDM_examples/Singer/fig_1.ipynb