Interpolation Functionals#

Grid-To-Point Interpolation#

physicsnemo.nn.functional.grid_to_point_interpolation(
query_points: Tensor,
context_grid: Tensor,
grid: List[Tuple[float, float, int]],
interpolation_type: str = 'smooth_step_2',
mem_speed_trade: bool = True,
) Tensor#

Interpolate values from a structured grid at query point locations.

This functional evaluates a scalar or multi-channel field defined on a regular Cartesian grid at arbitrary query points in 1D, 2D, or 3D.

For a query point \(\mathbf{x}\) and a grid field \(f\), interpolation is computed as a weighted sum over local stencil points:

\[\hat{f}(\mathbf{x}) = \sum_{i \in \mathcal{N}(\mathbf{x})} w_i(\mathbf{x})\, f_i\]

where \(\mathcal{N}(\mathbf{x})\) is the interpolation neighborhood and \(w_i(\mathbf{x})\) are interpolation weights.

The interpolation mode controls the stencil and weights:

  • nearest_neighbor: nearest grid point (piecewise constant, 1-point stencil)

  • linear: multilinear interpolation (2^d stencil in d dimensions)

  • smooth_step_1: multilinear-style interpolation with smooth-step weights \(3t^2 - 2t^3\)

  • smooth_step_2: multilinear-style interpolation with quintic smooth-step weights \(t^3(6t^2 - 15t + 10)\)

  • gaussian: local Gaussian weighting over a larger fixed stencil

Notes

  • Grid spacing and extents are provided by grid.

  • The warp and torch backends are intended to be numerically aligned.

  • warp is the default dispatch path for grid_to_point_interpolation.

  • The deprecated interpolation alias defaults to torch unless an explicit implementation is provided.

Parameters:
  • query_points (torch.Tensor) – Points at which interpolation is to be performed.

  • context_grid (torch.Tensor) – Source grid from which values are interpolated.

  • grid (list[tuple[float, float, int]]) – Describes the grid’s range and resolution.

  • interpolation_type (str, optional) – Interpolation method name, by default "smooth_step_2".

  • mem_speed_trade (bool, optional) – Trade-off between memory usage and speed.

  • implementation ({"warp", "torch"} or None) – Implementation to use. When None, dispatch selects the available implementation.

Grid-to-point interpolation query visualization

Point-To-Grid Interpolation#

physicsnemo.nn.functional.point_to_grid_interpolation(
query_points: Tensor,
point_values: Tensor,
grid: List[Tuple[float, float, int]],
interpolation_type: str = 'smooth_step_2',
mem_speed_trade: bool = True,
) Tensor#

Scatter point values back onto a structured grid using interpolation weights.

This functional maps values defined at query points onto a regular Cartesian grid in 1D/2D/3D. It is the adjoint-style counterpart to grid_to_point_interpolation.

For point values \(v_n\) at points \(\mathbf{x}_n\), the gridded field \(g_i\) is accumulated as:

\[g_i = \sum_{n} w_i(\mathbf{x}_n)\, v_n\]

where \(w_i(\mathbf{x}_n)\) are interpolation weights for grid node \(i\) at query point \(\mathbf{x}_n\).

Parameters:
  • query_points (torch.Tensor) – Query points with shape (num_points, dims).

  • point_values (torch.Tensor) – Values at query points with shape (num_points, channels).

  • grid (list[tuple[float, float, int]]) – Grid extent and resolution metadata.

  • interpolation_type (str, optional) – Interpolation method name.

  • mem_speed_trade (bool, optional) – Forwarded to the underlying grid-to-point implementation.

  • implementation ({"warp", "torch"} or None) – Implementation to use. When None, dispatch selects by rank.

Notes

  • query_points and point_values currently support torch.float32.

  • The warp and torch backends are intended to be numerically aligned.

  • warp is the default dispatch path for point_to_grid_interpolation.

Point-to-grid interpolation accumulation visualization

Deprecated Alias#

physicsnemo.nn.functional.interpolation(*args, **kwargs)[source]#

Deprecated alias for grid_to_point_interpolation.