Optimize harmonic processing speed with numba #36
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi! Thank you very much for the code, I use it heavily on my thesis.
As mentioned in #7 which one of the todo list items is to convert the code to low level language to increase the performance, here I provide a
numba-optimized code forrfpy.harmonics.numbatranslates Python functions to optimized machine code at runtime, it can be an alternative or temporary solution to performance optimization without rewriting the code to lower level language.I optimized
rfpy_harmonicsand created a simple performance comparison by running the script for station MMPY for 9 different scenarios depending on the number of receiver functions (nrf), each of the scenario is executed based on two cases: with and without numba.The device and environment for testing:
ROG Zephyrus G14 GA401QH_GA401QH
AMD Ryzen 7 5800HS with Radeon Graphics (16 CPUs), ~3.2GHz
8192MB RAM
Ubuntu 18.04 WSL2, Windows 11
Python 3.8.13
The input parameters and the result:
Table:
Graph:
As shown on the table and graph,
numbacan significantly increase the performance.Changes
_dcomp_calculate_harmonics_isolatedstatic method to isolate harmonics calculation based onnumba,obspy.Streamobject in this function is converted tonumpy.arrayto accomodatenumbause_numbaas argument forrfpy.harmonics.Harmonic.dcomp_find_azim, when this argument is True then the processing will be executed bynumbatqdmandnumba_progressbar--use-numbaargument forrfpy_harmonicsnumbaandnumba_progressbarinsetup.pyrfpy.rstandtutorial.rstNotes
numbaas mentioned here, canceling processing with CTRL+C is currently not supported. Actually I have managed to successfully solve this problem on branchharmonics-numba-sigintbut it requires GCC (Linux) or MSVC (Windows) to work.numbaas mentioned here and here. For example, when running the first scenario on the table (137 nrf), the variances of C1 for index 83 and 173, corresponding to azimuth 166 and 346 respectively:numbawill be a little bit slower in the first run because of compilationScreenshots