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 kernel functions for tesseroid forward modeling #118

Merged
merged 47 commits into from Mar 11, 2015

Conversation

Projects
None yet
1 participant
@leouieda
Member

leouieda commented Jul 21, 2014

Separate the tesseroid functions into kernels. Clean up the Cython code (very messy and not very fast) and make more/better tests.

Fixes #114

Tasks:

  • Separate the tensor components into "kernel" functions.
  • Speedup computations, if possible.
  • Better docs for gravmag.tesseroid.
  • Increase test coverage.
  • Update ratio values based on paper results
  • Update algorithm to match method paper

Checklist:

  • More complete methods in module docs (UPDATE: will include citation later)
  • Create/update docstrings
  • Make tests for new code
  • Tests against spherical shell values
  • All tests pass
  • Can be merged
  • Changelog entry
  • Benckmark
  • At least as fast

leouieda added some commits Jul 21, 2014

Gather tesseroid vs spherical shell tests
Using a single function and looping over module functions.

@leouieda leouieda modified the milestones: 1.0, 0.3 Jul 21, 2014

@leouieda leouieda self-assigned this Jul 21, 2014

leouieda added some commits Jul 22, 2014

In the middle of separating tesseroid functions
Didn't have time to check. Probably broken.
Moved model iteration out of optimal discretize
This will allow future magnetic functions to get the magnetization from
the tesseroids without having to modify the discretization code.
Also made some aesthetic changes to the Cython code.
Updated benchmark for tesseroid
Profiling code need update for new function names
Using collections.deque for the queue
Docs say it is more efficient. Benchmark says it doesn't make much of a
difference. Still, better use it just in case.
Dont precalc distance, stop alloc in too_close
In gravmag.tesseroid:
Moved distance calculating into too_close.
Sorting input 'points' array instead of allocating a buffer and
splitting that.
too_close now returns the index that splits 'points' into don't need
division and need division.
Using sincos to calculate sin and cos at the same time.
Raise a ValueError if trying to calculate directly on top of the
tesseroid.
Check the Fatiando vs Tesseroids result
In the benchmark, just run a quick check if they are equal.
Added check for input shape and more tests
Improved tests for tesseroid and added check if the input arrays have
the same shape.
Need to try, except import of _tesseroid for docs
Docs wont build because of importing _tesseroid extension module. Need
to make it a silent import error for now (bad solution).
@leouieda

This comment has been minimized.

Member

leouieda commented Jul 24, 2014

@birocoles could you please take a look at the new code here? It's in tesseroid.py and the Cython module _tesseroid.pyx. The kernelxx, etc, functions are only in _tesseroid.pyx.

We should start doing this kind of review more often. Doing it only at the end of a project is not very good because things get complicated.

Removed obsolete numpy version of tesseroid
Wasn't even suitable for testing anymore.

@leouieda leouieda added this to the 0.4 milestone Oct 14, 2014

leouieda added some commits Oct 24, 2014

Merge branch 'master' into tesseroid-kernels
Conflicts:
	doc/changelog.rst
Trial recursive implementation for gzz
Getting Float 0 division errors. Not sure where.
Fixed Float division error and switched to queue
Moved the queue inside Cython kernel function. This resulted in a faster
implementation than the Tesseroids recursive one for gzz.
Need to refactor code into smaller functions and reusable part. That's
why I didn't commit the C files as well to avoid clutter.
Separated gzz into funcstions and profiled
Moved some things around and got rid of some Python variable conversions
to get a decent speedup. Got it faster than C.
Need to implement a queue in Cython to be able to release the GIL and
use prange.
Trade collections.deque for a numpy array
Results in ~2x speedup with respect to latest build of Tesseroids.
Could release the GIL for the data loop, making use of prange possible.
Use Cython function pointer to separate kernels
Separated the data loop and redistretization into a cdef function and
pass a pointer to the kernel.
PEP8 fix on tesseroid test
Few changes to benchmark as well
Moved all fields to new Cython rediscretization
Got consistent speedups with respect to Tesseroids implementation. The
biggest gains are in gzz
Test tesseroid raises exception on queue overflow
Passing queue size as an argument to the Cython functions.
Merge branch 'master' into tesseroid-kernels
Conflicts:
	doc/changelog.rst
Bug fix in queue overflow check
Number of new elements is nlon*nlat*nr not +
Using normal law of cos to calculate size
As is being done in Tesseroids. The Vicenty formula was not necessary
and took longer to calculate.

leouieda added some commits Mar 10, 2015

Merge branch 'master' into tesseroid-kernels
Conflicts:
	doc/changelog.rst
	fatiando/gravmag/_tesseroid.c
Updated tesseroids ratios and distance
The distance is measured to the center of the tesseroid.

Test trying to raise an overflow error is failing.
Fix overflow test
The test that was breaking was checking for overflow with default queue
size at h=1. This didn't overflow anymore with the new distance
calculation. Adapted to use queue size =  20  and calculate at h=0. Now
overflows.
Test against spherical shell
Check is all tesseroid results are within 0.1% of the shell values.
Had to adjust gz ratio to 1.6 for tests to pass.

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

Merge pull request #118 from fatiando/tesseroid-kernels
Implement kernel functions for tesseroid forward modeling

@leouieda leouieda merged commit 53a39a7 into master Mar 11, 2015

2 checks passed

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

@leouieda leouieda deleted the tesseroid-kernels branch Mar 12, 2015

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