Skip to content

added Cython PBC#2007

Closed
richardjgowers wants to merge 8 commits intodevelopfrom
new_pbc
Closed

added Cython PBC#2007
richardjgowers wants to merge 8 commits intodevelopfrom
new_pbc

Conversation

@richardjgowers
Copy link
Copy Markdown
Member

@richardjgowers richardjgowers commented Jul 25, 2018

So in #1996 @seb-buch introduced some code (originally from gromacs) which featured a different way of doing PBC for triclinic boxes. Our current method searches all neighbouring images to find the closest, the gromacs approach builds a list of images to search (based on box geometry) and then only searches these if required.

I went ahead and rewrote it a little to work for all cases, I think it's an improvement over our current solution of C header + Cython.

How to read this PR:

  • new_distances.pyx shows how distance_array looks with the new PBC function
  • pbc.pyx is mostly lifted and trimmed from Gromacs. It defines a PBC object (box with extra info attached) and a minimum_image function which expects the PBC and a separation

Pros:

  • Cython reads much nicer than C
  • gets rid of all our different functions (we currently have 3 C functions for each function in lib.distances
  • faster (about 4x faster for triclinic boxes, orthogonal performance the same)

Cons:

  • not sure I can get the openmp thing to work again. There is cython.prange though (I think parallelism like pmda is the way to go anyway though)

Copy link
Copy Markdown
Member

@kain88-de kain88-de left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you using the shifts that are calculated?

dx_start[j] = dx[j]

i = 0
while (d2min > pbc.max_cutoff2) and (i < pbc.ntric_vec):
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kain88-de this seems to be using the shifts

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part is missing from @seb-buch conversion in the ns-grid code. This is why I'm interested in maxcutoff2. The code has two max cutoff value and I don't see the difference right away.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/gromacs/gromacs/blob/7b95d9dd145fcf9141b5aa489c47920a3c2e2cc3/src/gromacs/pbcutil/pbc.cpp#L170

This is where it's taken from. WRT two max cutoffs, is this how it looks at both orthogonal and triclinic box vectors?

for j in range(i, -1, -1):
dx[j] += pbc.box[i][j]
d2min = norm2(dx)
if d2min > pbc.max_cutoff2:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you explain what max_cutoff2 is and when this condition is met? I think it will also affect the code from @seb-buch for the ns-grid.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's only used for triclinic conditions, and I think @seb-buch said that his grid code remaps a triclinic cell to orthogonal conditions, so shouldn't affect that afaik.

This is what I got confused about yesterday, as the tric_vec stuff was removed.

@richardjgowers
Copy link
Copy Markdown
Member Author

richardjgowers commented Jul 26, 2018 via email

@codecov
Copy link
Copy Markdown

codecov bot commented Jul 26, 2018

Codecov Report

Merging #2007 into develop will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           develop   #2007   +/-   ##
=======================================
  Coverage     88.5%   88.5%           
=======================================
  Files          143     143           
  Lines        17249   17249           
  Branches      2646    2646           
=======================================
  Hits         15267   15267           
  Misses        1385    1385           
  Partials       597     597

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b50c6f0...1aeabe0. Read the comment docs.

@kain88-de
Copy link
Copy Markdown
Member

not sure I can get the openmp thing to work again. There is cython.prange though (I think parallelism like pmda is the way to go anyway though)

not in such a nice way that we have right now. The openMP gave a nice speed boost though. I still like to have this though if it covers more cases. We should first strive to be correct.

@richardjgowers
Copy link
Copy Markdown
Member Author

@kain88-de so this method seems to give correct triclinic distances. Did you have a good method for finding difficult cases when you looked at it before? Or just generate random coordinates with smallish angles in the triclinic cell?

@richardjgowers
Copy link
Copy Markdown
Member Author

Ok thinking about it, I think we can just do the same trick. Cython just spits out some C with openmp sections, we compile whatever Cython spits out twice, once with openmp flags once without.

@RMeli RMeli deleted the new_pbc branch February 18, 2025 21:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants