Repository navigation
Fix bounds transform for problems with initialization data and quasi-Newton algorithms - #955
Conversation
…Newton algs Two bugs in the box-constraint bounds transform: 1. `transform_bounded_problem` unconditionally read `alg.autodiff`, which threw a `FieldError` for algorithms without that field (e.g. `QuasiNewtonAlgorithm`, reached as part of the default polyalgorithm). Guard the access. 2. The wrapped function carried over the original `initialization_data`, which is defined in the *bounded* coordinates. Running it on the transformed problem interpreted the unbounded iterate `t` as a bounded state and corrupted the solution (e.g. ModelingToolkit `NonlinearProblem`s, which always attach initialization data, converged to `from_unbounded(root)` instead of `root`). Initialization is now run once in the original bounded space before transforming, and stripped from the transformed function so it isn't re-run in `t`-space. Co-Authored-By: Chris Rackauckas <[email protected]>
The umbrella `test/bounds_tests.jl` integration test exercised the fix through a full solve, but on Julia < 1.11 the umbrella resolves the *registered* NonlinearSolveBase (the `[sources]` path redirect to the in-repo sublibrary is ignored there), so the test ran against unpatched code and failed. Add a `transform_bounded_problem` unit test to NonlinearSolveBase's own test suite, which always runs against the in-repo code (incl. on lts), covering the quasi-Newton `autodiff`-access guard with a dummy algorithm that has no `autodiff` field. Gate the umbrella integration test on the loaded NonlinearSolveBase version so it only runs where the fix is present. Co-Authored-By: Chris Rackauckas <[email protected]>
|
Pushed a follow-up addressing the Cause: the umbrella Fix: moved the regression coverage into NonlinearSolveBase's own test suite ( Unrelated pre-existing failure: |
The bounds forwarded to `NonlinearProblem`/`NonlinearLeastSquaresProblem` are only retained through the `remake` that runs during problem construction as of SciMLBase 3.18 (SciML/SciMLBase.jl#1372); on older versions they are silently dropped. The solve-time correctness for bounded problems carrying initialization data is provided by NonlinearSolveBase 2.30.3 (SciML/NonlinearSolve.jl#955), which the test environment resolves to. Co-Authored-By: Chris Rackauckas <[email protected]>
Note
Draft — please ignore until reviewed by @ChrisRackauckas.
Two bugs in the box-constraint bounds transform (
lib/NonlinearSolveBase/src/bounds_transform.jl), both surfaced while wiring ModelingToolkit'sboundsmetadata through to nonlinear solvers (SciML/ModelingToolkit.jl#4308).1.
alg.autodiffFieldErroron quasi-Newton algorithmstransform_bounded_problemunconditionally readalg.autodiffto choose the cache type.QuasiNewtonAlgorithm(Broyden/Klement, reached as part of the defaultFastShortcutNonlinearPolyalg) has noautodifffield, so solving a bounded problem with the default polyalgorithm threw:Fixed by guarding the access with
hasproperty.2. Initialization data corrupts the transformed solution
The wrapped problem function carried over the original
initialization_data, which is defined in the bounded coordinates. The transform reparametrizes the problem into an unbounded variablet; running the bounded-space initialization on the transformed problem interprets the iteratetas a bounded state and corrupts the result.Concretely, every ModelingToolkit
NonlinearProblemattaches initialization data, so a bounded MTK problem converged tofrom_unbounded(root)instead ofroot:Initialization is now run once in the original bounded space (
run_bounded_initialization) before the transform, and stripped from the transformed function (build_initializeprob = Val{false}) so it isn't re-run int-space. Raw problems without initialization data are unaffected.Tests
:boundstestitem covering the default polyalgorithm and quasi-Newton algorithms (Broyden,Klement) on a boundedNonlinearProblem(exercises fix Modify the benchmark and tests #1 and confirms the correct root is found).test/bounds_tests.jlscenarios verified locally against this branch (no regression).Dependencies
Builds on SciML/SciMLBase.jl#1372 (so
remakepreserveslb/ub, which the transform's solution-reconstruction relies on).🤖 Generated with Claude Code