librascal
librascal copied to clipboard
Segfault with bad values of max_radial/max_angular
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 |
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
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