Migrate KiLCA 1F1 to fortnum (7/8)#146
Draft
krystophny wants to merge 1 commit into
Draft
Conversation
0c81000 to
406cf38
Compare
b41221c to
eba278e
Compare
eba278e to
821ba9f
Compare
This was referenced Jun 14, 2026
a350c4c to
2200b8e
Compare
e19b952 to
0f1adf1
Compare
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.
Merge order
These fortnum-migration PRs are individually based on
mainand form onecumulative stack. Merge them in this order:
#140 -> #141 -> #142 -> #143 -> #144 -> #145 -> #146 -> #147 -> #148 -> #149 -> #150
Each PR is opened against
main, so its diff is cumulative versusmainandoverlaps its predecessors. Merging in the order above keeps the history linear.
Scope
Route the production KiLCA FLR conductivity 1F1 through fortnum. The hot path
hypergeometric1f1_cont_fract_1_modified_0_ada_(called bycalc_Imn_array,calc_W2_array_wc,calc_I_array, ...) consumes the modified form F11m, where1F1(1;b;z) = 1 + z/b + z^2/(b(b+1)) * (1 + F11m). The previous routine eithersummed a Kummer-modified series directly (
|z/b| < 0.1) or reconstructed F11mfrom the full Kummer value M for larger
|z/b|. The reconstruction subtractstwo ~1 quantities and divides by z^2, losing about eight digits at small z and
exceeding the rtol=1e-8 golden bar.
This PR calls
fortnum_hyperg_1f1m_a1, which returnsF11m = M(1, b+2, z) - 1directly with no cancellation, and re-pins fortnum to the main commit that adds
the entry point.
fortnum changes (on fortnum main)
49e65d0addshyperg_1f1m_a1(Fortran, C ABI,fortnum.h) and fixes the1F1 series/asymptotic crossover to use the Taylor series whenever
|b| >= |z|,not only for small
|z|. The old|z|-only gate forced the large-z asymptotic(DLMF 13.7.2) for
M(1, b+2, z)withb ~ 1 + z, where that expansion isinvalid; it returned a value off by about 100% at z=64. The flre FLR
conductivity sweep reaches z up to ~1600, so the wrong value drove the
downstream CVODE field-profile solve into a non-terminating run.
Verification
fortnum 1F1m versus the original KiLCA modified routine across the flre
conductivity grid (z = x1^2 up to 1600, b = 1 + z - i*x2):
fortnum unit tests at the pinned commit: 71/71 pass, including the
modified-form test covering small-z cancellation and large-z crossover
(worst F11m rel err 1.26e-15).
KiLCA flre run with the fix completes (was a non-terminating hang before the
crossover fix):
ql-balance golden (
uvvenv: pytest numpy scipy h5py f90nml), built againstthe pinned fortnum:
The golden runs to completion and does not hang, but does not yet meet the bar.
The residual failures are NOT from the 1F1 path: the modified F11m now matches
the original to < 2e-11. They are accumulated drift from the other fortnum
kernels already in this cumulative branch chain (complex Bessel, dop853 ODE,
roots/multiroot, adaptive quadrature) compounding over the 8-step QL-Balance
evolution. Those are addressed by their own PRs in the stack; this PR is green
for the 1F1 quantity it owns.
Stack reconciliation (update)
The migration stack was rebuilt as a strictly linear cumulative chain on main
428a708:Every branch now pins fortnum to main
974dcf1(all kernel fixes plus both new integrators). This branch's standalone golden result above stands. The cumulative tip (#150 z3) does not pass: the KiLCA background equilibrium ODE on#143 k4cannot reproduce the GSLrk8pdgolden with DOP853 at the unchanged1e-8bar. See#143and#150. Tolerances were not weakened and the stored golden was not regenerated.Merge order:
#140 -> #141 -> #142 -> #143 -> #144 -> #145 -> #146 -> #147 -> #148 -> #149 -> #150.Note: fortnum pin updated to current main (92de6e9) after a fortnum history rewrite; old shas no longer resolve.