fix: structural cheap_iszero hook in CLIL dropzeros! (OOM on symbolic values after #97)#99
Open
baggepinnen wants to merge 2 commits into
Open
fix: structural cheap_iszero hook in CLIL dropzeros! (OOM on symbolic values after #97)#99baggepinnen wants to merge 2 commits into
baggepinnen wants to merge 2 commits into
Conversation
… values) dropzeros!(::SparseMatrixCLIL) (added in #97) called Base.iszero on the stored values. For symbolic value types (Num) that is a semantic, expansion-based zero test that OOMs on large coefficient expressions. Explicit stored zeros are always structural, so a structural check suffices: add a cheap_iszero hook (default Base.iszero) and overload it for Num/SymbolicT in ModelingToolkitTearing via SU._iszero. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This was referenced Jun 11, 2026
Draft
Contributor
|
Please cherry pick b281896 onto this branch |
Author
|
Done — branch fast-forwarded to |
Member
|
Should be rendered unnecessary by JuliaSymbolics/Symbolics.jl#1893 |
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.
Follow-up to #97, implementing the fix proposed in this comment.
Problem
dropzeros!(::SparseMatrixCLIL)(added in #97) callsBase.iszeroon the stored values. Inget_new_mmthe value type isNum, andiszero(::Num)is a semantic zero test (fraction_iszero→expand) that can be arbitrarily expensive. OnMultibodyComponents.examples.suspension.HalfCarthe process is OOM-killed insidedropzeros!at ~row 40 of a 295-rowNum-valuedmm(instrumented run; the pre-#97 commit completes fine).Fix
Explicit stored zeros (as produced by
sparsevecduplicate-index summation or alias cancellation) are always structural zeros, so a structural check suffices:StateSelection.CLIL.cheap_iszero(x) = iszero(x)— hook used bydropzeros!(::SparseMatrixCLIL)instead ofBase.iszero,ModelingToolkitTearingoverloads it forNum/SymbolicTviaSU._iszero(structuralConst(0)check, no expansion).Numeric value types are unaffected (the default is
Base.iszero).Validation
Base.iszerothrows (standing in for "arbitrarily expensive") must still round-trip throughdropzeros!correctly via the hook.🤖 Generated with Claude Code