Solve interior with exact-JVP Newton-Krylov#66
Open
krystophny wants to merge 38 commits into
Open
Conversation
17 tasks
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.
Replaces the finite-difference-Jacobian
hybrinterior re-solve in the SIMSOPT wrappers with a damped Newton-Krylov solver.State.raw_residual_jvp(exact on Enzyme builds, centered FD on default builds), preconditioned byState.apply_preconditioner; no dense O(n^2) FD Jacobian remains anywhere on the solve path.solve_interiorsemantics: the energy becomes stationary with respect to interior solve error, which makes finite-difference cross-checks of the boundary gradient well conditioned.accept_tol * |F0|raises and triggers the penalty contract.residual_evaluationsandjvp_evaluationsmake solver cost measurable.Default builds keep working: the same Newton-Krylov runs with FD matvecs and the public API is unchanged.
Verification
Before
GvecEnergyProblem.solve_equilibriumcalledscipy.optimize.root(method="hybr"), whose MINPACK Jacobian costs O(n^2) FD residual evaluations per solve (~20 s per solve on the converted solovev case) and fails on stiff cases.After
Enzyme-on isolated build (fixed RZ, LLVM/Flang 22.1.6):
Enzyme-off isolated build:
test_newton_interior_solve_reaches_force_balancedrives the fixture (initial interior residual norm 3.78) below 1e-3 relative with fewer than 20 residual evaluations per Newton iteration.test_simsopt_gradient_matches_fd_resolvevalidates the adjoint boundary gradient against centered FD with full re-solves atrtol=1e-5.