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

[WIP] feat: initial implementation of SCCNonlinearProblem codegen #3213

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

AayushSabharwal
Copy link
Member

@AayushSabharwal AayushSabharwal commented Nov 16, 2024

I've checked this on the trivial case in SCCNonlinearSolve's tests. However, there is one major caveat: There can be multiple orderings of the SCCs. As a result, solving the same system with NonlinearProblem and SCCNonlinearProblem leads to different ordering of the solution vector, because one uses the order of unknowns in the system and the other uses the order of SCCs. I'm figuring out how to use the same sorted order of SCCs in the simplified system.

@AayushSabharwal
Copy link
Member Author

Example:

julia> @variables u(t)[1:8] [irreducible = true]
julia> @mtkbuild sys = NonlinearSystem([
                 0 ~ u[5]^2 + u[4]
                 0 ~ u[3]^2 + u[5]
                 0 ~ cos(u[2]) - u[1]
                 0 ~ 2u[4] + u[3] + 1.0
                 0 ~ u[1] + u[2] + u[3] + u[4] + u[5]    + 2.0u[6] + 2.5u[7] + 1.5u[8]
                 0 ~ u[1] + u[2] + u[3] + 2.0u[4] + u[5] + 4.0u[6] - 1.5u[7] + 1.5u[8]
                 0 ~ u[1] + 2.0u[2] + 3.0u[3] + 5.0u[4] + 6.0u[5] + u[6] - u[7] - u[8]
                 0 ~ sin(u[1] + u[2]) + u[2]
             ])
julia> prob =  SCCNonlinearProblem{true}(sys, unknowns(sys) .=> zeros(8));
julia> sol = solve(prob, NewtonRaphson())
julia> sol
retcode: Success
u: 8-element Vector{Float64}:
 -0.443600343333633
  0.9032122743166665
 -0.41964337760708054
 -0.17610056436947866
 -0.6477988712610427
 -4.179650698308442
  1.0580471331304233
  2.204144548445586
julia> nprob = NonlinearProblem(sys, unknowns(sys) .=> zeros(8))
julia> nsol = solve(nprob, NewtonRaphson())
retcode: Success
u: 8-element Vector{Float64}:
 -0.41964337760708054
 -0.17610056436947866
 -0.6477988712610426
 -0.44360034333363063
  0.903212274316663
 -4.179650698308441
  1.0580471331304235
  2.204144548445586

Note how both solutions have the same answer, but in different permutations.

@AayushSabharwal AayushSabharwal changed the title feat: initial implementation of SCCNonlinearProblem codegen [WIP] feat: initial implementation of SCCNonlinearProblem codegen Nov 16, 2024
@AayushSabharwal AayushSabharwal marked this pull request as draft November 16, 2024 14:18
@ChrisRackauckas
Copy link
Member

But SII should take care of that?

@ChrisRackauckas
Copy link
Member

  1. Is there a way to toggle the initialization problem to be SCC or not?

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