Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
odow committed Aug 16, 2023
1 parent f6d0995 commit 3ebfe5c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
5 changes: 5 additions & 0 deletions docs/src/manual/nlp.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ DocTestFilters = [r"≤|<=", r"≥|>=", r" == | = ", r" ∈ | in ", r"MathOptInt

# Nonlinear Modeling

!!! info
This page describes the legacy nonlinear interface to JuMP. A new,
exerimental nonlinear interface is in development. Find out more by reading
[Nonlinear Modeling](@ref new_nonlinear_interface).

JuMP has support for general smooth nonlinear (convex and nonconvex)
optimization problems. JuMP is able to provide exact, sparse second-order
derivatives to solvers. This information can improve solver accuracy and
Expand Down
19 changes: 19 additions & 0 deletions src/optimizer_interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,13 @@ function optimize!(
# The nlp_model is not kept in sync, so re-set it here.
# TODO: Consider how to handle incremental solves.
if nonlinear_model(model) !== nothing
if _uses_new_nonlinear_interface(model)
error(
"Cannot optimize a model which contains the features from " *
"both the legacy and new nonlinear interfaces. You must use " *
"one or the other.",
)
end
evaluator = MOI.Nonlinear.Evaluator(
nonlinear_model(model),
_differentiation_backend,
Expand Down Expand Up @@ -454,6 +461,18 @@ function optimize!(
return
end

function _uses_new_nonlinear_interface(model)
if objective_function_type(model) <: GenericNonlinearExpr
return true
end
for (F, S) in list_of_constraint_types(model)
if F <: GenericNonlinearExpr
return true
end
end
return false
end

"""
compute_conflict!(model::GenericModel)
Expand Down
16 changes: 16 additions & 0 deletions test/test_nlp_expr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -649,4 +649,20 @@ function test_show_nonlinear_model()
return
end

function test_error_both_nl_interfaces()
model = Model()
@variable(model, x)
@constraint(model, log(x) <= 1)
@NLconstraint(model, log(x) <= 1)
@test_throws(
ErrorException(
"Cannot optimize a model which contains the features from both " *
"the legacy and new nonlinear interfaces. You must use one or " *
"the other.",
),
optimize!(model),
)
return
end

end # module

0 comments on commit 3ebfe5c

Please sign in to comment.