Skip to content
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

BUG: force contiguous calling find_points_in_spheres #3108

Merged
merged 2 commits into from
Jun 26, 2023

Conversation

lbluque
Copy link
Contributor

@lbluque lbluque commented Jun 26, 2023

Checklist

  • Google format doc strings added. Check with ruff.
  • Type annotations included. Check with mypy.
  • Tests added for new features/fixes.

Tip: Install pre-commit hooks to auto-check types and linting before every commit:

pip install -U pre-commit
pre-commit install

@shyuep
Copy link
Member

shyuep commented Jun 26, 2023

Quick qn: what is the purpose of this? Speed up?

@lbluque
Copy link
Contributor Author

lbluque commented Jun 26, 2023

Having the arrays contiguous makes it faster., which I had already added in the previous PR #3015.

However, we noticed that when called internally by a structure where the lattice matrix or frac_coords had been changed in such a way (such as applying strain) that the arrays were not contiguous then the call to the cython function would raise errors.

@janosh
Copy link
Member

janosh commented Jun 26, 2023

@shyuep Just for context, this came up in CederGroupHub/chgnet#39 where tests were failing with

chgnet/graph/converter.py:142: in get_neighbors
    center_index, neighbor_index, image, distance = structure.get_neighbor_list(
/opt/hostedtoolcache/Python/3.8.17/x64/lib/python3.8/site-packages/pymatgen/core/structure.py:1533: in get_neighbor_list
    center_indices, points_indices, images, distances = find_points_in_spheres(
pymatgen/optimization/neighbors.pyx:49: in pymatgen.optimization.neighbors.find_points_in_spheres
    ???
stringsource:660: in View.MemoryView.memoryview_cwrapper
    ???
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

>   ???
E   ValueError: ndarray is not C-contiguous

@lbluque Thanks for the really fast fix and unit test. 👍 Makes me sleep better every time we add a new test. 😄

@shyuep shyuep merged commit 7818bba into materialsproject:master Jun 26, 2023
@shyuep
Copy link
Member

shyuep commented Jun 26, 2023

Thanks.

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.

3 participants