Skip to content

get_differential_vars: accept IdentityOperator and ScalarOperator mass matrices - #3837

Merged
ChrisRackauckas merged 1 commit into
SciML:masterfrom
singhharsh1708:fix/get-differential-vars-operator-mm
Jul 12, 2026
Merged

ChrisRackauckas merged 1 commit into
SciML:masterfrom
singhharsh1708:fix/get-differential-vars-operator-mm

Conversation

@singhharsh1708

Copy link
Copy Markdown
Member

Follow-up to #3814. Once SciML/SciMLOperators.jl#400 lands the issingular methods, IdentityOperator and ScalarOperator mass matrices still hit MethodError: no method matching iterate(::IdentityOperator) inside get_differential_vars at lib/OrdinaryDiffEqCore/src/misc_utils.jl:143.

Root cause: the function reaches elseif all(!iszero, mm) and tries to iterate the operator.

Fix: treat IdentityOperator and ScalarOperator the same as UniformScaling (both represent scalar-uniform mass matrices) and return nothing early.

if mm isa UniformScaling ||
        mm isa SciMLOperators.IdentityOperator ||
        mm isa SciMLOperators.ScalarOperator
    return nothing
elseif ...

End-to-end verified against the #3814 repro with both fixes in place:

IdentityOperator + TRBDF2 (IIP) => OK, retcode=Success
ScalarOperator   + TRBDF2 (IIP) => (DimensionMismatch further down — separate downstream bug, out of scope here)

Direct regression test added in algebraic_vars_detection_tests.jl calls get_differential_vars on both operator kinds and asserts nothing.

Depends on SciML/SciMLOperators.jl#400 for full end-to-end.

@singhharsh1708
singhharsh1708 force-pushed the fix/get-differential-vars-operator-mm branch from 2e98253 to 93382fd Compare July 12, 2026 19:39
@singhharsh1708

singhharsh1708 commented Jul 12, 2026 •

Copy link
Copy Markdown
Member Author

Rebased on master. Also fixed a hole in my own first pass.

The original patch returned nothing (all variables differential) for any ScalarOperator. That's wrong when the scalar is zero: ScalarOperator(0.0) is 0·I, so every variable is algebraic. It also contradicted issingular(α::ScalarOperator) = iszero(α.val) from SciML/SciMLOperators.jl#400.

ScalarOperator now matches what the equivalent dense mass matrix already gives:

ScalarOperator(0.0)  =>  Bool[0, 0, 0]
zeros(3, 3)          =>  Bool[0, 0, 0]

IdentityOperator still returns nothing unconditionally — it is always I, never singular.

Test covers the singular case. OrdinaryDiffEqCore suite passes locally on Julia 1.12; Runic clean.

@ChrisRackauckas
ChrisRackauckas merged commit 62b3d02 into SciML:master Jul 12, 2026
197 of 249 checks passed
@singhharsh1708
singhharsh1708 deleted the fix/get-differential-vars-operator-mm branch July 12, 2026 20:13
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.

2 participants