Repository navigation
Release v0.7.0: optional LinearSolve.jl backend, rename Mem to F1Cache - #20
Merged
Merged
Conversation
Adds an opt-in LinearSolve.jl-backed linear-solve path via a package
extension so LinearSolve remains a weak dependency. Default behaviour
(linsolve = nothing) is unchanged from 0.6.x.
Breaking renames (deprecation wrappers retained for 0.7.x; remove in 0.8):
- Mem -> F1Cache
- initialize_mem(...) -> F1Cache(...) constructor
- update_mem! -> update_cache! (internal)
- Mem.A field -> F1Cache.linear_cache
New:
- Optional `linsolve` kwarg on the F1Cache constructor. With it,
F1Cache.linear_cache holds a LinearSolve.LinearCache, enabling
symbolic factorization reuse for sparse direct solvers and buffer
reuse for dense.
- Tested with LUFactorization, GenericLUFactorization,
UMFPACKFactorization, KLUFactorization.
Tests:
- Refactored test/sparse_aibecs.jl (renamed from AIBECS_test.jl) and
test/dense_rosenbrock.jl (new) into a symmetric pattern: each loops
over (nothing, ...) linsolve variants and compares against
pre-computed ground-truth oracles (closed-form / ForwardDiff /
FiniteDiff).
- Dropped redundant test/rosenbrock.jl whose 6 assertions are now
exercised by dense_rosenbrock.jl's linsolve = nothing arm.
Co-Authored-By: Claude Opus 4.7 (1M context) <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.
Summary
linsolvekwarg on the renamedF1Cacheconstructor. Default behaviour (linsolve = nothing) is unchanged from 0.6.x.Mem->F1Cache,initialize_mem(...)->F1Cache(...),update_mem!->update_cache!,Mem.Afield ->F1Cache.linear_cache.for linsolve in (nothing, ...)pattern for dense (test/dense_rosenbrock.jl, new) and sparse (test/sparse_aibecs.jl, renamed fromAIBECS_test.jl). Redundanttest/rosenbrock.jldeleted (its assertions are now exercised by thelinsolve = nothingarm ofdense_rosenbrock.jl).What ships in the extension
The new
F1MethodLinearSolveExtextension (loaded whenLinearSolveis) routes the internal linear solves through aLinearSolve.LinearCache. This enables symbolic-factorization reuse for sparse direct solvers (UMFPACK / KLU) and buffer reuse for dense (LU / GenericLU). The adjoint solve insidehessianreuses the same factors viacacheval' \ B(Group A algorithms only; Pardiso / MUMPS / CUDSS / STRUMPACK / cusolverRF would need per-library shims and are explicitly out of scope, tracked at SciML/LinearSolve.jl#92).CI exercises four algorithms:
LUFactorization,GenericLUFactorization,UMFPACKFactorization,KLUFactorization. Other LU-family algorithms (MKLLUFactorization,AppleAccelerateLUFactorization,RFLUFactorization,SparspakFactorization,ParUFactorization) should work via the samecachevalpath, but the point of this PR isn't to test exhaustively — they can be added in a subsequent PR if requested.Implementation notes
Two non-obvious wrinkles that surfaced during testing:
LinearSolve.init(LinearProblem(J, B))allocatesLinearCache.uas aVector{Float64}even whenbis aMatrix{Float64}, so the subsequentsolve!errors on the shape mismatch. Fixed by passingu0 = similar(B)toLinearProblem.GenericLUFactorization.cachevalis aTuple{LU, ipiv}rather than a bareFactorization, socacheval' \ BthrowsMethodError: adjoint(::Tuple{...}). Added a 2-method_factorhelper that unwraps the tuple;LUFactorization/UMFPACKFactorization/KLUFactorizationall hit the identity branch.Test plan
Pkg.test()passes locally on Julia 1.12.6: dense (18 tests) + Optimization.jl extension (2) + sparse (31) = 51 pass, 0 fail.linsolve = nothingrow ofdense_rosenbrock.jlis bit-identical to the deletedrosenbrock.jltests (same model, same x0/p0, same oracles).linsolve = nothingrow ofsparse_aibecs.jlis byte-identical to the priorAIBECS_test.jlassertions.LUFactorization/GenericLUFactorizationmatch the closed-form Rosenbrock derivatives.UMFPACKFactorization/KLUFactorizationmatch theForwardDiffground truth on the AIBECS P-model at bothlambdaand2*lambda.julia --depwarn=yes,initialize_mem(F, ∇ₓf, x₀, p₀, MyAlg())emitsWarning: initialize_mem is deprecated; use F1Cache(...) insteadon stderr and returns anF1Method.F1Cache(not covered byPkg.test()—initialize_memis unreferenced by the test suite).Generated with Claude Code