-
Notifications
You must be signed in to change notification settings - Fork 652
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
WIP: Cython port of contact map functions #375
WIP: Cython port of contact map functions #375
Conversation
Simple Cython implementation. Instead of the other functions in distances.pyx I have used pure cython for clarity. The loop is converted to pure C except for saving the sparse matrix element.
Hey, This looks like a good start. To run a subset of tests, from a command line in the directory
More details here: This should then let you see the two tests that fail on Travis (scroll to bottom): If you're not sure a test is running, the quickest way to check is to change the reference state (your Let us know if you need any more help |
The test are currently only run for the dense arrays.
1886597
to
af65ed5
Compare
Ok I got the new test running and it passes like it should. The current sparse test is failing though due to an error in the cython code. My next problem is that installing the changes with Sorry for all the questions but this is badly/not documented in the wiki. |
My workflow is to run If that doesn't do it, deleting |
Due to a typo I calculated the distance between points on different axes instead of on the same one.
Yeah got it working now. Installing cython in the virtual-env and removing the c file did it. I have noticed that the return values between the numpy and sparse matrix are inconsistent. For the numpy array the diagonal of the contact-matrix is true. But for sparse matrices the diagonal is set to false. Personally I would prefer if if the diagonal elements were always true independent of the chosen return-type. |
It's not documented either way, so we can go with the diagonal being True (update the docstring and tests) unless anyone objects. The only thing in the package that uses contact_matrix current is To do the PBC versions, it might be a good idea to import |
Simple port. I'm currently not using any of the helper functions defined in calc_distances.h
8f88666
to
2b92835
Compare
Btw is the progressbar feature still required? Without it it should be straight forward to add these functions to |
I wasn't too sure how easy it'd be to fill a np sparse matrix in C though? |
The progressbar feature is not really necessary inside the cython code; feel free to get rid of it, especially if it makes the code cleaner. |
Only calculate the distances for the upper triangle contact matrix. The other entries are already determined through the symmetry. This also sets the contacts along the diagonal automatically to true.This should save about half of the operations.
This makes the behavior consistent regardless of the chosen return type.
The refactored tests don't depend on any external test-data anymore. This has two nice effects. Giving the coordinates explicitely makes it easy to see where a contact is and the tests now run over a 100 times faster. Plus everything looks a lot more cleaned up.
I reordered some variable assigment and calculate the squares directely instead of using `pow`. This can lead to performance improvements on some platforms.
b95dadb
to
ac0acb0
Compare
I added some changes
|
Ok this is looking good, nice catch with the reflection. There's actually a minor bug in the code you've translated, (was present before so not your fault), I've left a line comment, if you can fix that up then we're good to go. Other minor things to do:
|
y = xyz[i, 1] - xyz[j, 1] | ||
z = xyz[i, 2] - xyz[j, 2] | ||
|
||
if abs(x) > box_half[0]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will only add/subtract a single box_view
from each dimension, but it needs to do it multiple times where necessary.
So if box_half = 10
then x = 1 = 11 == 21 = 31
, and x = 1 = -9 = -19
You can either import the minimum_image
function from calc_distances.h
which does this, or inline that into here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. I always assume that particles are in one of the neighboring images and then wonder that happened when this is not the case. I will first add this to the unit-tests and then fix it.
Two points with PBC can be further apart then one image. The test now checks that as well. The numpy pbc function already passes this. The sparse version still assumes that a point is maximally in a neighboring image.
Now also points that are several images apart are handled correctly. All tests are passing.
PBC are handled correctly with |
Btw should I regenerate the documentation or is this done automatically with a git-hook when this PR is merged? |
Docs are not generated automatically (yet). There is a page in the wiki outlining the procedure but in the end someone with write access has to merge the develop branch with docs into the gh-pages branch. Oliver Beckstein Am Aug 4, 2015 um 2:55 schrieb kain88-de notifications@github.com:
|
Docs are updated now. Sphinx has rebuild almost all the doc pages but I have only included the one affected by this PR. |
I had a quick look and it seems fine but I let @richardjgowers do the final approval and merge. Thanks @kain88-de ! |
WIP: Cython port of contact map functions
I want to fix #264. The non PBC version is already implemented in Cython and the tests are passing as well. The Cython-implementation is also faster using the 1Q0W protein.
Porting the PBC version I noticed that there are no tests for it. I added a test and the test suite is still passing. But I'm not sure if the test I have added is run. Btw I'm new to nose is there a way to specify a subset of tests that I want to run instead of executing the whole test-suite all the time?
If someone can help me get the test-cases for the PBC-case running I will also port the PBC version.
Here is a short description how I run the test-suite since I couldn't find up-to-date information how to set-up a dev environment or run unit-tests.
For testing I'm using the approach defined in the
travis.yml
, but I installed all dependencies via pip.After each change in either the package or testsuite folder I reinstalled them with
pip install --upgrade <folder>/