Fix jacobian2W! DimensionMismatch for ScalarOperator mass matrix (#3915) - #3916
Open
singhharsh1708 wants to merge 1 commit into
Open
Fix jacobian2W! DimensionMismatch for ScalarOperator mass matrix (#3915)#3916singhharsh1708 wants to merge 1 commit into
singhharsh1708 wants to merge 1 commit into
Conversation
singhharsh1708
force-pushed
the
fix-scalaroperator-massmatrix-buildJW
branch
3 times, most recently
from
July 21, 2026 14:31
5063be8 to
08be517
Compare
singhharsh1708
force-pushed
the
fix-scalaroperator-massmatrix-buildJW
branch
3 times, most recently
from
August 1, 2026 21:26
e06103c to
15df5ff
Compare
ScalarOperator reports axes(mm) == (), unlike UniformScaling which jacobian2W! already special-cases, so it fell into the boundscheck meant for full matrices. Fixes SciML#3915.
singhharsh1708
force-pushed
the
fix-scalaroperator-massmatrix-buildJW
branch
from
August 1, 2026 22:04
15df5ff to
4386090
Compare
Member
|
A ScalarOperator mass matrix doesn't seem valid, how does that come up? |
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.
Fixes #3915.
Bug
jacobian2W!/jacobian2Wspecial-casemass_matrix isa UniformScalingto skip theaxes(mass_matrix) == axes(W)boundscheck and use the scalar directly.ScalarOperatoris the same thing (λ·I) but isn't aUniformScaling, and reportsaxes(mm) == (), so it falls through to the boundscheck meant for full matrices and throws.IdentityOperatordoesn't hit this since itsaxeshappen to matchW.Fix
Treat
ScalarOperatorthe same asUniformScalingin bothjacobian2W!methods andjacobian2W, via_is_scalar_massmatrix/_scalar_massmatrix_λ. Follows #3814 → SciMLOperators#400 → #3837, the same operator-mass-matrix chain, one step further (this is the first place aScalarOperatormass matrix reaches once the entry crash andget_differential_varsare both already fixed).Tests
New
scalar_operator_massmatrix_tests.jlcoversjacobian2W!through both the::Matrixspecialization and the generic::AbstractMatrixmethod (reached with a sparseJ), the out-of-placejacobian2W, and an end-to-endTRBDF2()solve of the case from #3915 — Lorenz withmass_matrix = ScalarOperator(2.0)againstmass_matrix = 2.0*I. 7 assertions; the file errors on master with the reportedDimensionMismatch.Those two solves are in fact bit-identical (max abs difference 0.0 over
saveat = 0:0.1:1atabstol = reltol = 1e-12, identical accepted-step counts) for TRBDF2, KenCarp4, FBDF and Rodas5P, and Rodas5P agrees to 7e-12 with a 1e-14 reference solve of the equivalentM = I,f/2problem.OrdinaryDiffEqDifferentiationCore suite: 65 passes across 10 testsets (master: 61 across 9). QA also passes (JET 1/1, Aqua/ExplicitImports 15/15).Scope
This fixes the in-place W assembly, which is what #3915 reports. Still failing and unchanged by this PR, with different errors: out-of-place and StaticArrays
ScalarOperatormass matrices (Out-of-place NLNewton does not support non-concrete W, and anAssertionErrorin theStaticWOperatorpath), and a sparsejac_prototypecombined with aScalarOperatormass matrix, which fails earlier inprepare_user_sparsity.AI Disclosure
Claude assisted with this work.