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

Error message improvement for value(Array of NLexpression) #2635

Closed
anastasianikolako opened this issue Jun 22, 2021 · 1 comment · Fixed by #2690
Closed

Error message improvement for value(Array of NLexpression) #2635

anastasianikolako opened this issue Jun 22, 2021 · 1 comment · Fixed by #2690
Labels
Category: Nonlinear Related to nonlinear programming Type: Error Messages Can be fixed with better error message

Comments

@anastasianikolako
Copy link

When calling value(u) where u is an array of variables the following error shows up

julia> value(u)
ERROR: `JuMP.value` is not defined for collections of JuMP types. Use Julia's broadcast syntax instead: `JuMP.value.(x)`.
Stacktrace:
 [1] error(s::String)
   @ Base .\error.jl:33
 [2] value(#unused#::Matrix{VariableRef})
   @ JuMP C:\Users\user\.julia\packages\JuMP\Xrr7O\src\variables.jl:1204

This error is helpful.

On the other hand, when calling value(u) where u is an array of nonlinear expressions the error is

ERROR: LoadError: MethodError: no method matching value(::Matrix{NonlinearExpression})

This is not as helpful as it does not say that value. should be used instead.

@blegat blegat added Category: Nonlinear Related to nonlinear programming Type: Error Messages Can be fixed with better error message labels Jun 22, 2021
@odow
Copy link
Member

odow commented Jun 22, 2021

Thanks for raising the issue.

There is this error:

JuMP.jl/src/variables.jl

Lines 1230 to 1235 in 2871a06

function value(::AbstractArray{<:AbstractJuMPScalar})
return error(
"`JuMP.value` is not defined for collections of JuMP types. Use" *
" Julia's broadcast syntax instead: `JuMP.value.(x)`.",
)
end

but it looks like we need to make NonlinearExpression <: AbstractJuMPScalar:
struct NonlinearExpression

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: Nonlinear Related to nonlinear programming Type: Error Messages Can be fixed with better error message
Development

Successfully merging a pull request may close this issue.

3 participants