Skip to content

Apply the chain rule to bounded-problem derivative callbacks - #1269

Merged
ChrisRackauckas merged 2 commits into
SciML:masterfrom
ChrisRackauckas-Claude:fix/bounded-transform-derivatives
Sep 13, 2026
Merged

ChrisRackauckas merged 2 commits into
SciML:masterfrom
ChrisRackauckas-Claude:fix/bounded-transform-derivatives

Conversation

@ChrisRackauckas-Claude

@ChrisRackauckas-Claude ChrisRackauckas-Claude commented Sep 13, 2026 •

Copy link
Copy Markdown
Member

Bounded problems transformed to unbounded coordinates passed the transformed state directly to analytic derivative callbacks and omitted the inverse-transform derivative. For f(u) = u² - 4, u = 1, and bounds [0, 10], this produced a Jacobian of -4.394449154672439 instead of 1.7999999999999992.

Evaluate jac, jvp, vjp, and paramjac in physical coordinates and apply the chain rule to state derivatives. Sparse Jacobians retain their stored-zero structure even when transform derivatives vanish, supplied callbacks remain in use, and scalar states now work through transformation and solution reconstruction. The defect is present in the original bounds-transform commit; executing that original transform against current dependencies reproduces the incorrect Jacobian above.

Please ignore this PR until reviewed by @ChrisRackauckas.

Verification

The same array-derivative regression tests were run on unmodified master and with the fix using Julia 1.13.0:

# Unfixed (compiled-modules=no)
analytic derivatives follow bounded coordinates | 20 passed, 64 failed, 84 total
# Fixed
analytic derivatives follow bounded coordinates | 84 passed, 84 total

The complete focused file also covers scalar derivatives and scalar solution reconstruction:

julia +1.13.0 --compiled-modules=existing --project=. lib/NonlinearSolveBase/test/bounds_transform.jl
bounds transform handles algorithms without an `autodiff` field |   8 /   8
analytic derivatives follow bounded coordinates               |  84 /  84
zero transform derivatives preserve sparse structure          |  16 /  16
scalar analytic derivatives follow bounded coordinates        |  30 /  30

The array cases cover in-place/out-of-place callbacks, dense/sparse rectangular Jacobians, all four bound configurations, JVP/VJP, parameter Jacobians, and repeated states/parameters.

GROUP=Core julia +1.13.0 --compiled-modules=existing --project=lib/NonlinearSolveBase -e 'using Pkg; Pkg.test(; julia_args=["--compiled-modules=existing"])'
GROUP=QA julia +1.13.0 --compiled-modules=existing --project=lib/NonlinearSolveBase -e 'using Pkg; Pkg.test(; julia_args=["--compiled-modules=existing"])'

Core: 523 assertions passed; QA: 20 assertions passed. Both end with Testing NonlinearSolveBase tests passed. Runic, typos, and git diff --check pass.

The root Core group passed 1,028 assertions at 59ffc83c4, including 18 supplemental Newton assertions across dense, sparse, Krylov JVP/VJP, and scalar solves:

GROUP=Core julia +1.13.0 --compiled-modules=existing --project=. -e 'using Pkg; Pkg.test(; julia_args=["--compiled-modules=existing"])'

Those integration tests are being carried by the dependent bounded-default PR, which raises the Base minimum version; this prerequisite keeps its regression tests inside Base's own suite.

A second regression test exercises derivative underflow at transformed coordinates [-1000, 0]. Broadcast scaling incorrectly removed stored zeros; public rmul!(J, Diagonal(scale)) preserves the structure required by cached sparse symbolic factorizations:

# Before structure-preserving scaling
colptr: [1, 1, 3] != [1, 3, 5]
rowvals: [1, 2] != [1, 2, 1, 2]
nnz: 2 != 4
zero transform derivatives preserve sparse structure | 1 passed, 3 failed, 1 error
# After
zero transform derivatives preserve sparse structure | 16 passed, 16 total

Three 1,024-variable sparse diffusion cases that previously threw snlu! requires the same sparsity pattern as the analyzed matrix now return solutions without exceptions. The root case returns Success with residual 3.06e-10; the two active-bound least-squares cases return MaxIters with projected gradients 3.30e-13 and 3.94e-13. These latter two remain benchmark failures under the successful-retcode criterion. The final structural-zero change was checked with the complete Base Core/QA groups and those three solver-level reproductions; root Core was not rerun for that follow-up.

GPU/downstream jobs and prerelease Julia were not run. Docs were not built because this changes private implementation only. Arbitrary custom operator-valued jac callbacks were not validated; the tested operator path uses JVP/VJP callbacks.

🤖 Generated with Codex CLI 0.154.0 (model: gpt-6-astra; session: local transcript /home/crackauc/.codex/sessions/2026/09/12/rollout-2026-09-12T04-30-15-01a094bd-179a-7972-97ec-36badb9448cd.jsonl).

ChrisRackauckas and others added 2 commits September 13, 2026 08:20
Evaluate analytic Jacobians and products in physical coordinates and apply the
inverse-transform derivative to Jacobian columns and JVP/VJP directions.
Preserve sparse storage and provided parameter Jacobians. Handle scalar states
through transformation and solution reconstruction.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Codex <[email protected]>
Agent-Harness: Codex CLI 0.154.0
Agent-Model: gpt-6-astra
Agent-Session: local transcript /home/crackauc/.codex/sessions/2026/09/12/rollout-2026-09-12T04-30-15-01a094bd-179a-7972-97ec-36badb9448cd.jsonl
Use in-place right multiplication by the transform's diagonal derivative so
stored zeros remain available to cached sparse symbolic factorizations.
Exercise saturated coordinates and subsequent callback reuse.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Codex <[email protected]>
Agent-Harness: Codex CLI 0.154.0
Agent-Model: gpt-6-astra
Agent-Session: local transcript /home/crackauc/.codex/sessions/2026/09/12/rollout-2026-09-12T04-30-15-01a094bd-179a-7972-97ec-36badb9448cd.jsonl
@ChrisRackauckas-Claude
ChrisRackauckas-Claude force-pushed the fix/bounded-transform-derivatives branch from a6dad2d to dc007c8 Compare September 13, 2026 12:20
@ChrisRackauckas
ChrisRackauckas marked this pull request as ready for review September 13, 2026 13:36
@ChrisRackauckas
ChrisRackauckas merged commit 9ed5110 into SciML:master Sep 13, 2026
100 checks passed
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