refactor: neighbours are now exposed by the neighbour lists themselves#60
Conversation
Codecov Report❌ Patch coverage is
... and 1 file with indirect coverage changes 🚀 New features to boost your workflow:
|
|
I did some tests, and for LinkedList there is actually a huge performance hit from this implementation. |
|
I updated the implementation, which removed the performance bottleneck arising from using Feel free to challenge the content of this PR! |
|
I like the idea of using |
I went with a mix of your suggestion and what was previously done: neighbour lists are now callable, and return an iterator. |
|
I finally found the bug that caused the unit test to fail. Commit be8c121 fixed that. I'm shocked that such a small change affects the run time by a factor 3. I find the linked list iterator extremely complicated for what is essentially a while loop in a for loop. |
|
Thanks a lot @V-Francois for this nice refactor :) |
4ffa6c4
into
TheDisorderedOrganization:main
Summary
This PR moves all neighbour-list related logic to the neighour subpackage, so that all other modules are agnostic of the underlying implementation.
This is accomplished by making each neighbour list type callable (with
systemandiare arguments). The call to the instances return generators, that when iterated upon return the indices of all the particles adjacent toi.The methods to compute energies leverage these newly defined methods instead of encoding the neighbour list logic themselves.
Implementation discussion
For linked lists, I wasn't able to return a simple generator in the dedicated calling function. It looks like Julia doesn't have some of the features that would be required to create custom generators (something like the
yieldkeyword in Python).Instead, I created a new struct that is used to iterate over.
This adds some complexity and makes the iteration process less clear, which is opposite to the goal of this PR.
I believe this complexity is inherent to the linked list algorithm, and is now fully contained in the implementation of this list (rather than spread to other parts), so I'd argue that this PR still improves overall clarity.
Test plan
CI, which contains tests that rely on these lists.
Locally, tests on a polymer chain.
Currently, unit tests on molecules fail - need to be fixed.