fix: don't leak the operating point into unbounded nonlinear bounds - #4902
Draft
ChrisRackauckas-Claude wants to merge 1 commit into
Draft
Conversation
`generate_nonlinear_bounds` resolves symbolic bounds by merging the operating point into the bounds map. The map is seeded only for finite bounds, so the merge also hands every unbounded unknown its operating-point value. That pins the unknown to `lb == ub == u0`, and the solver's bounds transform then evaluates `logit((u - lb) / (ub - lb))` = `logit(0/0)` = `NaN`. Restore the `±Inf` sentinel after resolution for entries whose metadata bound was already `±Inf`. The all-numeric branch is unaffected. Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
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.
Please ignore this PR until it has been reviewed by @ChrisRackauckas.
What changed and why
generate_nonlinear_boundsresolves symbolic bounds (e.g.bounds = (some_parameter, 1.0)) by merging the operating point into the bounds map. The map is seeded only for finite bounds:so the merge also hands every unbounded unknown its operating-point value. That pins the unknown to
lb == ub == u0, and NonlinearSolveBase's bounds transform then computeslogit((u - lb) / (ub - lb))=logit(0/0)=NaN.This fix restores the
±Infsentinel after resolution for entries whose metadata bound was already±Inf, leaving the resolution machinery (and the ability of a bound to reference another symbol) intact. The all-numeric branch never entered this path and is unchanged.Found while investigating #4672. It is not that issue's reported failure — see the analysis in that thread — but it produces the
NaNthat issue's title describes, via a different route. It only fires when at least one bound is symbolic, which is why the numeric-bounds MWEs in #4672 don't hit it.Failing before / passing after
Test added to the existing bounds testset in
lib/ModelingToolkitBase/test/nonlinearsystem.jl.Before the fix (test applied to unmodified source at
453c45c08e, source change stashed):Observed values on the unfixed code:
After the fix:
Verification
GROUP=InterfaceII(the group that ownsnonlinearsystem.jl), on this branch:Runic: clean on both changed files.
typos: clean.Not verified / known gaps
GROUP=QAfails on this branch — but it fails identically on unmodifiedmaster. I ran QA on a clean453c45c08eworktree to check: both give10 passed, 1 failed, both failing the AquaPiracycheck atAqua/src/piracies.jl:244, with a byte-identical method list (src/ModelingToolkitBase.jl:119,123,131,132,133andsrc/problems/jumpproblem.jl:257,263). None of those files are touched here. Pre-existing master failure, reported separately; not introduced by this PR.restore_infinite_boundsis an internal helper; its docstring is not registered indocs/).Worth pushing back on
±Infup front. Seeding would be tidier, but it would change behaviour for a bound that references another unknown: today such a bound resolves through that unknown's operating-point value, and seeding would make it resolve through that unknown's bound instead. I kept the existing semantics rather than silently changing them.Environment: Julia 1.12.6, ModelingToolkitBase v1.61.0, NonlinearSolve v4.26.0, base commit
453c45c08e.