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

Added type info in NL error message #1872

Merged
merged 4 commits into from
Feb 19, 2019
Merged
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
10 changes: 8 additions & 2 deletions src/parse_nlp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,17 @@ end
function _parse_NL_expr_runtime(m::Model, x::GenericQuadExpr, tape, parent, values)
error("Unexpected quadratic expression $x in nonlinear expression. " *
"Quadratic expressions (e.g., created using @expression) and " *
"nonlinear expression cannot be mixed.")
"nonlinear expressions cannot be mixed.")
end

function _parse_NL_expr_runtime(m::Model, x::GenericAffExpr, tape, parent, values)
error("Unexpected affine expression $x in nonlinear expression. " *
"Affine expressions (e.g., created using @expression) and " *
"nonlinear expressions cannot be mixed.")
end

function _parse_NL_expr_runtime(m::Model, x, tape, parent, values)
error("Unexpected object $x in nonlinear expression.")
error("Unexpected object $x (of type $(typeof(x)) in nonlinear expression.")
end

function _expression_complexity(ex::Expr)
Expand Down
26 changes: 26 additions & 0 deletions test/nlp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -619,4 +619,30 @@
evaluator = JuMP.NLPEvaluator(model)
@test !(:Hess in MOI.features_available(evaluator))
end

@testset "Error on using AffExpr in NLexpression" begin
model = Model()
@variable(model, x)
@variable(model, y)
A = x + y
expected_exception = ErrorException(
"Unexpected affine expression x + y in nonlinear expression. " *
"Affine expressions (e.g., created using @expression) and " *
"nonlinear expressions cannot be mixed."
)
@test_throws expected_exception @NLexpression(model, A)
end

@testset "Error on using QuadExpr in NLexpression" begin
model = Model()
@variable(model, x)
@variable(model, y)
A = x*y
expected_exception = ErrorException(
"Unexpected quadratic expression x*y in nonlinear expression. " *
"Quadratic expressions (e.g., created using @expression) and " *
"nonlinear expressions cannot be mixed."
)
@test_throws expected_exception @NLexpression(model, A)
end
end