Merged
Conversation
Member
vchuravy
commented
Apr 20, 2026
- Add NewtonKrylovWorkspace to pre-allocate all Newton-Krylov buffers
- Add evaluate! and refactor linesearch to operate on workspace
|
Once the build has completed, you can preview your PR at this URL: https://NumericalMathematics.github.io/Ariadne.jl/previews/PR130/ in a couple of minutes. |
vchuravy
commented
Apr 20, 2026
vchuravy
commented
Apr 20, 2026
vchuravy
commented
Apr 20, 2026
vchuravy
commented
Apr 20, 2026
vchuravy
commented
Apr 20, 2026
vchuravy
commented
Apr 20, 2026
Introduces `NewtonKrylovWorkspace` that holds `res`, `neg_res`, `JacobianOperator` (with Enzyme caches), and the Krylov solver workspace, eliminating per-call allocations in the Newton loop. The main `newton_krylov!(ws, u, p; ...)` method operates on the pre-allocated workspace. Existing convenience methods now create a workspace internally and delegate to it. Passing a different initial-guess array copies it into `ws.u` automatically when `ws.u !== u`. Adds `test/workspace.jl` covering correctness, workspace reuse, and a regression guard showing allocations are significantly reduced vs the non-workspace API. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
`evaluate!(ws::NewtonKrylovWorkspace)` evaluates `F!(ws.res, ws.u, ws.p)` in-place and returns `norm(ws.res)`, eliminating the need to pass `F!`, `u`, and `p` separately after construction. `NewtonKrylovWorkspace` gains `f` and `p` fields so all inputs are self-contained. The linesearch interface is updated to `(ws, norm_res_prior, d)` — both `NoLineSearch` and `BacktrackingLineSearch` now call `evaluate!(ws)` instead of invoking `F!` and `norm` directly. The top-level solver is split into `newton_krylov!(ws)` (no extra args) and a thin `newton_krylov!(ws, u)` wrapper that copies `u` into `ws.u` when needed. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Pass `res` as keyword arg to constructor instead of copying via `ws.res .= res` - Add ghost-cell comment before `Enzyme.make_zero!(res)` - Fix `newton_krylov!(ws, u₀; ...)` to drop redundant `u₀` arg - Fix docstring for `newton_krylov!(ws; kwargs...)` to include signature - Remove unused `krylov_ws` local variable - Drop `NewtonKrylovWorkspace` from Theseus import Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
ranocha
reviewed
Apr 21, 2026
ranocha
requested changes
Apr 21, 2026
Co-authored-by: Hendrik Ranocha <ranocha@users.noreply.github.com>
vchuravy
commented
Apr 21, 2026
vchuravy
commented
Apr 21, 2026
Co-authored-by: Valentin Churavy <v.churavy@gmail.com>
|
Your PR requires formatting changes to meet the project's style guidelines. Click here to view the suggested changes.diff --git a/src/Ariadne.jl b/src/Ariadne.jl
index 14628d2..40d9dbd 100644
--- a/src/Ariadne.jl
+++ b/src/Ariadne.jl
@@ -338,7 +338,7 @@ struct NewtonKrylovWorkspace{F, A, P, JOp <: AbstractJacobianOperator, KW}
end
function NewtonKrylovWorkspace(
- F!, u::AbstractArray, p, res::AbstractArray, ::Val{Algo}=Val(:gmres);
+ F!, u::AbstractArray, p, res::AbstractArray, ::Val{Algo} = Val(:gmres);
assume_p_const::Bool = false
) where {Algo}
# res .= 0 might ignore ghost cells
diff --git a/test/workspace.jl b/test/workspace.jl
index 3ade878..b592a75 100644
--- a/test/workspace.jl
+++ b/test/workspace.jl
@@ -96,5 +96,5 @@ Base.zero(v::WrappedVector) = WrappedVector(zero(v.data))
res = zero(x₀)
x, stats = newton_krylov!(F!, x₀, nothing, res)
@test stats.solved
- @test x ≈ [1.0, 1.0] atol = 1e-5
+ @test x ≈ [1.0, 1.0] atol = 1.0e-5
end |
…rator type mismatch When newton_krylov!(F!, u, p, res) was called with a custom array type, the supplied `res` was passed as a keyword to the 3-arg NewtonKrylovWorkspace constructor, which silently dropped it into kwargs and created a fresh `similar(u, M)` instead. For types where similar(u, ::Int) falls back to returning a plain Vector, this produced a res/u type mismatch that violated JacobianOperator's res::A / u::A constraint. Fix by routing directly to the 5-arg NewtonKrylovWorkspace constructor with res as a positional argument. Add a regression test using WrappedVector, a minimal AbstractVector subtype whose similar(v, ::Int) is undefined so it would trigger the fallback. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.