POSYDON-code/POSYDON

Error encountered with LinearNDInterpolator

Open

#492 opened on Jan 23, 2025

 (2 comments) (0 reactions) (2 assignees)Python (35 forks)auto 404
duplicatehelp wantedquestion

Repository metrics

Stars
 (42 stars)
PR merge metrics
 (PR metrics pending)

Description

When running the postprocessing pipeline to create interpolators (step 4), classes are dynamically fetched. However there is no check on the size of these classes. E.g., there is no check in the following lines for CO-type classes (and similarly no check when dynamically fetching classes based on MT type):

https://github.com/POSYDON-code/POSYDON/blob/4d05dec7ab1e3a96453d5c52af4c89205c63c823/bin/posydon-run-pipeline#L425-L431

This currently can result in an error for some cases with the LinearNDInterpolator() used by posydon/interpolation/IF_interpolation.py. Here is an example traceback from a case where the class (BH) consists of only 3 points

Traceback (most recent call last):
  File "/projects/b1119/ssg9761/POSYDON_v3_test/POSYDON/bin/posydon-run-pipeline", line 1428, in <module>
    train_interpolators(SLURM_I, PATH_TO_CSV_FILE, verbose=VERBOSE)
  File "/projects/b1119/ssg9761/POSYDON_v3_test/POSYDON/bin/posydon-run-pipeline", line 486, in train_interpolators
    interp.train()
  File "/projects/b1119/ssg9761/POSYDON_v3_test/POSYDON/posydon/interpolation/IF_interpolation.py", line 247, in train
    self.interpolators.append(BaseIFInterpolator(grid=self.grid,
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/projects/b1119/ssg9761/POSYDON_v3_test/POSYDON/posydon/interpolation/IF_interpolation.py", line 505, in __init__
    self.in_scaling, self.out_scaling = self._bestScaling(grid.final_values[self.c_key])
                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/projects/b1119/ssg9761/POSYDON_v3_test/POSYDON/posydon/interpolation/IF_interpolation.py", line 1035, in _bestScaling
    out_scaling[c] = scale_one(in_scaling, c)
                     ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/projects/b1119/ssg9761/POSYDON_v3_test/POSYDON/posydon/interpolation/IF_interpolation.py", line 1003, in scale_one
    interp = LinearNDInterpolator(X_T, Y_T)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-merge  _zero-centrum  Qinterior-keepcipy.interpolate.interpnd.LinearNDInterpolator.__init__
  File "interpnd.pyx", line 92, in scipy.interpolate.interpnd.NDInterpolatorBase.__init__
  File "interpnd.pyx", line 330, in scipy.interpolate.interpnd.LinearNDInterpolator._calculate_triangulation
  File "_qhull.pyx", line 1821, in scipy.spatial._qhull.Delaunay.__init__
  File "_qhull.pyx", line 343, in scipy.spatial._qhull._Qhull.__init__
scipy.spatial._qhull.QhullError: QH6214 qhull input error: not enough points(3) to construct initial simplex (need 5)

While executing:  | qhull d Qz Qbb Qt Qc Q12
Options selected for Qhull 2019.1.r 2019/06/21:
  run-id 1661478093  delaunay  Qz-infinity-point  Qbbound-last  Qtriangulate
  Qcoplanar-keep  Q12-allow-wide  _pre-merge  _zero-centrum  Qinterior-keep
  _maxoutside  0

I am able to bypass this error by checking for a minimum size of the class (e.g., that the class has greater than 5 points in this case), but in reading it seems that Qhull should be able to handle any dimensional set of points. Any ideas why this fails here with 3 points?

The shapes of X_T and Y_T are (3, 3) and (3, 7) here, and the docs state that these should have shapes (npoints, ndim) and (npoints, ...), respectively; i.e., the first axis (npoints) of each input matrix should be the same length, which is the case (both 3). I notice that we're interpolating in 3D with tetrahedra, so would the minimum number of points required for triangulation be 4? (I'm not sure why the error says 5 points are needed here. Artificially adding an extra point such that we have shapes (4, 3) and (4, 7) does resolve the error as well.)

Contributor guide