Skip to content

Support LinearProblems in SCCs #633

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 26, 2025
Merged

Support LinearProblems in SCCs #633

merged 5 commits into from
Jun 26, 2025

Conversation

ChrisRackauckas
Copy link
Member

No description provided.

@ChrisRackauckas ChrisRackauckas merged commit cf7c6be into master Jun 26, 2025
9 of 15 checks passed
@ChrisRackauckas ChrisRackauckas deleted the linscc branch June 26, 2025 12:19
Comment on lines +10 to +17
du[1]=cos(u[2])-u[1]
du[2]=sin(u[1]+u[2])+u[2]
du[3]=2u[4]+u[3]+1.0
du[4]=u[5]^2+u[4]
du[5]=u[3]^2+u[5]
du[6]=u[1]+u[2]+u[3]+u[4]+u[5]+2.0u[6]+2.5u[7]+1.5u[8]
du[7]=u[1]+u[2]+u[3]+2.0u[4]+u[5]+4.0u[6]-1.5u[7]+1.5u[8]
du[8]=u[1]+2.0u[2]+3.0u[3]+5.0u[4]+6.0u[5]+u[6]-u[7]-u[8]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
du[1]=cos(u[2])-u[1]
du[2]=sin(u[1]+u[2])+u[2]
du[3]=2u[4]+u[3]+1.0
du[4]=u[5]^2+u[4]
du[5]=u[3]^2+u[5]
du[6]=u[1]+u[2]+u[3]+u[4]+u[5]+2.0u[6]+2.5u[7]+1.5u[8]
du[7]=u[1]+u[2]+u[3]+2.0u[4]+u[5]+4.0u[6]-1.5u[7]+1.5u[8]
du[8]=u[1]+2.0u[2]+3.0u[3]+5.0u[4]+6.0u[5]+u[6]-u[7]-u[8]
du[1] = cos(u[2]) - u[1]
du[2] = sin(u[1] + u[2]) + u[2]
du[3] = 2u[4] + u[3] + 1.0
du[4] = u[5]^2 + u[4]
du[5] = u[3]^2 + u[5]
du[6] = u[1] + u[2] + u[3] + u[4] + u[5] + 2.0u[6] + 2.5u[7] + 1.5u[8]
du[7] = u[1] + u[2] + u[3] + 2.0u[4] + u[5] + 4.0u[6] - 1.5u[7] + 1.5u[8]
du[8] = u[1] + 2.0u[2] + 3.0u[3] + 5.0u[4] + 6.0u[5] + u[6] - u[7] - u[8]

Comment on lines +19 to +20
prob=NonlinearProblem(f, zeros(8))
sol=solve(prob, NewtonRaphson())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
prob=NonlinearProblem(f, zeros(8))
sol=solve(prob, NewtonRaphson())
prob = NonlinearProblem(f, zeros(8))
sol = solve(prob, NewtonRaphson())

Comment on lines +22 to +23
u0=zeros(2)
p=zeros(3)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
u0=zeros(2)
p=zeros(3)
u0 = zeros(2)
p = zeros(3)

Comment on lines +26 to +27
du[1]=cos(u[2])-u[1]
du[2]=sin(u[1]+u[2])+u[2]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
du[1]=cos(u[2])-u[1]
du[2]=sin(u[1]+u[2])+u[2]
du[1] = cos(u[2]) - u[1]
du[2] = sin(u[1] + u[2]) + u[2]

