Drop GSL dependency#135
Closed
krystophny wants to merge 1 commit into
Closed
Conversation
Replace all GSL usage with in-tree numerics and the libneo math kit. KIM (Fortran): - erf: Fortran 2008 intrinsic instead of gsl_sf_erf binding - modified Bessel I_n: neo_bessel_i from libneo (LIBNEO::math) - delete gsl_mod.f90, unlink GSL from KIM_lib KiLCA / QL-Balance (C++), new KiLCA/math/numeric modules: - adaptive_quad: Gauss-Kronrod QAG with QUADPACK semantics (public-domain Netlib constants and error tests) - quadpack_qagi: QAGI/QAGIU as a faithful translation of the public-domain QUADPACK dqagie/dqk15i/dqelg/dqpsrt, including the epsilon-algorithm extrapolation; matches gsl_integration_qagi to 3e-16 over 216 resonant vel_integral parameter sets - ode_rk8pd: Prince-Dormand RK8(7)13M stepper; step control and evolve semantics follow the gsl_odeiv documented behavior (truncated final-step suggestion, no-progress acceptance); single steps match GSL bitwise in 98 percent of probes - brent_root: Brent-Dekker bracketing solver - deriv_central: adaptive 5-point central difference - sort_index_doubles (std::sort) replaces gsl_heapsort_index - 2D Newton iteration replaces gsl_multiroot hybridsj in the eigenmode determinant zero search - delete dead GSL-based code paths (Levin acceleration variant, circle-integral quadrature, unused analytic Jacobians) Build system: remove cmake/FetchGSL.cmake and all GSL link and include references; KIM_lib now links LIBNEO::math. Requires itpplasma/libneo math kit (itpplasma/libneo#290).
Member
Author
|
Superseded by #139, which drops GSL by routing all of KAMEL (KIM Fortran, KiLCA/QL-Balance C/C++) onto the fortnum numerical core directly rather than reimplementing the routines in-tree and pulling Bessel from libneo. #139 builds GSL-free with 18/18 ctests passing and zero gsl_ symbols in every shipped binary. Leaving this open for a human to decide on closing. |
Member
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Addresses #134.
KAMEL is MIT-licensed but linked GSL (GPL-2.0+) via
cmake/FetchGSL.cmake. This PR removes GSL entirely: every call site now uses a Fortran intrinsic, the libneo math kit, or a small in-tree replacement. No shipped target links GSL.Depends on the libneo math kit: itpplasma/libneo#290 must merge first, since KIM now uses
neo_bessel_ifromLIBNEO::math. Draft until that lands; see also the golden-record note below.Changes
KIM (Fortran)
gsl_sf_erfbindings replaced by the Fortran 2008erfintrinsic (integrands.f90,integrands_adaptive.f90,numerics_utils.f90).gsl_sf_bessel_Inreplaced bybessel_infrom libneoneo_bessel_i(FLR2_asymptotics.f90);KIM_liblinksLIBNEO::math.gsl_mod.f90deleted.KiLCA / QL-Balance (C++), new modules under
KiLCA/math/numeric/:adaptive_quad: adaptive Gauss-Kronrod quadrature with QUADPACK QAG semantics (GK15/21/31). Nodes, weights, and error tests are the public-domain Netlib QUADPACK data (dqk15/21/31,dqage), with attribution in the source. Replacesgsl_integration_qaginfour_transf.cpp,hyper1F1.cpp, and thecalc_I_array_drifttest driver.quadpack_qagi: infinite-range integration as a faithful translation of the public-domain QUADPACKdqagie,dqk15i,dqelg,dqpsrt, including the epsilon-algorithm extrapolation. Replacesgsl_integration_qagi/qagiuinvel_integral.cpp. Matchesgsl_integration_qagito 2.6e-16 worst-case over 216 parameter sets spanning the resonantvel_integralregime (omega_E through zero, small collisionality).ode_rk8pd: embedded Runge-Kutta 8(7) with the RK8(7)13M tableau of Prince and Dormand (J. Comp. Appl. Math. 7, 1981) and the gsl_odeiv step-control semantics: scaleeps_abs + eps_rel*|y|, safety 0.9, growth limits 0.2 to 5, truncated final-step suggestion, acceptance when a rejected step cannot make progress. Replacesgsl_odeivrk8pd/control/evolve incalc_back.cpp,incompressible.cpp,compressible_flow.cpp. Single steps reproduce GSL bitwise in 98 percent of probes; the rest differ by 1 to 2 ulp from compiler-specific FMA contraction.brent_root: Brent-Dekker bracketing solver (Brent 1973). Replaces thegsl_root_fsolverbrent loop incalc_mode.cpp.deriv_central: adaptive 5-point central difference. Replacesgsl_deriv_central.sort_index_doubles(std::sortover an index array, incore/shared.cpp) replacesgsl_heapsort_indexinadaptive_grid.cpp,calc_cond.cpp,sysmat_profs.cpp.calc_eigmode.cpp) uses a plain 2D Newton iteration with the existing finite-difference Jacobian instead ofgsl_multiroot_fdfsolver_hybridsj. Stopping criteria unchanged (same residual and step-size tests).hyper1F1.cpp(marked "do not use" upstream), the never-calledcalc_circle_integral_gkq, and the unused analytic Jacobians of the explicit rk8pd stepper.Build system
cmake/FetchGSL.cmakedeleted,include(FetchGSL)removed fromcmake/Dependencies.cmake.gsl/gslcblasremoved from KiLCA, KIM, and QL-Balance link lists, include paths, setup scripts, and READMEs.Verification
All on macOS arm64, Homebrew clang 21 / gfortran, GSL 2.8 as test oracle only.
Before (main): GSL fetched and linked. After (this branch): full build succeeds, no GSL symbol in any shipped binary.
ctest: 17/18 pass. The one failure (
test_rhs_balance,gamma_a_eexpected-0.0vs2.78e-14*1e13) fails identically on unmodifiedmainbuilt with the same toolchain; it is fp-association noise in a pure-Fortran flux test untouched by this PR.Oracle tests against GSL at the real call-site parameters (gate 1e-12 rel):
Golden record (ql-balance.x vs
golden.h5frommain+GSL on the same machine; on this platform the run produces LinearProfiles 0-1 and KinProfiles 1000 onmainand branch alike, so 33 of 114 quantities are comparable):The 18 failures are a one-time transition artifact, bisected to
calc_back.cpp: the background equilibrium ODE integrates ateps_abs = eps_rel = 1e-16, where the step controller operates at the roundoff floor and accepts or rejects steps on the last ulp of the error estimate. The resultinguprofile differs from the GSL build by at most 2.9e-15 relative (measured by instrumenting both builds), and the resonant layer of the linear mode solve amplifies that to the observed 1e-6-level diffs in Br and dql. At this tolerance even two GSL builds with different compilers produce different step sequences, so no independent implementation can hold rtol 1e-8 on this path; once this PR is onmain, the golden reference regenerates GSL-free and the test is consistent again. All other golden quantities, and the full pipeline up to the linear profiles, match the GSL build to better than 1e-8.