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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions src/systems/nonlinear/nonlinearsystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ function DiffEqBase.NonlinearProblem{iip}(sys::NonlinearSystem, u0map,
end
end
f, u0, p = process_SciMLProblem(NonlinearFunction{iip}, sys, u0map, parammap;
check_length, kwargs...)
check_length, build_initializeprob = false, kwargs...)
pt = something(get_metadata(sys), StandardNonlinearProblem())
NonlinearProblem{iip}(f, u0, p, pt; filter_kwargs(kwargs)...)
end
Expand Down Expand Up @@ -568,7 +568,7 @@ function DiffEqBase.NonlinearLeastSquaresProblem{iip}(sys::NonlinearSystem, u0ma
error("A completed `NonlinearSystem` is required. Call `complete` or `structural_simplify` on the system before creating a `NonlinearLeastSquaresProblem`")
end
f, u0, p = process_SciMLProblem(NonlinearFunction{iip}, sys, u0map, parammap;
check_length, kwargs...)
check_length, build_initializeprob = false, kwargs...)
pt = something(get_metadata(sys), StandardNonlinearProblem())
NonlinearLeastSquaresProblem{iip}(f, u0, p; filter_kwargs(kwargs)...)
end
Expand Down Expand Up @@ -681,7 +681,8 @@ function SciMLBase.SCCNonlinearProblem{iip}(sys::NonlinearSystem, u0map,
obs = observed(sys)

_, u0, p = process_SciMLProblem(
EmptySciMLFunction, sys, u0map, parammap; eval_expression, eval_module, kwargs...)
EmptySciMLFunction, sys, u0map, parammap; eval_expression, eval_module,
build_initializeprob = false, kwargs...)

explicitfuns = []
nlfuns = []
Expand Down Expand Up @@ -832,7 +833,8 @@ function DiffEqBase.IntervalNonlinearProblem(sys::NonlinearSystem, uspan::NTuple
error("`IntervalNonlinearProblem` only supports with a single equation and a single unknown.")
end
f, u0, p = process_SciMLProblem(
IntervalNonlinearFunction, sys, unknowns(sys) .=> uspan[1], parammap; kwargs...)
IntervalNonlinearFunction, sys, unknowns(sys) .=> uspan[1], parammap;
build_initializeprob = false, kwargs...)

return IntervalNonlinearProblem(f, uspan, p; filter_kwargs(kwargs)...)
end
Expand Down Expand Up @@ -865,7 +867,7 @@ function NonlinearProblemExpr{iip}(sys::NonlinearSystem, u0map,
error("A completed `NonlinearSystem` is required. Call `complete` or `structural_simplify` on the system before creating a `NonlinearProblemExpr`")
end
f, u0, p = process_SciMLProblem(NonlinearFunctionExpr{iip}, sys, u0map, parammap;
check_length, kwargs...)
check_length, build_initializeprob = false, kwargs...)
linenumbers = get(kwargs, :linenumbers, true)

ex = quote
Expand Down Expand Up @@ -905,7 +907,7 @@ function NonlinearLeastSquaresProblemExpr{iip}(sys::NonlinearSystem, u0map,
error("A completed `NonlinearSystem` is required. Call `complete` or `structural_simplify` on the system before creating a `NonlinearProblemExpr`")
end
f, u0, p = process_SciMLProblem(NonlinearFunctionExpr{iip}, sys, u0map, parammap;
check_length, kwargs...)
check_length, build_initializeprob = false, kwargs...)
linenumbers = get(kwargs, :linenumbers, true)

ex = quote
Expand Down Expand Up @@ -933,7 +935,8 @@ function IntervalNonlinearProblemExpr(sys::NonlinearSystem, uspan::NTuple{2},
error("`IntervalNonlinearProblemExpr` only supports with a single equation and a single unknown.")
end
f, u0, p = process_SciMLProblem(
IntervalNonlinearFunctionExpr, sys, unknowns(sys) .=> uspan[1], parammap; kwargs...)
IntervalNonlinearFunctionExpr, sys, unknowns(sys) .=> uspan[1], parammap;
build_initializeprob = false, kwargs...)
linenumbers = get(kwargs, :linenumbers, true)

ex = quote
Expand Down
19 changes: 19 additions & 0 deletions test/nonlinearsystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -380,3 +380,22 @@ end
@test_throws ["single equation", "unknown"] IntervalNonlinearFunctionExpr(
sys, (0.0, 1.0))
end

@testset "Overconditioned Initial Conditions" begin
# Define the nonlinear system
@variables x=1.0 y=0.0 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())
@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

Loading