radiasoft / rswarp

Python utilities specific to running Warp
Other
5 stars 5 forks source link

ConductorTemplates _norm_factor field no longer available in scipy #23

Open moellep opened 3 years ago

moellep commented 3 years ago

A recent change to scipy.stats.gaussian_kde is the removal of the _norm_factor field which rswarp is depending on here:

https://github.com/radiasoft/rswarp/blob/47cc514bcca20becd043f9f981a661b000ad223f/rswarp/diagnostics/ConductorTemplates.py#L63

This is causing sirepo/warpvnd simulations to fail on the Visualization page with the error 'gaussian_kde' object has no attribute '_norm_factor'.

ncook882 commented 3 years ago

@moellep It looks like the commit https://github.com/scipy/scipy/commit/e04c172ab20810a79e15949a1b1a061e540b780c to scipy.stats removed the _norm_factor as an attribute for the kde, and replaced it with some slightly different intermediary calculations. The previous calculation relied on computing the determinant of the covariance matrix for the kernel to compute a normalization factor. Unfortunately, for singular matrices, some decomposition methods will fail and throw an error.

I've added a fix https://github.com/radiasoft/rswarp/commit/eadb1bef78b130cd988fb2dfb86e86e825aae852 which recreates the previous calculation of the _norm_factor, and excepts LinAlgErrors when the matrix is singular or the determinant cannot be computed.

This fix should allow you to use the most recent version of SciPy.