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

Better error messages for vector variable bounds #2056

Closed
pierre-haessig opened this issue Sep 9, 2019 · 1 comment · Fixed by #2725
Closed

Better error messages for vector variable bounds #2056

pierre-haessig opened this issue Sep 9, 2019 · 1 comment · Fixed by #2725
Labels
Type: Error Messages Can be fixed with better error message
Milestone

Comments

@pierre-haessig
Copy link

pierre-haessig commented Sep 9, 2019

Hello,

As suggested by @odow in this discussion, I report a possible enhancement of error message when one inadvertidly uses broadcasted vector bounds when creating a vector of JuMP variables.

Considering the following preamble code,

using JuMP
model = Model()
xmax = [10., 0.]

the correct way to have a variable x<=xmax elementwise is by using an explicit indexing variable (which is documented, but not exactly for this vector slicing usecase)

@variable(model, x[i=1:2] <= xmax[i])

However, there is a wrong approach that someone can easily follow (at least I did -;)), using broadcasting on the comparison operator:

@variable(model, x[1:2] .<= xmax)

which yields the surprising error message:

ERROR: LoadError: In `@variable(model, x[1:2] .<= xmax)`: Unknown sense .<=.

Also, in the case of two bounds, with the same mistake:

@variable(model, 0 <= x[1:2] .<= xmax)

the error message is different but also not helpful:

ERROR: LoadError: In `@variable(model, 0 <= x[1:2] .<= xmax)`: Use the form lb <= ... <= ub.

Expected behavior: in an ideal world, the error message would point out to the correct solution (ex : "broadcasted constraints are not yet supported, use ... instead"). Alternatively, it may be worth supporting the broadcasted syntax, but I don't have enough background on JuMP to judge the difficulty of the task. This last idea may relate to the closed issue #1455, although it was about applying broadcasting on the set_lower_bound function not within the @variable macro.

@odow odow added the Type: Error Messages Can be fixed with better error message label Sep 9, 2019
@odow odow added this to the 1.0 milestone Feb 18, 2021
@odow
Copy link
Member

odow commented Jul 22, 2021

We should endeavor to make this work:

@variable(model, x[1:2] .<= xmax)

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

Successfully merging a pull request may close this issue.

2 participants