Skip to content

Commit e885edf

Browse files
ChrisRackauckas-ClaudeChrisRackauckasclaude
authored
Fix SCCNonlinearProblem not having u0 field (issue #758) (#759)
* Fix SCCNonlinearProblem not having u0 field (issue #758) SCCNonlinearProblem does not have a u0 field - each subproblem has its own u0. The solve function was incorrectly trying to access prob.u0 when u0 was not provided, causing a FieldError. Changes: - Remove the u0 = prob.u0 fallback since SCCNonlinearProblem has no u0 field - Add regression test to prevent this from happening again Closes #758 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]> * Bump SCCNonlinearSolve version to 1.8.0 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]> * Fix test to properly import SciMLBase The test item needs to explicitly use SciMLBase to access NonlinearProblem and other types from the module. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]> * Fix ExplicitImports check in ChainRulesCore extension Use `import SCCNonlinearSolve: ...` instead of `using SCCNonlinearSolve` to avoid implicit import of the module name, which causes ExplicitImports tests to fail on macOS CI. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]> * Fix code formatting in test file Apply SciML formatting style (spaces around operators and assignments) to the test file to pass CI code-style checks. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]> * Fix indentation in ChainRulesCore extension Align continuation indent for multi-line import statement. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]> * Fix formatting: add spaces around ≈ operator Restore spaces around ≈ operator that were accidentally removed. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]> --------- Co-authored-by: ChrisRackauckas <[email protected]> Co-authored-by: Claude Opus 4.5 <[email protected]>
1 parent 9f462d1 commit e885edf

File tree

4 files changed

+41
-6
lines changed

4 files changed

+41
-6
lines changed

lib/SCCNonlinearSolve/Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "SCCNonlinearSolve"
22
uuid = "9dfe8606-65a1-4bb3-9748-cb89d1561431"
3+
version = "1.8.0"
34
authors = ["Avik Pal <[email protected]> and contributors"]
4-
version = "1.7.0"
55

66
[deps]
77
CommonSolve = "38540f10-b2f7-11e9-35d8-d573e4eb0ff2"
@@ -23,8 +23,8 @@ ChainRulesCore = "1"
2323
CommonSolve = "0.2.4"
2424
ExplicitImports = "1.5"
2525
Hwloc = "3"
26-
LinearAlgebra = "1.10"
2726
InteractiveUtils = "<0.0.1, 1"
27+
LinearAlgebra = "1.10"
2828
NonlinearProblemLibrary = "0.1.2"
2929
NonlinearSolve = "4.8"
3030
NonlinearSolveBase = "2.1"

lib/SCCNonlinearSolve/ext/SCCNonlinearSolveChainRulesCoreExt.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
module SCCNonlinearSolveChainRulesCoreExt
22

3-
using SCCNonlinearSolve
4-
using SCCNonlinearSolve: SCCAlg, scc_solve_up
3+
import SCCNonlinearSolve: SCCAlg, scc_solve_up
54
using SciMLBase: SCCNonlinearProblem, AbstractSensitivityAlgorithm, ChainRulesOriginator,
6-
_concrete_solve_adjoint
5+
_concrete_solve_adjoint
76

87
import ChainRulesCore
98

lib/SCCNonlinearSolve/src/SCCNonlinearSolve.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ end
3636

3737
function CommonSolve.solve(prob::SciMLBase.SCCNonlinearProblem, alg::SCCAlg;
3838
sensealg = nothing, u0 = nothing, p = nothing, kwargs...)
39-
u0 = u0 !== nothing ? u0 : prob.u0
39+
# Note: SCCNonlinearProblem does not have a u0 field - each subproblem has its own u0.
40+
# The u0 parameter here is only used for AD hooks, not for actual solving.
4041
p = p !== nothing ? p : prob.p
4142
scc_solve_up(prob, sensealg, u0, p, alg; kwargs...)
4243
end

lib/SCCNonlinearSolve/test/core_tests.jl

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,41 @@ end
7676
@test sol manualscc scc_sol_default
7777
end
7878

79+
@testitem "SCCNonlinearProblem solve without explicit u0 (issue #758)" setup=[CoreRootfindTesting] tags=[:core] begin
80+
# Regression test for https://github.com/SciML/NonlinearSolve.jl/issues/758
81+
# SCCNonlinearProblem does not have a u0 field, so calling solve() without
82+
# explicit u0 should not try to access prob.u0
83+
using SciMLBase
84+
using SCCNonlinearSolve
85+
import NonlinearSolve
86+
87+
# Create simple nonlinear subproblems (OOP style, returning vectors)
88+
f1(u, p) = [u[1]^2 - 2.0]
89+
f2(u, p) = [u[1] - 1.0]
90+
91+
prob1 = NonlinearProblem(f1, [1.0])
92+
prob2 = NonlinearProblem(f2, [1.0])
93+
94+
# Create explicit functions (identity - just pass through)
95+
explicitfun1!(p, sols) = nothing
96+
explicitfun2!(p, sols) = nothing
97+
98+
# Create the SCC problem using the same pattern as existing tests
99+
scc_prob = SciMLBase.SCCNonlinearProblem(
100+
(prob1, prob2),
101+
SciMLBase.Void{Any}.([explicitfun1!, explicitfun2!])
102+
)
103+
104+
# This should not throw an error about prob.u0 field
105+
sol = SciMLBase.solve(scc_prob)
106+
107+
@test SciMLBase.successful_retcode(sol)
108+
# First subproblem: u^2 = 2 → u = sqrt(2)
109+
@test sol.u[1] sqrt(2.0)
110+
# Second subproblem: u = 1
111+
@test sol.u[2] 1.0
112+
end
113+
79114
@testitem "SCC Residuals Transfer" setup=[CoreRootfindTesting] tags=[:core] begin
80115
using NonlinearSolveFirstOrder
81116
using LinearAlgebra

0 commit comments

Comments
 (0)