Repository navigation
Add ChainRulesCore support for SCCNonlinearProblem - #757
Merged
ChrisRackauckas merged 1 commit intoDec 19, 2025
Merged
Conversation
This enables automatic differentiation through SCCNonlinearProblem solves by adding a ChainRulesCore extension that hooks into SciMLSensitivity's adjoint machinery. Changes: - Add `scc_solve_up` internal function that can be hooked by ChainRulesCore - Route public `solve` through `scc_solve_up` → `_scc_solve` - Add ChainRulesCore weak dependency and extension - Extension defines rrule for `scc_solve_up` that calls `_concrete_solve_adjoint` This is needed to fix zero gradients when differentiating through MTK v10 initialization which uses SCCNonlinearProblem. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
ChrisRackauckas-Claude
force-pushed
the
scc-chainrules-support
branch
from
December 19, 2025 21:18
2e4a8a2 to
c18d3d9
Compare
ChrisRackauckas-Claude
pushed a commit
to ChrisRackauckas-Claude/SciMLSensitivity.jl
that referenced
this pull request
Dec 19, 2025
Adds specialized adjoint handling for SCCNonlinearProblem to enable differentiation through MTK v10 initialization. SCCNonlinearProblem cannot use SteadyStateAdjoint because its `f` field is `Returns(nothing)` - it represents a sequence of connected sub-problems rather than a single nonlinear system. Instead, we default to ForwardDiffSensitivity which can trace through any code. Changes: - Import SCCNonlinearProblem from SciMLBase - Add _concrete_solve_adjoint(prob::SCCNonlinearProblem, sensealg::Nothing) that defaults to ForwardDiffSensitivity - Add _concrete_solve_adjoint(prob::SCCNonlinearProblem, sensealg::ForwardDiffSensitivity) that computes gradients using ForwardDiff.jacobian - Add error-throwing dispatch for SteadyStateAdjoint with SCCNonlinearProblem Related: SciML/NonlinearSolve.jl#757 (adds ChainRulesCore hooks for SCCNonlinearSolve) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
2 tasks
ChrisRackauckas-Claude
pushed a commit
to ChrisRackauckas-Claude/SciMLSensitivity.jl
that referenced
this pull request
Dec 19, 2025
Adds specialized adjoint handling for SCCNonlinearProblem to enable differentiation through MTK v10 initialization. SCCNonlinearProblem cannot use SteadyStateAdjoint because its `f` field is `Returns(nothing)` - it represents a sequence of connected sub-problems rather than a single nonlinear system. Instead, we default to EnzymeAdjoint which propagates reverse-mode AD through the solve, using existing adjoint methods for each sub-problem. Changes: - Import SCCNonlinearProblem from SciMLBase - Add _concrete_solve_adjoint(prob::SCCNonlinearProblem, sensealg::Nothing) that defaults to EnzymeAdjoint - Add error-throwing dispatch for SteadyStateAdjoint with SCCNonlinearProblem The existing EnzymeAdjoint dispatch for AbstractNonlinearProblem handles the actual gradient computation. Related: SciML/NonlinearSolve.jl#757 (adds ChainRulesCore hooks for SCCNonlinearSolve) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
ChrisRackauckas-Claude
pushed a commit
to ChrisRackauckas-Claude/SciMLSensitivity.jl
that referenced
this pull request
Dec 19, 2025
Adds specialized adjoint handling for SCCNonlinearProblem to enable differentiation through MTK v10 initialization. SCCNonlinearProblem cannot use SteadyStateAdjoint because its `f` field is `Returns(nothing)` - it represents a sequence of connected sub-problems rather than a single nonlinear system. Instead, we default to EnzymeAdjoint which propagates reverse-mode AD through the solve, using existing adjoint methods for each sub-problem. Changes: - Import SCCNonlinearProblem from SciMLBase - Add _concrete_solve_adjoint(prob::SCCNonlinearProblem, sensealg::Nothing) that defaults to EnzymeAdjoint - Add error-throwing dispatch for SteadyStateAdjoint with SCCNonlinearProblem The existing EnzymeAdjoint dispatch for AbstractNonlinearProblem handles the actual gradient computation. Related: SciML/NonlinearSolve.jl#757 (adds ChainRulesCore hooks for SCCNonlinearSolve) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
ChrisRackauckas-Claude
pushed a commit
to ChrisRackauckas-Claude/SciMLSensitivity.jl
that referenced
this pull request
Dec 19, 2025
Adds specialized adjoint handling for SCCNonlinearProblem to enable differentiation through MTK v10 initialization. SCCNonlinearProblem cannot use SteadyStateAdjoint because its `f` field is `Returns(nothing)` - it represents a sequence of connected sub-problems rather than a single nonlinear system. Instead, we default to EnzymeAdjoint which propagates reverse-mode AD through the solve, using existing adjoint methods for each sub-problem. Changes: - Import SCCNonlinearProblem from SciMLBase - Add _concrete_solve_adjoint(prob::SCCNonlinearProblem, sensealg::Nothing) that defaults to EnzymeAdjoint - Add error-throwing dispatch for SteadyStateAdjoint with SCCNonlinearProblem The existing EnzymeAdjoint dispatch for AbstractNonlinearProblem handles the actual gradient computation. Related: SciML/NonlinearSolve.jl#757 (adds ChainRulesCore hooks for SCCNonlinearSolve) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
ChrisRackauckas-Claude
pushed a commit
to ChrisRackauckas-Claude/SciMLSensitivity.jl
that referenced
this pull request
Dec 20, 2025
Adds specialized adjoint handling for SCCNonlinearProblem to enable differentiation through MTK v10 initialization. SCCNonlinearProblem cannot use SteadyStateAdjoint because its `f` field is `Returns(nothing)` - it represents a sequence of connected sub-problems rather than a single nonlinear system. Instead, we default to EnzymeAdjoint which propagates reverse-mode AD through the solve, using existing adjoint methods for each sub-problem. Changes: - Import SCCNonlinearProblem from SciMLBase - Add _concrete_solve_adjoint(prob::SCCNonlinearProblem, sensealg::Nothing) that defaults to EnzymeAdjoint - Add error-throwing dispatch for SteadyStateAdjoint with SCCNonlinearProblem The existing EnzymeAdjoint dispatch for AbstractNonlinearProblem handles the actual gradient computation. Related: SciML/NonlinearSolve.jl#757 (adds ChainRulesCore hooks for SCCNonlinearSolve) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
ChrisRackauckas-Claude
pushed a commit
to ChrisRackauckas-Claude/SciMLSensitivity.jl
that referenced
this pull request
Dec 20, 2025
Adds specialized adjoint handling for SCCNonlinearProblem to enable differentiation through MTK v10 initialization. SCCNonlinearProblem cannot use SteadyStateAdjoint because its `f` field is `Returns(nothing)` - it represents a sequence of connected sub-problems rather than a single nonlinear system. Instead, we default to EnzymeAdjoint which propagates reverse-mode AD through the solve, using existing adjoint methods for each sub-problem. Changes: - Import SCCNonlinearProblem from SciMLBase - Add _concrete_solve_adjoint(prob::SCCNonlinearProblem, sensealg::Nothing) that defaults to EnzymeAdjoint - Add error-throwing dispatch for SteadyStateAdjoint with SCCNonlinearProblem The existing EnzymeAdjoint dispatch for AbstractNonlinearProblem handles the actual gradient computation. Related: SciML/NonlinearSolve.jl#757 (adds ChainRulesCore hooks for SCCNonlinearSolve) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
ChrisRackauckas-Claude
pushed a commit
to ChrisRackauckas-Claude/SciMLSensitivity.jl
that referenced
this pull request
Dec 20, 2025
Adds specialized adjoint handling for SCCNonlinearProblem to enable differentiation through MTK v10 initialization. SCCNonlinearProblem cannot use SteadyStateAdjoint because its `f` field is `Returns(nothing)` - it represents a sequence of connected sub-problems rather than a single nonlinear system. Instead, we default to EnzymeAdjoint which propagates reverse-mode AD through the solve, using existing adjoint methods for each sub-problem. Changes: - Import SCCNonlinearProblem from SciMLBase - Add _concrete_solve_adjoint(prob::SCCNonlinearProblem, sensealg::Nothing) that defaults to EnzymeAdjoint - Add error-throwing dispatch for SteadyStateAdjoint with SCCNonlinearProblem The existing EnzymeAdjoint dispatch for AbstractNonlinearProblem handles the actual gradient computation. Related: SciML/NonlinearSolve.jl#757 (adds ChainRulesCore hooks for SCCNonlinearSolve) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
ChrisRackauckas-Claude
pushed a commit
to ChrisRackauckas-Claude/SciMLSensitivity.jl
that referenced
this pull request
Dec 20, 2025
Adds specialized adjoint handling for SCCNonlinearProblem to enable differentiation through MTK v10 initialization. SCCNonlinearProblem cannot use SteadyStateAdjoint because its `f` field is `Returns(nothing)` - it represents a sequence of connected sub-problems rather than a single nonlinear system. Instead, we default to EnzymeAdjoint which propagates reverse-mode AD through the solve, using existing adjoint methods for each sub-problem. Changes: - Import SCCNonlinearProblem from SciMLBase - Add _concrete_solve_adjoint(prob::SCCNonlinearProblem, sensealg::Nothing) that defaults to EnzymeAdjoint - Add error-throwing dispatch for SteadyStateAdjoint with SCCNonlinearProblem The existing EnzymeAdjoint dispatch for AbstractNonlinearProblem handles the actual gradient computation. Related: SciML/NonlinearSolve.jl#757 (adds ChainRulesCore hooks for SCCNonlinearSolve) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
ChrisRackauckas-Claude
pushed a commit
to ChrisRackauckas-Claude/SciMLSensitivity.jl
that referenced
this pull request
Dec 20, 2025
Adds specialized adjoint handling for SCCNonlinearProblem to enable differentiation through MTK v10 initialization. SCCNonlinearProblem cannot use SteadyStateAdjoint because its `f` field is `Returns(nothing)` - it represents a sequence of connected sub-problems rather than a single nonlinear system. Instead, we default to EnzymeAdjoint which propagates reverse-mode AD through the solve, using existing adjoint methods for each sub-problem. Changes: - Import SCCNonlinearProblem from SciMLBase - Add _concrete_solve_adjoint(prob::SCCNonlinearProblem, sensealg::Nothing) that defaults to EnzymeAdjoint - Add error-throwing dispatch for SteadyStateAdjoint with SCCNonlinearProblem The existing EnzymeAdjoint dispatch for AbstractNonlinearProblem handles the actual gradient computation. Related: SciML/NonlinearSolve.jl#757 (adds ChainRulesCore hooks for SCCNonlinearSolve) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
ChrisRackauckas-Claude
pushed a commit
to ChrisRackauckas-Claude/SciMLSensitivity.jl
that referenced
this pull request
Dec 20, 2025
Adds specialized adjoint handling for SCCNonlinearProblem to enable differentiation through MTK v10 initialization. SCCNonlinearProblem cannot use SteadyStateAdjoint because its `f` field is `Returns(nothing)` - it represents a sequence of connected sub-problems rather than a single nonlinear system. Instead, we default to EnzymeAdjoint which propagates reverse-mode AD through the solve, using existing adjoint methods for each sub-problem. Changes: - Import SCCNonlinearProblem from SciMLBase - Add _concrete_solve_adjoint(prob::SCCNonlinearProblem, sensealg::Nothing) that defaults to EnzymeAdjoint - Add error-throwing dispatch for SteadyStateAdjoint with SCCNonlinearProblem The existing EnzymeAdjoint dispatch for AbstractNonlinearProblem handles the actual gradient computation. Related: SciML/NonlinearSolve.jl#757 (adds ChainRulesCore hooks for SCCNonlinearSolve) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
3 of 4 tasks
ChrisRackauckas-Claude
pushed a commit
to ChrisRackauckas-Claude/SciMLSensitivity.jl
that referenced
this pull request
Jan 21, 2026
Adds specialized adjoint handling for SCCNonlinearProblem to enable differentiation through MTK v10 initialization. SCCNonlinearProblem cannot use SteadyStateAdjoint because its `f` field is `Returns(nothing)` - it represents a sequence of connected sub-problems rather than a single nonlinear system. Instead, we default to EnzymeAdjoint which propagates reverse-mode AD through the solve, using existing adjoint methods for each sub-problem. Changes: - Import SCCNonlinearProblem from SciMLBase - Add _concrete_solve_adjoint(prob::SCCNonlinearProblem, sensealg::Nothing) that defaults to EnzymeAdjoint - Add error-throwing dispatch for SteadyStateAdjoint with SCCNonlinearProblem The existing EnzymeAdjoint dispatch for AbstractNonlinearProblem handles the actual gradient computation. Related: SciML/NonlinearSolve.jl#757 (adds ChainRulesCore hooks for SCCNonlinearSolve) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
ChrisRackauckas-Claude
pushed a commit
to ChrisRackauckas-Claude/SciMLSensitivity.jl
that referenced
this pull request
Feb 15, 2026
Adds specialized adjoint handling for SCCNonlinearProblem to enable differentiation through MTK v10 initialization. SCCNonlinearProblem cannot use SteadyStateAdjoint because its `f` field is `Returns(nothing)` - it represents a sequence of connected sub-problems rather than a single nonlinear system. Instead, we default to EnzymeAdjoint which propagates reverse-mode AD through the solve, using existing adjoint methods for each sub-problem. Changes: - Import SCCNonlinearProblem from SciMLBase - Add _concrete_solve_adjoint(prob::SCCNonlinearProblem, sensealg::Nothing) that defaults to EnzymeAdjoint - Add error-throwing dispatch for SteadyStateAdjoint with SCCNonlinearProblem The existing EnzymeAdjoint dispatch for AbstractNonlinearProblem handles the actual gradient computation. Related: SciML/NonlinearSolve.jl#757 (adds ChainRulesCore hooks for SCCNonlinearSolve) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
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.
Summary
solvethrough internalscc_solve_upfunction that can be hooked by ChainRulesCorerruleforscc_solve_upthat calls_concrete_solve_adjointMotivation
MTK v10 uses
SCCNonlinearProblemfor initialization of fully determined systems. Currently, differentiating through ODE solves with MTK v10 initialization returns zero gradients becauseSCCNonlinearProblem's solve bypasses the ChainRulesCore hooks that exist for regularNonlinearProblem.This PR adds the necessary hooks so that AD systems (Zygote, etc.) can differentiate through
SCCNonlinearProblemsolves by calling into SciMLSensitivity's_concrete_solve_adjointmachinery.Changes
lib/SCCNonlinearSolve/src/SCCNonlinearSolve.jl:
scc_solve_upinternal function (hookable by ChainRulesCore)solve→scc_solve_up→_scc_solvescc_solve_uplib/SCCNonlinearSolve/ext/SCCNonlinearSolveChainRulesCoreExt.jl (new):
rruleforscc_solve_upthat calls_concrete_solve_adjointlib/SCCNonlinearSolve/Project.toml:
Related
This requires a corresponding PR to SciMLSensitivity.jl that adds
_concrete_solve_adjointimplementations forSCCNonlinearProblem.Test plan
🤖 Generated with Claude Code