Skip to content

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.

2 participants