From 9e4f55ac1f3664cae712c27c8d1478043e2639b7 Mon Sep 17 00:00:00 2001 From: Tanjona Rabemananjara Date: Mon, 2 Feb 2026 18:45:42 +0100 Subject: [PATCH 1/4] Raw fix of `NaN` subgrids at N3LO --- src/yadism/coefficient_functions/heavy/n3lo/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/yadism/coefficient_functions/heavy/n3lo/__init__.py b/src/yadism/coefficient_functions/heavy/n3lo/__init__.py index 7f0957247..fdcd8552b 100644 --- a/src/yadism/coefficient_functions/heavy/n3lo/__init__.py +++ b/src/yadism/coefficient_functions/heavy/n3lo/__init__.py @@ -20,6 +20,7 @@ def interpolator(coeff, nf, variation): # load grid coeff = np.load(grid_path / grid_name) + coeff = np.nan_to_num(coeff, nan=0.0) grid_interpolator = RectBivariateSpline(xi_grid, eta_grid, coeff) # store result From 19249171c047241ebe56fc54cd2322fe22af94a5 Mon Sep 17 00:00:00 2001 From: rabemananjara-l Date: Tue, 3 Feb 2026 16:25:37 +0100 Subject: [PATCH 2/4] Avoid setting zero in favor of nearest neighbor inter-/extra-polations --- .../heavy/n3lo/__init__.py | 20 +++++++++++++++++-- src/yadism/runner.py | 6 ++---- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/yadism/coefficient_functions/heavy/n3lo/__init__.py b/src/yadism/coefficient_functions/heavy/n3lo/__init__.py index fdcd8552b..ec5a52f5a 100644 --- a/src/yadism/coefficient_functions/heavy/n3lo/__init__.py +++ b/src/yadism/coefficient_functions/heavy/n3lo/__init__.py @@ -1,7 +1,7 @@ import pathlib import numpy as np -from scipy.interpolate import RectBivariateSpline +from scipy.interpolate import NearestNDInterpolator, RectBivariateSpline grid_path = pathlib.Path(__file__).parent / "grids" @@ -11,6 +11,21 @@ interpolators = {} +def fill_nans_nearest_neighbor(xi_grid, eta_grid, coeffs): + z_filled = coeffs.copy() + mask = np.isfinite(coeffs) + values = coeffs[mask] + + xm, ym = np.meshgrid(xi_grid, eta_grid, indexing="ij") + points = np.column_stack((xm[mask], ym[mask])) + + interp_nn = NearestNDInterpolator(points, values) + z_filled[~mask] = interp_nn(xm[~mask], ym[~mask]) + assert np.all(np.isfinite(z_filled)) + + return z_filled + + def interpolator(coeff, nf, variation): grid_name = f"{coeff}_nf{int(nf)}_var{int(variation)}.npy" @@ -20,7 +35,8 @@ def interpolator(coeff, nf, variation): # load grid coeff = np.load(grid_path / grid_name) - coeff = np.nan_to_num(coeff, nan=0.0) + if np.isnan(coeff).sum() != 0: + coeff = fill_nans_nearest_neighbor(xi_grid, eta_grid, coeff) grid_interpolator = RectBivariateSpline(xi_grid, eta_grid, coeff) # store result diff --git a/src/yadism/runner.py b/src/yadism/runner.py index cc41f9344..0d899569b 100644 --- a/src/yadism/runner.py +++ b/src/yadism/runner.py @@ -216,7 +216,7 @@ def replace_nans_with_0(self, out): # Loop through each observable in the dictionary for observable, points in out2.items(): # Skip the keys that are not an observable - if observable not in observable_name.kinds: + if not observable_name.ObservableName.is_valid(observable): continue # Loop over the kinematic points @@ -274,9 +274,7 @@ def get_result(self): Q2 = None # compute - for idx, elem in sorted( - enumerate(obs.elements), key=lambda indexed: indexed[1].Q2 - ): + for idx, elem in sorted(enumerate(obs.elements), key=lambda indexed: indexed[1].Q2): # if we're changing Q2, drop cache if Q2 is not None and Q2 != elem.Q2: self.drop_cache() From b20f20e86191958be79fb9e43c221e56cd532607 Mon Sep 17 00:00:00 2001 From: rabemananjara-l Date: Tue, 3 Feb 2026 16:27:52 +0100 Subject: [PATCH 3/4] Run pre-commit --- src/yadism/runner.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/yadism/runner.py b/src/yadism/runner.py index 0d899569b..794ce5db7 100644 --- a/src/yadism/runner.py +++ b/src/yadism/runner.py @@ -274,7 +274,9 @@ def get_result(self): Q2 = None # compute - for idx, elem in sorted(enumerate(obs.elements), key=lambda indexed: indexed[1].Q2): + for idx, elem in sorted( + enumerate(obs.elements), key=lambda indexed: indexed[1].Q2 + ): # if we're changing Q2, drop cache if Q2 is not None and Q2 != elem.Q2: self.drop_cache() From 33dccdaf2446a8c06e6cc8064c25660bdf3155eb Mon Sep 17 00:00:00 2001 From: "Tanjona R. Rabemananjara" Date: Wed, 4 Feb 2026 10:56:26 +0100 Subject: [PATCH 4/4] Apply suggestions Co-authored-by: Felix Hekhorn --- src/yadism/coefficient_functions/heavy/n3lo/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/yadism/coefficient_functions/heavy/n3lo/__init__.py b/src/yadism/coefficient_functions/heavy/n3lo/__init__.py index ec5a52f5a..6f78d7042 100644 --- a/src/yadism/coefficient_functions/heavy/n3lo/__init__.py +++ b/src/yadism/coefficient_functions/heavy/n3lo/__init__.py @@ -35,7 +35,7 @@ def interpolator(coeff, nf, variation): # load grid coeff = np.load(grid_path / grid_name) - if np.isnan(coeff).sum() != 0: + if np.isnan(coeff).any(): coeff = fill_nans_nearest_neighbor(xi_grid, eta_grid, coeff) grid_interpolator = RectBivariateSpline(xi_grid, eta_grid, coeff)