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

Fix interpretation of nonlinear system overdetermined defaults #3343

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

ChrisRackauckas
Copy link
Member

using ModelingToolkit, NonlinearSolve

# Define the nonlinear system
@variables x=1.0 y z=0.0
@parameters σ=10.0 ρ=26.0 β=8 / 3

eqs = [0 ~ σ * (y - x),
    0 ~ x *- z) - y,
    0 ~ x * y - β * z]
@mtkbuild ns = NonlinearSystem(eqs, [x, y, z], [σ, ρ, β])

# Convert the symbolic system into a numerical system
prob = NonlinearProblem(ns, [])

# Solve the numerical problem
sol = solve(prob, NewtonRaphson())

This failed because of an initialization failure. This is because those conditions cannot be satisfied with the nonlinear system. But that doesn't make sense: the purpose of a nonlinear system is to find the set of values that satisfies the system. So this case should not be building initialization problems, there is no reason to assume that the user's initial guess satisfies the system, and in fact, you should assume if basically never does as the point is to solve the system.

There can be an argument to have the initialization specifically for the parameters, but that can be added in the future. For now, this is fixing a major regression and adding a test to make sure this doesn't regress again.

OptimizationSystem should be similarly checked as its initial conditions should be handled similarly.

ChrisRackauckas and others added 5 commits January 18, 2025 09:14
```julia
using ModelingToolkit, NonlinearSolve

# Define the nonlinear system
@variables x=1.0 y z=0.0
@parameters σ=10.0 ρ=26.0 β=8 / 3

eqs = [0 ~ σ * (y - x),
    0 ~ x * (ρ - z) - y,
    0 ~ x * y - β * z]
@mtkbuild ns = NonlinearSystem(eqs, [x, y, z], [σ, ρ, β])

# Convert the symbolic system into a numerical system
prob = NonlinearProblem(ns, [])

# Solve the numerical problem
sol = solve(prob, NewtonRaphson())
```

This failed because of an initialization failure. This is because those conditions cannot be satisfied with the nonlinear system. But that doesn't make sense: the purpose of a nonlinear system is to find the set of values that satisfies the system. So this case should not be building initialization problems, there is no reason to assume that the user's initial guess satisfies the system, and in fact, you should assume if basically never does as the point is to solve the system.

There can be an argument to have the initialization specifically for the parameters, but that can be added in the future. For now, this is fixing a major regression and adding a test to make sure this doesn't regress again.

OptimizationSystem should be similarly checked as its initial conditions should be handled similarly.
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>
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>
sol = solve(prob, NewtonRaphson())
@test SciMLBase.successful_retcode(sol)
@test norm(sol.resid) < 1e-12
end
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
end
end

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