Comment on lines +29 to +30
explicitfun1(p, sols)=nothing
prob1=NonlinearProblem(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
explicitfun1(p, sols)=nothing
prob1=NonlinearProblem(
explicitfun1(p, sols) = nothing
prob1 = NonlinearProblem(

Comment on lines +46 to +48
A3=[2.0 2.5 1.5; 4.0 -1.5 1.5; 1.0 -1.0 -1.0]
b3=p # b will be updated by explicitfun3
prob3=LinearProblem(A3, b3, zeros(3))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
A3=[2.0 2.5 1.5; 4.0 -1.5 1.5; 1.0 -1.0 -1.0]
b3=p # b will be updated by explicitfun3
prob3=LinearProblem(A3, b3, zeros(3))
A3 = [2.0 2.5 1.5; 4.0 -1.5 1.5; 1.0 -1.0 -1.0]
b3 = p # b will be updated by explicitfun3
prob3 = LinearProblem(A3, b3, zeros(3))

Comment on lines +50 to +53
p[1]=-(sols[1][1]+sols[1][2]+sols[2][1]+sols[2][2]+sols[2][3])
p[2]=-(sols[1][1]+sols[1][2]+sols[2][1]+2.0sols[2][2]+sols[2][3])
p[3]=-(sols[1][1]+2.0sols[1][2]+3.0sols[2][1]+5.0sols[2][2]+
6.0sols[2][3])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
p[1]=-(sols[1][1]+sols[1][2]+sols[2][1]+sols[2][2]+sols[2][3])
p[2]=-(sols[1][1]+sols[1][2]+sols[2][1]+2.0sols[2][2]+sols[2][3])
p[3]=-(sols[1][1]+2.0sols[1][2]+3.0sols[2][1]+5.0sols[2][2]+
6.0sols[2][3])
p[1] = -(sols[1][1] + sols[1][2] + sols[2][1] + sols[2][2] + sols[2][3])
p[2] = -(sols[1][1] + sols[1][2] + sols[2][1] + 2.0sols[2][2] + sols[2][3])
p[3] = -(sols[1][1] + 2.0sols[1][2] + 3.0sols[2][1] + 5.0sols[2][2] +
6.0sols[2][3])

Comment on lines +56 to +57
sol3=solve(prob3) # LinearProblem uses default linear solver
manualscc=reduce(vcat, (sol1, sol2, sol3))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
sol3=solve(prob3) # LinearProblem uses default linear solver
manualscc=reduce(vcat, (sol1, sol2, sol3))
sol3 = solve(prob3) # LinearProblem uses default linear solver
manualscc = reduce(vcat, (sol1, sol2, sol3))


sccprob = SciMLBase.SCCNonlinearProblem([prob1, prob2, prob3],
sccprob=SciMLBase.SCCNonlinearProblem((prob1, prob2, prob3),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
sccprob=SciMLBase.SCCNonlinearProblem((prob1, prob2, prob3),
sccprob = SciMLBase.SCCNonlinearProblem((prob1, prob2, prob3),

Comment on lines +64 to +65
scc_alg=SCCNonlinearSolve.SCCAlg(nlalg = NewtonRaphson(), linalg = nothing)
scc_sol=solve(sccprob, scc_alg)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
scc_alg=SCCNonlinearSolve.SCCAlg(nlalg = NewtonRaphson(), linalg = nothing)
scc_sol=solve(sccprob, scc_alg)
scc_alg = SCCNonlinearSolve.SCCAlg(nlalg = NewtonRaphson(), linalg = nothing)
scc_sol = solve(sccprob, scc_alg)

@test sol ≈ manualscc ≈ scc_sol

# Backwards compat of alg choice
scc_sol=solve(sccprob, NewtonRaphson())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
scc_sol=solve(sccprob, NewtonRaphson())
scc_sol = solve(sccprob, NewtonRaphson())

scc_sol = solve(sccprob)
@test sol ≈ manualscc ≈ scc_sol
# Test default interface
scc_sol_default=solve(sccprob)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
scc_sol_default=solve(sccprob)
scc_sol_default = solve(sccprob)

if !SciMLBase.successful_retcode(_sol)
break
end
function CommonSolve.solve(prob::SciMLBase.SCCNonlinearProblem, alg::SciMLBase.AbstractNonlinearAlgorithm; kwargs...)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
function CommonSolve.solve(prob::SciMLBase.SCCNonlinearProblem, alg::SciMLBase.AbstractNonlinearAlgorithm; kwargs...)
function CommonSolve.solve(prob::SciMLBase.SCCNonlinearProblem,
alg::SciMLBase.AbstractNonlinearAlgorithm; kwargs...)

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.

1 participant