Skip to content

Migrate KiLCA 1F1 to fortnum (7/8)#146

Draft
krystophny wants to merge 1 commit into
fortnum/k6-complex-besselfrom
fortnum/k7-hyper1f1
Draft

Migrate KiLCA 1F1 to fortnum (7/8)#146
krystophny wants to merge 1 commit into
fortnum/k6-complex-besselfrom
fortnum/k7-hyper1f1

Conversation

@krystophny

@krystophny krystophny commented Jun 14, 2026

Copy link
Copy Markdown
Member

Merge order

These fortnum-migration PRs are individually based on main and form one
cumulative 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 versus main and
overlaps 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 by calc_Imn_array,
calc_W2_array_wc, calc_I_array, ...) consumes the modified form F11m, where
1F1(1;b;z) = 1 + z/b + z^2/(b(b+1)) * (1 + F11m). The previous routine either
summed a Kummer-modified series directly (|z/b| < 0.1) or reconstructed F11m
from the full Kummer value M for larger |z/b|. The reconstruction subtracts
two ~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 returns F11m = M(1, b+2, z) - 1
directly with no cancellation, and re-pins fortnum to the main commit that adds
the entry point.

fortnum changes (on fortnum main)

  • 49e65d0 adds hyperg_1f1m_a1 (Fortran, C ABI, fortnum.h) and fixes the
    1F1 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) with b ~ 1 + z, where that expansion is
    invalid; 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):

worst orig-vs-fortnum rel = 1.8622e-11 at x1=0.01 x2=16.00

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):

$ ./run_local  -> EXIT 0

ql-balance golden (uv venv: pytest numpy scipy h5py f90nml), built against
the pinned fortnum:

99 failed, 16 passed in 86.66s
worst rel diff 9.57e-02 (final evolution step)

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:

k1 (+ golden CI fix) -> k2 -> k3 -> k4 -> k5 -> k6 -> k7 -> k8 -> z1 -> z2 -> z3

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 k4 cannot reproduce the GSL rk8pd golden with DOP853 at the unchanged 1e-8 bar. See #143 and #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.

@krystophny krystophny force-pushed the fortnum/k7-hyper1f1 branch from e19b952 to 0f1adf1 Compare June 15, 2026 19:28
@krystophny krystophny changed the base branch from main to fortnum/k6-complex-bessel June 15, 2026 19:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant