fix(discretization): fold symbolic initial conditions for MTK v1.45 compatibility#584
Merged
ChrisRackauckas merged 2 commits intoJul 8, 2026
Conversation
Refactor the handling of initial conditions to ensure proper folding of symbolic expressions.
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.
Root Cause
MTKBase v1.45.1-era
varmap_to_varsnow strictly enforcesSU.isconstchecks onu0map values. Meanwhile, MOL'sgenerate_ic_defaultsbuildsu0values via substitution (here viapde_substitute), which leaves function-call ICs as unfolded symbolic trees rather than literal constants (e.g.,cos(0.108)remains a symbolic tree). This mismatch triggersInitial condition underdefinederrors duringdiscretize(). ICs containing function calls fail, while plain/constant ICs (e.g., Burgers, Integrals) continue to pass.Fix
generate_ic_defaults.jl: Wrapped substitutedu0values inSymbolics.symbolic_to_float. This safely folds constant expressions into numbers while preserving genuinely symbolic/parametric expressions for MTK to resolve. Also removed a deadout = ...block.MethodOfLines.jl: Importedsymbolic_to_float.qa.jl: Added:symbolic_to_floatto theExplicitImportsignore list.Verification: Verified locally on failing groups. Diffusion, Components, Convection_WENO, Sol_Interface, Complex, and Wave_Eq_Staggered are now green. No regressions in previously passing groups (Burgers, Integrals, Stationary).
Reviewer Note
symbolic_to_floatis not public API, so I added it to the QA ignore list (following the:diff2termprecedent). Since public APIs likesimplifyorsubstituteno longer fold constants in Symbolics v7, this was the safest workaround. If there is a preferred public alternative, please let me know and I will gladly switch! (Note: I did not bisect the exact MTKBase commit, but the failure window aligns perfectly with the v1.45.1 release and the newSU.isconstchecks).CheckInitnow rejects the O(dx²) residual inMOL_1D_PDAE.jl. Passinginitializealg = BrownFullBasicInit()fixes it locally (matching theschroedinger.jlprecedent), but I left it out of this PR to strictly contain scope.