ampl / mp

An open-source library for mathematical programming
https://mp.ampl.com
Other
229 stars 42 forks source link

Difficulties with Gurobi `nonconvex` option #195

Closed 4er4er4er closed 1 year ago

4er4er4er commented 1 year ago

The Gurobi MP interface has trouble with this nonconvex quadratic example:

var x >= -2.5;
var y >= -2.5;
minimize obj:  x^2 - y^2;
s.t. c:  x + y <= 1;

option solver gurobi;
#option gurobi_options "NonConvex=2";
solve;

With option gurobi_options commented out as shown, Gurobi is supposed to prompt the user to set an option, but the message reads more like a report of a crash:

Gurobi 10.0.0: Error: Call failed: 'GRBoptimize(model())' with code 10020, Gurobi message: Objective Q not PSD (negative diagonal entry). Set NonConvex parameter to 2 to solve model.
exit value 18446744073709551615
<BREAK>
ampl: 

Also the message line is very long and (at least in some environments) only the first part is immediately visible. Perhaps it would be possible to remove Error: Call failed: 'GRBoptimize(model())' with code 10020 and exit value 18446744073709551615 <BREAK> so that the message's informational purpose clearer to the user.

Also the message says Set NonConvex parameter to 2 to solve model but when a user followed this instruction by uncommenting option gurobi_options "NonConvex=2"; in the above example, the option was rejected:

Gurobi 10.0.0: Unknown option or invalid key "NonConvex"
exit value 1
<BREAK>

To get a correct result, it's necessary to specify option gurobi_options "nonconvex=2"; or else switch back to gurobiasl which is not case-sensitive for option names. Since we do not use case to distinguish options, the MP interface can be made case-insensitive for option names as well.

glebbelov commented 1 year ago

Isn't the absence of NonConvex=2 an error in this case? I think we should print 'Error' and return failure exit code so scripts fail. Suggest as follows:

ampl: solve;                     
Gurobi 10.0.0: Error: Objective Q not PSD (negative diagonal entry). Set NonConvex=2 to solve model.
exit value 255
<BREAK>
4er4er4er commented 1 year ago

I agree. When this message appears, you could be in either of these situations:

Or maybe you are confused and need to think more about your model. But in any case, Gurobi is refusing to solve the problem, and should return an error condition.

glebbelov commented 1 year ago

Drivers updated.