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

Voronoi silently crashing if duplicates or out of box points #841

Open
Optimox opened this issue Sep 22, 2021 · 0 comments
Open

Voronoi silently crashing if duplicates or out of box points #841

Optimox opened this issue Sep 22, 2021 · 0 comments

Comments

@Optimox
Copy link

Optimox commented Sep 22, 2021

Describe the bug
As discussed in #839, there are two ways to make the voronoi computation silently crash currently:

  • giving points with a duplicated point
  • giving points with one point outside the original box

I guess those two configurations could be checked automatically before launching the computation and return clear errors about what's the problem.

To Reproduce

This code should be enough to reproduce the duplicated part:

import numpy as np
import freud
import time
from matplotlib import pyplot as plt

def check_inside_box(points, freud_box):

    Lx, Ly, Lz = freud_box.Lx, freud_box.Ly, freud_box.Lz
    if Lz == 0:
        # for 2D don't take Lz into account
        Lz = 1000
    is_x = (points[:, 0] <= Lx/2) & (points[:, 0] >= -Lx/2)
    is_y = (points[:, 1] <= Ly/2) & (points[:, 1] >= -Ly/2)
    is_z = (points[:, 2] <= Lz/2) & (points[:, 2] >= -Lz/2)
    return (is_x & is_y & is_z)

L = 100


freud_timings = []
numpy_timings = []
N_points = range(100, 6000, 1000)

for n_points in N_points:
    print(f"Num points : {n_points}")

    points = np.random.randint(2, L-2, (n_points, 3))
    # center the points
    points = points - np.array([L/2, L/2, L/2])
    
    # MAKE SURE THERE ARE NO DUPLICATED POINTS
    # I consider this a bug of the library
    # without this if you have duplicates the code will crash with no error
    # it simply kills the kernel
    points = np.unique(points, axis=0)
    
    
#     points = points.astype(np.float32)

    box = freud.box.Box(Lx=L, Ly=L, Lz=L, is2D=False)

    voro = freud.locality.Voronoi()

    voro.compute((box, points));

    start = time.time()
    nlist = voro.nlist
    print(f"Computation for neighbors list took {time.time()-start:.5f} seconds")

    start = time.time()
    unwrapped_bonds = points[nlist.query_point_indices] \
                    + box.wrap(points[nlist.point_indices] \
                    - points[nlist.query_point_indices])
    print(f"Computation for wrapped points took {time.time()-start:.5f} seconds")


    start = time.time()
    real_connections = check_inside_box(unwrapped_bonds, box)
    numpy_timings.append(time.time()-start)
    print(f"Computation for numpy box containing took {numpy_timings[-1]:.5f} seconds")

    start = time.time()
    slow_real_connections = box.contains(unwrapped_bonds)
    freud_timings.append(time.time()-start) 
    print(f"Computation for freud box containing took {freud_timings[-1]:.5f} seconds")
    assert(np.all(slow_real_connections==real_connections))
    
fig = plt.Figure()
plt.plot(N_points, freud_timings, color="red")
plt.plot(N_points, numpy_timings, color="green")
plt.show()

Error output
It's a sudden crash without errors.

System configuration (please complete the following information):

  • Version of freud '2.6.2'
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

No branches or pull requests

1 participant