New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement tesseroid forward modeling using numba #175

merged 18 commits into from Mar 13, 2015


None yet
2 participants

leouieda commented Mar 11, 2015

I needed to update the tesseroids implementation here to match the one in Tesseroids. There was a lot I had to change so I figured I could also try to do it in numba. It was pleasantly easy to implement the adaptive discretization with numba and the preliminary benchmarks show that it matches the speed of Cython. All this without any compiled code at install time (see #169).

As a bonus, I implemented a simple parallelism by splitting the computation grid into chunks and passing it to multiprocessing.Pool. This is embedded in each function and can be activated by the njobs argument. It will run in serial by default so that it doesn't interfere with other parallel code.

Note: A big thanks to @gmarkall for helping with my initial doubts and getting this started!

I also made a version using pure Python + numpy for benchmarks and to use in testing. It is used as a fail-safe if numba is not available. For tesseroids this version is much slower (~100x). For the prism, sphere, etc it won't be. So it is a viable alternative to have.


  • Remove old Cython code
  • Make tests for new code
  • Make tests for parallel execution
  • Create/update docstrings
  • Include relevant equations and citations in docstrings
  • Code follows PEP8 style conventions
  • Code and docs have been spellchecked
  • Include new dependencies in docs, requirements.txt, README
  • Documentation builds properly
  • All tests pass
  • Can be merged
  • Changelog entry

leouieda added some commits Mar 10, 2015

Reorganizing functions be handle diff engines
Want to allow an 'engine' option to choose between numpy and numba
Merge branch 'master' into tesseroid-numba
Added get engine and func to choose density
These things are called from all other functions so put them separately.
Initial numba implementation of tesseroid gravity
Missing docstrings and more comments. I'm copy/pasting the adaptive
discretization for each field because callbacks aren't supported.
An alternative would be to use closures but those seem to give slower
results. Need to investigate.
Adapted gz to use the numba kernel
Added many helper functions to sanitize inputs, pre-compute
degree-radian transformations, etc.
Supports parallel execution by splitting the grid and spreading over
Copied other fields to numba implementation
All tests passing except comparison to numpy version (because it doesn't

@leouieda leouieda added this to the 0.4 milestone Mar 11, 2015

leouieda and others added some commits Mar 11, 2015

Made numpy version of tesseroid effects
Moved the kernels from the numba version over to the numpy version (they
are the same). The numba module now only loads them from the numpy
version and jit compiles.
Remove tesseroid Cython files
Both the pyx and C source
Cleaned up the numba code a bit
Gave different functions names and moved things around. Nothing much.
Added more docstrings and better module docstring
Included the new arguments in functions docs. Merged the make_buffers
function into the adaptive discretization.

leouieda added a commit that referenced this pull request Mar 13, 2015

Merge pull request #175 from fatiando/tesseroid-numba
Implement tesseroid forward modeling using numba

@leouieda leouieda merged commit 490a0b9 into master Mar 13, 2015

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
continuous-integration/travis-ci/push The Travis CI build passed

@leouieda leouieda deleted the tesseroid-numba branch Mar 13, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment