Skip to content

Fix jacobian2W! DimensionMismatch for ScalarOperator mass matrix (#3915)#3916

Open
singhharsh1708 wants to merge 1 commit into
SciML:masterfrom
singhharsh1708:fix-scalaroperator-massmatrix-buildJW
Open

Fix jacobian2W! DimensionMismatch for ScalarOperator mass matrix (#3915)#3916
singhharsh1708 wants to merge 1 commit into
SciML:masterfrom
singhharsh1708:fix-scalaroperator-massmatrix-buildJW

Conversation

@singhharsh1708

Copy link
Copy Markdown
Contributor

Fixes #3915.

Bug

jacobian2W!/jacobian2W special-case mass_matrix isa UniformScaling to skip the axes(mass_matrix) == axes(W) boundscheck and use the scalar directly. ScalarOperator is the same thing (λ·I) but isn't a UniformScaling, and reports axes(mm) == (), so it falls through to the boundscheck meant for full matrices and throws.

using OrdinaryDiffEqSDIRK, SciMLOperators
f = ODEFunction((du, u, p, t) -> (du .= -u); mass_matrix = ScalarOperator(1.0))
solve(ODEProblem(f, [1.0], (0.0, 1.0)), TRBDF2())
# DimensionMismatch: W: (Base.OneTo(1), Base.OneTo(1)), mass matrix: ()

IdentityOperator doesn't hit this since its axes happen to match W.

Fix

Treat ScalarOperator the same as UniformScaling in both jacobian2W! methods and jacobian2W, 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 a ScalarOperator mass matrix reaches once the entry crash and get_differential_vars are both already fixed).

Tests

New scalar_operator_massmatrix_tests.jl: jacobian2W!/jacobian2W on ScalarOperator match the UniformScaling result directly. Also verified end-to-end (not in the test suite, checked locally): TRBDF2() on Lorenz with mass_matrix = ScalarOperator(2.0) now succeeds and matches mass_matrix = 2.0*I to the solver's tolerance.

OrdinaryDiffEqDifferentiation Core suite passes (24/24, including the new tests).

AI Disclosure

Claude assisted with this work.

@singhharsh1708
singhharsh1708 force-pushed the fix-scalaroperator-massmatrix-buildJW branch 2 times, most recently from 2d951f4 to 5063be8 Compare July 18, 2026 07:33
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
singhharsh1708 force-pushed the fix-scalaroperator-massmatrix-buildJW branch from 5063be8 to 08be517 Compare July 21, 2026 14:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ScalarOperator mass matrix crashes in jacobian2W! (DimensionMismatch)

1 participant