Repository navigation
Stop threading LinearSolve cache through solution return values - #3875
Merged
ChrisRackauckas merged 1 commit intoJul 11, 2026
Merged
ChrisRackauckas merged 1 commit into
ChrisRackauckas merged 1 commit into
Conversation
Modern LinearSolve.LinearCache is mutable and updated in place: solve! never replaces the cache, so linres.cache === cache always. Use the cache built at init directly instead of reading .cache off returned LinearSolutions, and drop the no-op writebacks. Prepares for LinearSolve 5.0, which removes the cache from solve!'s returned LinearSolution. Co-Authored-By: Claude Fable 5 <[email protected]> Co-Authored-By: Chris Rackauckas <[email protected]>
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.
What
Stops threading the LinearSolve cache through solution return values (
linres.cache). OrdinaryDiffEq now holds theLinearSolve.LinearCacheit builds atalg_cachetime (cache.linsolve,cache.linsolve1/2/3,cache.linsolve[i]) and passes that stable reference to everydolinsolve/solve!call, instead of re-reading.cacheoff the previously returnedLinearSolution.Requested by @ChrisRackauckas.
Why
Modern
LinearSolve.LinearCacheis mutable and updated in place:solve!(cache)never replaces the cache, solinres.cache === cachealways. Thelinres.cachethreading is a relic of an era when cache updates could rebuild the cache — every deletedcache.linsolve = linres.cachewriteback was assigning an object to the field that already held it.This prepares OrdinaryDiffEq for LinearSolve 5.0, which will remove the cache from
solve!'s returnedLinearSolution(a parallel PR is making that change). After this PR, no code in the monorepo reads.cacheoff a linear solution.This PR should merge before LinearSolve 5.0 is released.
dolinsolve(lib/OrdinaryDiffEqDifferentiation/src/linsolve_utils.jl) was audited first: it mutates the passed cache in place (linsolve.b = b,linsolve.u = linu,LinearSolve.reinit!(linsolve; A)) and returnssolve!(linsolve)— no branch ever constructs a replacement cache, so this is a pure plumbing change with byte-identical semantics.Sites changed
lib/OrdinaryDiffEqNonlinearSolve/src/newton.jl: deleted thecache.linsolve = linres.cachewriteback incompute_step!(core path for all NLNewton-based implicit methods).lib/OrdinaryDiffEqRosenbrock/src/rosenbrock_perform_step.jl: chaineddolinsolve(integrator, linres.cache; …)calls now passcache.linsolve; deleted 3 writebacks (Rosenbrock23/32 caches and the genericRosenbrockCacheloop).lib/OrdinaryDiffEqRosenbrock/src/stiff_addsteps.jl: chained call now reuses the locallinsolve(cache.linsolve).lib/OrdinaryDiffEqFIRK/src/firk_perform_step.jlandfirk_addsteps.jl: deleted allcache.linsolveX = linresX.cachewritebacks (RadauIIA3/5/9);cache.linsolveX = dolinsolve(…).cacheassignments inAdaptiveRadauCachebecome baredolinsolve(…)calls; smooth_est error-estimate calls passcache.linsolve1/locallinsolve1instead oflinres1.cache; the GaussLegendre directLinearSolve.solve!no longer binds an unusedlinres.lib/OrdinaryDiffEqExtrapolation/src/extrapolation_perform_step.jl: deleted all 31cache.linsolve[…] = linres.cachewritebacks (serial and threaded implicit extrapolation paths).Not changed:
lib/OrdinaryDiffEqAMF/src/linsolve.jlconstructs aLinearSolutionviaSciMLBase.build_linear_solution(alg, y, nothing, cache)— that is construction (SciMLBase API), not a read of.cacheoff a returned solution, and is unaffected by removing the read-side threading. It may need a follow-up when SciMLBase/LinearSolve 5.0 land, depending on the finalbuild_linear_solutionsignature.Tests run locally (Julia 1.12.4, monorepo
GROUProuting via rootPkg.test())GROUP=OrdinaryDiffEqFIRK(Core)GROUP=OrdinaryDiffEqFIRK_QAall_explicit_imports_are_public— reproduces identically on unmodified master (pre-existing, unrelated: flags long-standing imports likealg_cache,dolinsolve; being investigated separately)GROUP=OrdinaryDiffEqExtrapolation(Core)GROUP=OrdinaryDiffEqExtrapolation_Multithreading(2 threads)cache.linsolve[Threads.threadid()]branches)GROUP=OrdinaryDiffEqNonlinearSolveGROUP=OrdinaryDiffEqBDF(implicit-core stiff solvers over newton.jl)GROUP=OrdinaryDiffEqRosenbrockIIP=false Brown=true AutoForwardDiff(chunksize=3)× Rodas5P/Tsit5DA) — identical 2 errors on unmodified master (pre-existing Dual-conversion failure in the external NonlinearSolve initialization path; being investigated separately). Because that safetestset aborts the group, the remaining files were run directly on this branch: Rosenbrock AD Tests 56/56 pass, Rosenbrock Convergence Tests 169/169 passRunic produced no changes on the touched files.
Note: This PR should be ignored until reviewed by @ChrisRackauckas.
🤖 Generated with Claude Code