lab-cosmo / librascal

A scalable and versatile library to generate representations for atomic-scale learning
https://lab-cosmo.github.io/librascal/
GNU Lesser General Public License v2.1
80 stars 17 forks source link

Segfault with bad values of max_radial/max_angular #393

Open Luthaf opened 3 years ago

Luthaf commented 3 years ago

Another discovery by @bananenpampe. The following code segfaults:

from rascal.representations import SphericalInvariants

hypers = {
    "soap_type": "PowerSpectrum",
    "interaction_cutoff": 3,
    "radial_basis": "GTO",
    "max_radial": 0,
    "max_angular": 9,
    "gaussian_sigma_constant": 0.3,
    "gaussian_sigma_type": "Constant",
    "cutoff_function_type": "ShiftedCosine",
    "cutoff_smooth_width": 0.5,
    "normalize": True,
}

soap = SphericalInvariants(**hypers)

I think this should throw an error instead!


Other invalid combinations:

max_radial max_angular expected actual
1 0 OK OK
0 1 Error segfault
0 0 Error segfault
0 -1 Error segfault
1 -1 Error segfault
1 -3 Error std::bad_alloc
-1 1 Error std::bad_alloc
agoscinski commented 2 years ago

I am working on a PR making the json reading of cpp files more user friendly #376 (at the moment json error is returned which basically only tells you that somewhere in the hypers there is a parameter wrong). I can add also checks for max_angular and max_radial

agoscinski commented 2 years ago

so annoying, on the c++ side we use size_t, so one has to do the check on the python side. I really think size_t is always a bad choice for user input

EDIT: I can also read temporary an int and then convert it to size_t