Migrate interpolation backend to FastInterpolations.jl - #307
Conversation
… related documentation
…s, magnetics, and sol modules
…ct tests for its behavior
…tions.jl Migrate the last Interpolations.jl call sites to FastInterpolations and remove the dependency: - ρ_interpolant: cubic_spline_interpolation → FI.cubic_interp (ExtendExtrap) - avgZinterpolator: Gridded(Linear)+Flat → FI.linear_interp (ClampExtrap) - q_95 expression: linear_interpolation → FI.linear_interp - add _deduplicate_knots! (math.jl) replacing Interpolations.deduplicate_knots! for the SOL P(r)/r(P) interpolants - drop Interpolations from Project.toml and src/physics.jl Extend the interpolation characterization tests with avgZ Flat-extrapolation and _deduplicate_knots! contract checks. Full interpolation suite green.
… FastInterpolations
…r FastInterpolations
… FastInterpolations Migrate the last direct DataInterpolations calls to FI and remove the dependency: - sol.jl: CubicSpline → FI.cubic_interp (find_levels_from_P r(ψ)) - sources.jl: LinearInterpolation+Constant → FI.linear_interp+ClampExtrap (total_sources) - signal.jl: linear up-sampling → FI.linear_interp (smooth_by_convolution) - remove DataInterpolations import (physics.jl) and dependency (Project.toml) Extend test/runtests_interp1d.jl with smooth_by_convolution, total_sources, and find_levels_from_P characterization tests covering these sites.
…-shot API for direct querying
There was a problem hiding this comment.
Pull request overview
This PR migrates IMAS’s interpolation backend from Interpolations.jl/DataInterpolations.jl to FastInterpolations.jl, updating core physics workflows and adding characterization tests to preserve behavior within tolerances while improving performance.
Changes:
- Replace 1D/2D interpolation construction, evaluation, gradient, and extrapolation semantics with FastInterpolations equivalents across physics and expressions code.
- Update helper APIs (
cubic_interp1d,linear_interp1d) and remove legacy interpolation dependencies fromProject.toml. - Add new test suites covering interpolation-heavy workflows and 1D interpolation helpers, and wire them into
runtests.jl.
Reviewed changes
Copilot reviewed 19 out of 20 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| test/runtests.jl | Adds new interpolation-focused test files to the default test run. |
| test/runtests_interpolations.jl | New characterization/regression tests for interpolation-backed equilibrium/profile workflows. |
| test/runtests_interp1d.jl | New characterization/regression tests for IMAS 1D interpolation helpers and consumers. |
| src/signal.jl | Replaces DataInterpolations-based upsampling with FastInterpolations linear interpolation. |
| src/physics/thermal_loads.jl | Switches cubic interpolation usage to the updated one-shot helper API. |
| src/physics/sources.jl | Replaces DataInterpolations constant extrapolation with FastInterpolations clamp extrapolation. |
| src/physics/sol.jl | Updates interpolant types and knot deduplication; adjusts interpolant evaluation style. |
| src/physics/profiles.jl | Replaces Interpolations gridded linear+flat extrapolation with FastInterpolations linear+clamp. |
| src/physics/magnetics.jl | Updates interpolant argument types to FastInterpolations’ abstract interpolant. |
| src/physics/interferometer.jl | Updates segment interpolation evaluation to use FastInterpolations-backed interpolants. |
| src/physics/fluxsurfaces.jl | Updates interpolant argument types and uses new one-shot cubic interpolation call site(s). |
| src/physics/fields.jl | Replaces Interpolations.gradient with FastInterpolations gradient API; updates types/imports. |
| src/physics/equilibrium.jl | Replaces cubic spline interpolant builders with FastInterpolations cubic interpolation + extrapolation. |
| src/physics/currents.jl | Switches cubic interpolation call sites to the updated one-shot helper API. |
| src/physics.jl | Drops imports of legacy interpolation packages. |
| src/math.jl | Re-implements cubic_interp1d / linear_interp1d on FastInterpolations and adds one-shot overloads; adds _deduplicate_knots!. |
| src/IMAS.jl | Imports FastInterpolations as FI for module-wide use. |
| src/expressions/onetime.jl | Updates cubic interpolation usage to new helper overloads (vectorized evaluation). |
| src/expressions/dynamic.jl | Replaces Interpolations linear interpolation with FastInterpolations. |
| Project.toml | Removes DataInterpolations/Interpolations deps and adds FastInterpolations (with compat entry). |
Comments suppressed due to low confidence (1)
src/physics/magnetics.jl:57
PSI_interpolant.(r, z)is broadcasting over scalarr/z, which adds unnecessary broadcast overhead; the interpolant is already callable on scalars.
r = sum(pos.r for pos in loop.position) / length(loop.position)
z = sum(pos.z for pos in loop.position) / length(loop.position)
psi = PSI_interpolant.(r, z)
set_time_array(loop.flux, :data, time0, psi)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
jmcclena
left a comment
There was a problem hiding this comment.
Looks good to me. If the FUSE regressions pass, let's merge it.
…ent seam Downstream packages (FUSE/FRESCO) pass Interpolations.jl interpolants into IMAS, which broke after the FastInterpolations migration restricted args to ::FI.AbstractInterpolant (MethodError in find_magnetic_axis and trace_simple_surfaces!->Br_Bz; FUSE CI run 28040722813). Restore compatibility without re-adding Interpolations as a dependency: - drop ::FI.AbstractInterpolant on PSI_interpolant args in fields/fluxsurfaces/sol/magnetics (scalar eval itp(r,z) is backend-agnostic) - funnel the only FI-specific coupling (gradient) through _psi_gradient in fields.jl: FI -> FI.gradient (analytic, FI numerics unchanged); otherwise -> parentmodule(typeof(itp)).gradient (resolves the owning module from the object, so no Interpolations dependency is declared) - Br_Bz is the single gradient call site; Bp/trace_*/field! route through it fluxsurfaces_cubic.jl internal helpers left as-is (always FI, FI.value_gradient). Verified: runtests_interpolations.jl golden values green; smoke test with a real Interpolations cubic interpolant passes find_magnetic_axis and Br_Bz.
|
@jmcclena It seems this PR is safe to merge. Thanks! |
Summary
Replace Interpolations.jl and DataInterpolations.jl with FastInterpolations.jl for all interpolation in IMAS, and drop both legacy dependencies from
Project.toml.Behavior is preserved within interpolation tolerance; performance improves across the board with no regressions.
Performance
@benchmark(BenchmarkTools, minimum time), master worktree vs this branch, identical public-API callson the bundled samples (D3D 65×65, omas 17×17). All comparisons are pure backend swaps — same algorithm,
only the interpolation library differs.
Interpolation primitives
cubic_interp1dbuildlinear_interp1dbuild+eval ×400PSIeval (50×50 grid)Br_Bz(∇ψ) ×200avgZ×1000ψ_interpolantbuildρ_interpolantbuild+evalReal IMAS routines
Jtor_2_Jpar(currents)line_averagetrace_surfacesflux_surfacesNotes
Interpolations.Line()→ExtendExtrap(),Flat()→ClampExtrap().CubicFitboundary condition reproduces cubic polynomials exactly; on theproduction equilibrium grids the migrated results match the previous ones within the test tolerances.