ampl / mp

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

gurobi_options format and echoing #220

Open 4er4er4er opened 1 year ago

4er4er4er commented 1 year ago

In build 20230728, gurobiasl recognizes a space or an = sign between an option name and the corresponding value. But gurobi only recognizes an = sign:

ampl: option gurobi_options 'nodemethod 0 iterlim 1000';

ampl: option solver gurobiasl;
ampl: solve;
Gurobi 10.0.2: nodemethod 0
iterlim 1000
Gurobi 10.0.2: optimal solution; objective 235625
280 simplex iterations
1 branch-and-cut nodes
plus 34 simplex iterations for intbasis

ampl: option solver gurobi;
ampl: solve;
Gurobi 10.0.2: mip:nodemethod=1
Unknown option or invalid key "0"

ampl: option gurobi_options 'nodemethod=0 iterlim=1000';
ampl: solve;
Gurobi 10.0.2: mip:nodemethod=0
lim:iter=1000
Gurobi 10.0.2: optimal solution; objective 235625
247 simplex iterations
1 branching nodes

Also, when outlev=1 is specified, the beginning of the log lists Gurobi names for options that were specified:

ampl: option gurobi_options 'outlev=1 nodemethod=0 iterlim=1000';
ampl: solve;
Gurobi 10.0.2: Set parameter LogToConsole to value 1
Set parameter NodeMethod to value 0
Set parameter IterationLimit to value 1000
Set parameter InfUnbdInfo to value 1
Gurobi Optimizer version 10.0.2 build v10.0.2rc0 (win64)

The AMPL names for the options are only echoed at the end of the log:

Optimal solution found (tolerance 1.00e-04)
Best objective 2.356250000000e+05, best bound 2.356250000000e+05, gap 0.0000%
tech:outlev=1
mip:nodemethod=0
lim:iter=1000
Gurobi 10.0.2: optimal solution; objective 235625
247 simplex iterations
1 branching nodes
ampl: 

The Gurobi names for the options are not helpful to most AMPL users, so it would be desirable to suppress them and to instead echo the AMPL option names at the beginning, like gurobiasl does:

ampl: option solver gurobiasl;
ampl: solve;
Gurobi 10.0.2: outlev=1
nodemethod=0
iterlim=1000
Set parameter OutputFlag to value 1
Set parameter InfUnbdInfo to value 1
Gurobi Optimizer version 10.0.2 build v10.0.2rc0 (win64)

(It would be really good if the few remaining stray Set parameter messages could also be suppressed, but I recall that that's more challenging.)

glebbelov commented 1 year ago

@4er4er4er I cannot reproduce the output order. Both in Windows and Linux I see:

ampl: solve;
Gurobi 10.0.2: Set parameter LogToConsole to value 1
tech:outlev=1
Set parameter NodeMethod to value 0
mip:nodemethod=0
Set parameter IterationLimit to value 1000
lim:iter=1000
Set parameter InfUnbdInfo to value 1
Gurobi Optimizer version 10.0.2 build v10.0.2rc0 (win64)

(and nothing about options after that.) I'd need the exact test setup please. @mapgccv do you guess what's happening?

4er4er4er commented 1 year ago

I did some further testing:

  1. I see the same output as you (the preferred output) when I run in a Windows Command Prompt window, or in a Google Colab window.
  2. I see the output that I reported, when I run in an "sw" command window, or in the AMPL IDE.
glebbelov commented 1 year ago

Fixed, to appear in the next release. Tested in Windows IDE (assume SW works similarly).

Solution: flush console output.

Log:

ampl: option gurobi_options 'outlev=1 nodemethod=0 iterlim 1000 version';
ampl: solve;
Gurobi 10.0.2: Set parameter LogToConsole to value 1
  tech:outlev = 1
Set parameter NodeMethod to value 0
  mip:nodemethod = 0
Set parameter IterationLimit to value 1000
  lim:iter = 1000
  tech:version
AMPL/Gurobi Optimizer [10.0.2] (Windows AMD64), driver(20230817), MP(20230817)

Licensed to License for development and testing <gleb@ampl.com>.
Maintenance expires with version 20231231.
Using license file "C:\Users\gbelov\AMPL\ampl.lic".

Set parameter InfUnbdInfo to value 1
Gurobi Optimizer version 10.0.2 build v10.0.2rc0 (win64)
....