Skip to content
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

Create SCCNonlinearSolve #502

Merged
merged 27 commits into from
Nov 16, 2024
Merged

Create SCCNonlinearSolve #502

merged 27 commits into from
Nov 16, 2024

Conversation

ChrisRackauckas
Copy link
Member

@ChrisRackauckas ChrisRackauckas commented Nov 14, 2024

Requires SciML/SciMLBase.jl#861

using NonlinearSolve, SCCNonlinearSolve

function f(du,u,p)
	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]
end
prob = NonlinearProblem(f, zeros(8))
sol = solve(prob)

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

function f1(du,u,p)
	du[1] = cos(u[2]) - u[1]
	du[2] = sin(u[1] + u[2]) + u[2]
end
explicitfun1(p,sols) = nothing
prob1 = NonlinearProblem(NonlinearFunction{true, SciMLBase.NoSpecialize}(f1), zeros(2), p)
sol1 = solve(prob1, NewtonRaphson())

function f2(du,u,p)
	du[1] = 2u[2] + u[1] + 1.0
	du[2] = u[3]^2 + u[2]
	du[3] = u[1]^2 + u[3]
end
explicitfun2(p,sols) = nothing
prob2 = NonlinearProblem(NonlinearFunction{true, SciMLBase.NoSpecialize}(f2), zeros(3), p)
sol2 = solve(prob2, NewtonRaphson())

function f3(du,u,p)
	du[1] = p[1] + 2.0u[1] + 2.5u[2] + 1.5u[3]
	du[2] = p[2] + 4.0u[1] - 1.5u[2] + 1.5u[3]
	du[3] = p[3] + + u[1] - u[2] - u[3]
end
prob3 = NonlinearProblem(NonlinearFunction{true, SciMLBase.NoSpecialize}(f3), zeros(3), p)
function explicitfun3(p,sols)
	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]
end
explicitfun3(p,[sol1,sol2])
sol3 = solve(prob3, NewtonRaphson())
manualscc = [sol1; sol2; sol3]

sccprob = SciMLBase.SCCNonlinearProblem([prob1,prob2,prob3], SciMLBase.Void{Any}.([explicitfun1,explicitfun2,explicitfun3]))
scc_sol = solve(sccprob, NewtonRaphson())
sol  manualscc  scc_sol

Right now this just handles solve. I want to get a first version in, then the todos for next steps are:

  • init
  • step!
  • Put appropriate trait calculations on this

@ChrisRackauckas
Copy link
Member Author

Note the SciMLBase.Void{Any}.([explicitfun1,explicitfun2,explicitfun3]) can likely be done internally in the SCCNonlinearProblem constructor. This also requires SciMLBase.NoSpecialize which we are going to make the default after a few things from @oscardssmith first.

This will start as undocumented and experimental so we can work out the kinks.

It has a few allocations, I'm not worrying about those yet, correctness first.

Copy link
Member

@AayushSabharwal AayushSabharwal left a comment

Choose a reason for hiding this comment

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

Looks really cool! Mostly just general readability/interface comments. I'm looking forward to targeting this with MTK, not so much figuring out how SII will have to interact with it 😅

lib/SCCNonlinearSolve/src/SCCNonlinearSolve.jl Outdated Show resolved Hide resolved
lib/SCCNonlinearSolve/src/SCCNonlinearSolve.jl Outdated Show resolved Hide resolved
lib/SCCNonlinearSolve/src/SCCNonlinearSolve.jl Outdated Show resolved Hide resolved
lib/SCCNonlinearSolve/test/core_tests.jl Outdated Show resolved Hide resolved
lib/SCCNonlinearSolve/test/core_tests.jl Outdated Show resolved Hide resolved
lib/SCCNonlinearSolve/test/core_tests.jl Outdated Show resolved Hide resolved
@ChrisRackauckas ChrisRackauckas changed the title [WIP] Create SCCNonlinearSolve Create SCCNonlinearSolve Nov 15, 2024
@ChrisRackauckas
Copy link
Member Author

@AayushSabharwal I see where the confusion was from yesterday: I didn't have the fully final version pushed to the package. This is now set to the parameter mutation form I mentioned.

ChrisRackauckas and others added 8 commits November 15, 2024 09:24
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
ChrisRackauckas and others added 2 commits November 15, 2024 18:51
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@ChrisRackauckas ChrisRackauckas merged commit bec0bf2 into master Nov 16, 2024
13 of 18 checks passed
@ChrisRackauckas ChrisRackauckas deleted the scc branch November 16, 2024 03:54
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