Repository navigation
Restore cache.A before QR safety fallback after in-place LU corruption - #888
Merged
ChrisRackauckas merged 2 commits intoFeb 19, 2026
Merged
ChrisRackauckas merged 2 commits into
ChrisRackauckas merged 2 commits into
Conversation
In-place LU factorizations (MKLLUFactorization, AppleAccelerateLU, etc.) corrupt cache.A via getrf!. When LU fails on a singular matrix and the DefaultLinearSolver safety fallback triggers, the QR fallback was operating on the corrupted matrix, producing incorrect results. Fix: Store a reference to the original prob.A in DefaultLinearSolverInit.A_backup (zero-cost since alias_A=false means cache.A is already a copy). Before the QR fallback, restore cache.A via copyto!. When alias_A=true (cache.A === prob.A), skip the fallback with a warning since there is no clean backup available. Fixes SciML#887 Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Replace @warn with @SciMLMessage(:default_lu_fallback) in the aliased fallback warning path for consistency with the rest of the codebase - Add regression test verifying QR fallback produces correct results on singular matrices and that prob.A is preserved as backup Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
ChrisRackauckas-Claude
force-pushed
the
fix-mkl-fallback-corruption
branch
from
February 19, 2026 12:26
6821ab2 to
1e0d4b0
Compare
This was referenced Feb 19, 2026
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
cache.Aviagetrf!. When LU fails on a singular matrix andDefaultLinearSolver's safety fallback triggers QR, the QR operates on the corrupted matrix producing incorrect results.prob.AinDefaultLinearSolverInit.A_backup(zero-cost: whenalias_A=false(default),cache.Ais already a copy soprob.Ais untouched). Before QR fallback, restore viacopyto!(cache.A, backup).alias_A=true(cache.A === prob.A), skip the fallback with a clear warning since there is no clean backup.Fixes #887
Root Cause
MKLLUFactorization(and other in-place LU variants) call LAPACK'sgetrf!which overwritescache.Ain-place with the LU factors. When the matrix is singular,getrf!returns an error code andsolve!returnsReturnCode.Failure. TheDefaultLinearSolverthen falls back toQRFactorization(ColumnNorm()), butcache.Astill contains the corrupted LU factors rather than the original matrix. This causes the QR fallback to produce garbage results.This was discovered via Julia 1.11 vs 1.12 behavioral difference: MKL_jll loads on 1.11 (selecting
MKLLUFactorization) but not on 1.12 (selectingLUFactorizationwhich useslu(A, check=false)— non-destructive).Test plan
DefaultLinearSolvermatches directQRFactorization(ColumnNorm())resultprob.Ais not modified (serves as backup)A_backupreferencesprob.A(not the copy) withalias_A=falsealias_A=truecorrectly detected (cache.A === A_backup)🤖 Generated with Claude Code