This PR is a first-attempt to close #14 . Turns out it was much easier than I expected to use numba to speed up the compute_Absorption() and compute_Absorption_fixed_cutoff() functions in Absorption_Crosssections_HITRAN2016.py.
To do this, I've made a separate file called Absorption_Crosssections_HITRAN2016_numba.py, and added a use_numba option to the OpticalThickness calculation. Currently it works exactly the same as before, but if you set use_numba=True (for example, in Test01.olr/compute_olr_h2o_numba.py) then the new, numba-accelerated functions are imported from Absorption_Crosssections_HITRAN2016_numba.py.
The code in Absorption_Crosssections_HITRAN2016_numba.py is quite similar to it's non-numba counterpart, but I've made some (minimal) changes to the structure so that it works with numba. For example, I've made separate functions for getGamma() and genAbsgrid(), because numba was having trouble dealing with those functions/lambdas in-loop.
In terms of speed up, on my Macbook Pro Test01.olr/compute_olr_h2o.py takes ~12 seconds to run, whereas Test01.olr/compute_olr_h2o_numba.py takes ~6 seconds to run the first time round (during numba's compilation procedure), but for everytime after that it takes ~3 seconds!
It's not a crazy speed-up, but given how easy it was to implement, I'm happy with a 4x increase in performance.
I think it would be helpful to implement some tests in PyRADS so that we can be sure that numba isn't changing any of the results. Perhaps this could happen next?
This PR is a first-attempt to close #14 . Turns out it was much easier than I expected to use numba to speed up the
compute_Absorption()
andcompute_Absorption_fixed_cutoff()
functions inAbsorption_Crosssections_HITRAN2016.py
.To do this, I've made a separate file called
Absorption_Crosssections_HITRAN2016_numba.py
, and added ause_numba
option to theOpticalThickness
calculation. Currently it works exactly the same as before, but if you setuse_numba=True
(for example, inTest01.olr/compute_olr_h2o_numba.py
) then the new, numba-accelerated functions are imported fromAbsorption_Crosssections_HITRAN2016_numba.py
.The code in
Absorption_Crosssections_HITRAN2016_numba.py
is quite similar to it's non-numba counterpart, but I've made some (minimal) changes to the structure so that it works with numba. For example, I've made separate functions forgetGamma()
andgenAbsgrid()
, because numba was having trouble dealing with those functions/lambdas in-loop.In terms of speed up, on my Macbook Pro
Test01.olr/compute_olr_h2o.py
takes ~12 seconds to run, whereasTest01.olr/compute_olr_h2o_numba.py
takes ~6 seconds to run the first time round (during numba's compilation procedure), but for everytime after that it takes ~3 seconds!It's not a crazy speed-up, but given how easy it was to implement, I'm happy with a 4x increase in performance.
I think it would be helpful to implement some tests in
PyRADS
so that we can be sure that numba isn't changing any of the results. Perhaps this could happen next?