Skip to content

Drop bundled MINPACK; use fortnum multiroot for quasi symplectic steps#390

Closed
krystophny wants to merge 5 commits into
mainfrom
drop-bundled-minpack-use-fortnum-multiroot
Closed

Drop bundled MINPACK; use fortnum multiroot for quasi symplectic steps#390
krystophny wants to merge 5 commits into
mainfrom
drop-bundled-minpack-use-fortnum-multiroot

Conversation

@krystophny

@krystophny krystophny commented Jun 14, 2026

Copy link
Copy Markdown
Member

Merge order

Merge sequence: #390, then #391 (#391 stacks its test coverage on this PR).

Both PRs are based on main individually, so each diff is cumulative against
main and the two overlap. Merge #390 first. Once it lands, the #391 diff
shrinks to its increment: the test_sympl_stell coverage for the fortnum
multiroot quasi path.

Scope

orbit_symplectic_quasi was the only consumer of the vendored MINPACK hybrd1. This PR removes the bundled MINPACK and routes all eight root-finding call sites through fortnum's multiroot_hybrids (Newton step with a backtracking line search and a finite-difference Jacobian), preserving the warm-started, Jacobian-free solve the call sites relied on. Each f_*_quasi residual now conforms to the multiroot_fn_t interface (assumed-shape x/f, optional ctx, no iflag); residual state still travels through the existing module globals f, fs, si, and the f_midpoint_quasi midpoint-then-endpoint double field evaluation is unchanged. xtol and ftol are both set to si%rtol to track the former hybrd1 stopping behavior. fortnum is wired via CMake FetchContent (GIT_TAG a7faa3c, guarded by NOT TARGET fortnum) and linked into the simple library.

Dependency removed: bundled MINPACK (src/contrib/minpack.f90, src/contrib/minpack_interfaces.f90, src/contrib/LICENSE.minpack).

Globalization note

hybrd1 used a Powell hybrid (dogleg trust region); multiroot_hybrids uses a Newton step with an Armijo backtracking line search. Both are warm-started from the previous step and use a finite-difference Jacobian. The direct symplectic-integrator tests below pass within their existing tolerances, but the full golden-record trajectory comparison could not be run in this environment (see Unverified).

Verification

Configure and build (fortnum fetched at a7faa3c, heap-trampoline path available):

$ cmake -S . -B build_fortnum -GNinja -DCMAKE_BUILD_TYPE=Fast -DENABLE_PYTHON_INTERFACE=OFF
-- Performing Test FORTNUM_HAVE_HEAP_TRAMPOLINES - Success
-- Configuring done (16.8s)
-- Generating done (0.5s)

$ cmake --build build_fortnum --target simple simple.x -j32
[562/562] Linking Fortran static library src/libsimple.a
[4/4] Linking Fortran executable simple.x      # exit 0

orbit_symplectic_quasi.f90 compiles with no warnings; the full target set links (427/427).

Direct symplectic-integrator tests (these drive euler1, euler2, midpoint, and gauss4 quasi steps through the new solver with rtol=1e-12 and assert energy-drift tolerances):

1/75 Test  #1: test_sympl_tokamak ......................   Passed    0.08 sec
3/75 Test  #3: test_sympl_testfield ....................   Passed    0.10 sec
6/75 Test  #2: test_sympl_tokamak_plot .................   Passed    2.72 sec
15/75 Test #4: test_axis_crossing ......................   Passed    7.49 sec
24/75 Test #27: test_orbit_symplectic_base .............   Passed    0.11 sec

Full 32-particle Gauss-mode (integmode=3, relerr=1d-13) orbit run completes and writes valid NetCDF output:

$ ./build_fortnum/simple.x        # in examples/orbit_output_test
INFO: Parallel particle tracing completed      69.763 s
 Total field evaluations:                692234
INFO: Output writing completed       0.057 s

$ ./test_orbit_netcdf_output.x    # verify orbits.nc
 PASS: Time data contains valid values
 All NetCDF orbit output tests PASSED!

51 of 75 ctest cases pass. The remaining cases fail for environment reasons unrelated to this change:

  • 9 golden_record_* cases: the harness builds a second reference copy of SIMPLE that clones fortplot over HTTPS, which fails here (fatal: fetch-pack: invalid index-pack output, Failed to clone repository: fortplot.git). The failure is in the reference sub-build, before any physics runs.
  • orbit_netcdf_output (120s budget), test_chartmap_pipeline (60s budget): timed out only under -j8 load. Run standalone they pass (simple.x 84s, test_chartmap_pipeline.x 82s, both exit 0).
  • orbit_netcdf_verify, orbit_netcdf_plot: depend on the truncated orbits.nc from the timed-out producer; they pass against a complete file (shown above).

Unverified

The golden-record trajectory comparison (golden_record.sh) builds a reference SIMPLE from main and clones libneo and fortplot over HTTPS; the network is isolated in this environment, so that comparison did not run. Marked draft until it runs against the reference build.

Note: fortnum pin updated to current main (92de6e9) after a fortnum history rewrite; old shas no longer resolve.

orbit_symplectic_quasi was the sole consumer of the vendored MINPACK
hybrd1. Replace each of the eight hybrd1 calls with fortnum's
multiroot_hybrids (Newton step with a backtracking line search and a
finite-difference Jacobian), which provides the same warm-started,
Jacobian-free root solve the call sites relied on.

Each f_*_quasi residual now conforms to the multiroot_fn_t interface
(assumed-shape x/f, optional ctx, no iflag); state still travels through
the existing module globals f, fs, si. The f_midpoint_quasi double
field evaluation ordering (midpoint stage saved, then endpoint) is
preserved. xtol and ftol are both set to si%rtol to track the former
hybrd1 stopping behavior.

Wire fortnum via CMake FetchContent (GIT_TAG a7faa3c, guarded by
NOT TARGET fortnum) and link it into the simple library. Delete
src/contrib/minpack.f90, minpack_interfaces.f90, and LICENSE.minpack.
@krystophny krystophny marked this pull request as ready for review June 14, 2026 08:24
fortnum a7faa3c installed its C ABI header from CMAKE_SOURCE_DIR, which
resolves to the consumer tree under FetchContent and failed SIMPLE's
install step. fortnum main now sources the header from PROJECT_SOURCE_DIR
(9595e51); pin to the merge commit that carries the fix.
@krystophny

Copy link
Copy Markdown
Member Author

Superseded by #392 (commit b3fe016 on main), whose squash merge already landed the bundled-MINPACK removal and fortnum multiroot migration. Closing as already-merged; this branch's tip is now behind main on cmake/Util.cmake (pre env-cleanup), so merging it would regress.

@krystophny krystophny closed this Jun 15, 2026
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