(compat): Upgrade FastInterpolations to v0.4 and AdaptiveArrayPools to v0.3#207
Conversation
Bump FastInterpolations compat to 0.4 and AdaptiveArrayPools to 0.3. Update all interpolation call sites across the codebase: - Val((x,y)) → DerivOp(x,y) for 2D derivatives - deriv=N → deriv=DerivOp(N) for 1D derivatives - Multi-column matrices → Series(matrix) for series interpolants - Remove now-default search=LinearBinary() and bc=CubicFit() - NaturalBC() → ZeroCurvBC() - Simplify selective imports to plain 'using FastInterpolations'
… vacuum response Pool-allocated arrays from zeros!(pool, ...) must not outlive the @with_pool scope, but compute_vacuum_response returns these arrays to the caller. Use standard zeros() instead to avoid use-after-return of pooled memory.
…paratrix finder The zsep loop in equilibrium_separatrix_find! used unbounded Newton iteration to find dZ/dθ = 0 extrema. Newton diverged when d²Z/dθ² passed through zero (inflection point), sending θ to values like ±1e9. Due to sin/cos periodicity the diverged θ still produced plausible Z values, silently returning wrong extrema depending on floating-point luck. This caused kappa ≈ 0 or kappa < 0 for some equilibria. Fix: use bracketed Brent method on dZ/dθ with θ ∈ [0.5,1.0] (bottom) and θ ∈ [0.0,0.5] (top). This eliminates d²Z/dθ² entirely, is 4x faster, and guarantees convergence to the correct extremum. Adds regression tests for kappa with Solovev equilibria (e=1.6, e=1.0).
…force tests Convert the rsep loop (outboard/inboard midplane finding) from unbounded Newton to bracketed Brent for consistency with the zsep fix. Remove unused mtheta and vector variables that were only needed for Newton initial guesses. Add rsep value-level checks (amean ≈ 0.33, rmean ≈ 1.0) and circular cross-section rext symmetry test (rext[1] ≈ rext[2]).
EQUIL - BUG FIX - Fix kappa calculation in separatrix finder
|
@mgyoo86 I am out Th,F then traveling to KSTAR for experiments the next two weeks, so forgive me if I am slow to review this - it is not for lack of appreciation!! @jhalpern30 please help me out with reviewing this |
|
@claude review |
|
Code review posted — see below for details. |
|
Placeholder — deleting this, real review below. |
|
Code Review Summary: This PR correctly migrates FastInterpolations v0.4 and AdaptiveArrayPools v0.3, and fixes a genuine memory-safety bug in Vacuum.jl. However, several Series() wrappers for multi-column interpolants were missed, which will cause runtime errors on those code paths. Bug 1 - InverseEquilibrium.jl (~line 304, ffac-normalization branch) Bug 2 - ForceFreeStates/Free.jl (~line 158) Bug 3 - ForceFreeStates/Bal.jl (~lines 292, 372) Separatrix refactor: hardcoded brackets Positive notes
|
jhalpern30
left a comment
There was a problem hiding this comment.
@mgyoo86 looks good, thanks for doing this! Let me know what you think of Claude's review comments regarding the missing Series and the separatrix Brent solve. Once those are resolved, I can merge.
…rpolants in FastInterpolations v0.4 InverseEquilibrium.jl: sq_fs in ffac-normalization branch Free.jl: wv_flat vacuum matrix interpolant Bal.jl: bf_fs, spl1_fs, bg_fs, spl2_fs, spl3_fs ballooning coefficient matrices
…ive error messages for all separatrix find_zero calls
|
@jhalpern30
I didn't widen the bracket values, however, the current brackets already span a full half-period each, which should be sufficient and safe to find solutions. Thanks! @logan-nc have a safe trip! :) |
Incorporates: - PR #207: FastInterpolations v0.4 API (Series() wrappers, ZeroCurvBC, remove explicit defaults) - PR #208: Separatrix finder Brent method fix - PR #198: Analysis module improvements (plot_eigenvalues, plot_delta_prime, plot_ffs_summary) - AdaptiveArrayPools v0.3.5, FastInterpolations v0.4.7 Conflict resolved in src/Analysis/ForceFreeStates.jl: retained our plot_edge_stability_scan alongside develop's new plot_eigenvalues, plot_delta_prime, and plot_ffs_summary functions. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Summary
Migrate all interpolation call sites across the codebase to the
FastInterpolationsv0.4 API and bumpAdaptiveArrayPoolsto v0.3. This is a mechanical but codebase-wide change (22 files, all modules).FastInterpolations v0.4
Full migration guides:
📖 v0.2->v0.3
📖 v0.3->v0.4
Key changes reflected in this PR:
Series()wrapper required for multi-column (series) interpolants:Saner defaults — less boilerplate:
CubicFit()is now the default BC andAutoSearch()is the default search policy (automatically selects the optimal algorithm internally). Explicitbc=CubicFit()andsearch=LinearBinarySearch()are no longer needed:Derivative dispatch:
Val((1, 0))replaced byDerivOp(1, 0)for ND derivatives; integerderiv=1replaced byderiv=DerivOp(1)for series interpolants.Renamed BC:
NaturalBC()→ZeroCurvBC().Simplified imports: Selective
import FastInterpolations: cubic_interp, deriv1, ...replaced withusing FastInterpolations— all public symbols are now properly exported.AdaptiveArrayPools v0.3
While upgrading, I discovered a misuse of
AdaptiveArrayPoolsincompute_vacuum_response: arrays allocated viazeros!(pool, ...)(wv,grri,grre,plasma_pts,wall_pts) were being returned to the caller, escaping their@with_poolscope. Once the scope ends, the pool may reclaim and reuse that memory, leading to silent data corruption. Fixed by replacing with standardzeros()allocations.AdaptiveArrayPools v0.3 now includes compile-time escape detection that catches most of these patterns automatically at macro-expansion time. Enabling
RUNTIME_CHECKmode for test suites and adopting the related safety skills will be addressed in a follow-up PR.