Skip to content

Add ChainRulesCore support for SCCNonlinearProblem - #757

Merged
ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:scc-chainrules-support
Dec 19, 2025
Merged

ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:scc-chainrules-support

Conversation

@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member

Summary

  • Add ChainRulesCore extension for SCCNonlinearProblem to enable automatic differentiation
  • Route solve through internal scc_solve_up function that can be hooked by ChainRulesCore
  • Extension defines rrule for scc_solve_up that calls _concrete_solve_adjoint

Motivation

MTK v10 uses SCCNonlinearProblem for initialization of fully determined systems. Currently, differentiating through ODE solves with MTK v10 initialization returns zero gradients because SCCNonlinearProblem's solve bypasses the ChainRulesCore hooks that exist for regular NonlinearProblem.

This PR adds the necessary hooks so that AD systems (Zygote, etc.) can differentiate through SCCNonlinearProblem solves by calling into SciMLSensitivity's _concrete_solve_adjoint machinery.

Changes

  1. lib/SCCNonlinearSolve/src/SCCNonlinearSolve.jl:

    • Add scc_solve_up internal function (hookable by ChainRulesCore)
    • Route public solve → scc_solve_up → _scc_solve
    • Export scc_solve_up
  2. lib/SCCNonlinearSolve/ext/SCCNonlinearSolveChainRulesCoreExt.jl (new):

    • Define rrule for scc_solve_up that calls _concrete_solve_adjoint
  3. lib/SCCNonlinearSolve/Project.toml:

    • Add ChainRulesCore as weak dependency
    • Register extension

Related

This requires a corresponding PR to SciMLSensitivity.jl that adds _concrete_solve_adjoint implementations for SCCNonlinearProblem.

Test plan

  • Existing tests pass
  • MTK v10 initialization differentiation tests pass (in SciMLSensitivity.jl)

🤖 Generated with Claude Code

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
ChrisRackauckas merged commit 3533027 into SciML:master Dec 19, 2025
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]>
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]>
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]>
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