Skip to content

Feature/scipy interpolation issue 261 - #295

Open
Ao-chuba wants to merge 4 commits into
theochem:masterfrom
Ao-chuba:feature/scipy-interpolation-issue-261
Open

Ao-chuba wants to merge 4 commits into
theochem:masterfrom
Ao-chuba:feature/scipy-interpolation-issue-261

Conversation

@Ao-chuba

@Ao-chuba Ao-chuba commented Feb 24, 2026 •

Copy link
Copy Markdown
Member

@PaulWAyers @Ali-Tehrani ,
This PR updates _HyperRectangleGrid.interpolate to route non-derivative interpolations directly to SciPy's RegularGridInterpolator. This enables vectorized evaluation on multiple points and exposes additional interpolation methods like slinear, quintic, and pchip.
Tested and all existing tests pass
image

Closes #261

closes theochem#261)

- Add support for 'slinear', 'quintic', and 'pchip' methods in
  _HyperRectangleGrid.interpolate in addition to existing 'linear',
  'nearest', and 'cubic' methods.
- Route all non-derivative interpolations (nu_x == nu_y == nu_z == 0)
  to SciPy's RegularGridInterpolator, enabling vectorized evaluation
  on multiple points at once for all methods, including 'cubic'.
- The custom CubicSpline-based derivative path is preserved and only
  used when nu_x, nu_y, or nu_z > 0.
- Correctly apply np.exp() when use_log=True in the SciPy path.
- Update tests: fix error message assertion and relax atol from 1e-6
  to 1e-5 to match SciPy cubic's numerical precision characteristics.
@Ao-chuba
Ao-chuba force-pushed the feature/scipy-interpolation-issue-261 branch from ee8aa4a to 77394ea Compare February 24, 2026 19:59
@Ao-chuba

Ao-chuba commented Apr 5, 2026

Copy link
Copy Markdown
Member Author

Hi @marco-2023 , please review this PR whenever you have time. Thanks!

@marco-2023 marco-2023 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you Aochuba for your constribution
The idea is sensible but needs furter development:

  1. Cubic interpolation and its derivatives use different potentially inconsistent implementations. When no derivative is requested, it uses scipy`s RegularGridInterpolator
  2. The existing cubic interpolation behavior changes, previous code supported extrapolation, current implementation doesn't.
  3. We need tests for new added methods.

- Keep cubic method on internal spline for consistency between values and derivatives
- Enable extrapolation in SciPy RegularGridInterpolator with bounds_error=False, fill_value=None
- Restore atol=1e-6 for cubic Gaussian interpolation test
- Add comprehensive tests for slinear, quintic, and pchip methods, extrapolation, and derivative error handling
@Ao-chuba

Ao-chuba commented Nov 9, 2026

Copy link
Copy Markdown
Member Author

Thanks for the review @marco-2023 I've updated the PR:

  1. Cubic consistency: method="cubic" now uses the internal spline for both function values and derivatives, keeping them fully consistent.
  2. Extrapolation & derivatives: Added bounds_error=False, fill_value=None to SciPy's RegularGridInterpolator to preserve extrapolation, and added checks that raise NotImplementedError if derivatives are requested with SciPy methods.
  3. Tests: Added tests for slinear, quintic, pchip, extrapolation, and derivative error handling.

All tests pass.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Interpolating on Cubic Grids Using Scipy

2 participants