Deactivating gurobi log files

547 views
Skip to first unread message

Cord Kaldemeyer

unread,
Mar 13, 2018, 11:58:43 AM3/13/18
to Pyomo Forum
Hi everybody,

I am solving a MIP a couple of hundred times using gurobi. During the solving process, gurobi seems to create (and delete) log files in the folder of the optimization code which I want to prevent since it slows down the overall process.

But passing options from the gurobi documentation does not seem to work here although other options like "MIPGap" are working (notice that it only seems to work in lowercase in contrast to the name within the gurobi manual):


# http://www.gurobi.com/documentation/7.5/refman/mipgap2.html
opt
.options['MIPGap'] = 0.1  # does not work
opt
.options['mipgap'] = 0.1  # works

# http://www.gurobi.com/documentation/6.0/refman/outputflag.html#parameter:OutputFlag
opt
.options['OutputFlag'] = 0  # does not work
opt
.options['outputflag'] = 0  # does not work

# http://www.gurobi.com/documentation/6.0/refman/logfile.html#parameter:LogFile
opt
.options['LogFile'] = ''  # does not work
opt
.options['logfile'] = ''  # does not work

# http://www.gurobi.com/documentation/6.0/refman/logtoconsole.html#parameter:LogToConsole
opt
.options['LogToConsole'] = 0  # does not work
opt
.options['logtoconsole'] = 0  # does not work

results
= opt.solve(model)

Has anyone muted gurobi so far and can provide help?

Cheers
Cord

Gabriel Hackebeil

unread,
Mar 13, 2018, 1:04:16 PM3/13/18
to Pyomo Forum
Are you using the Python interface to Gurobi (solver_io=‘python’) or the default LP-file interface (solver_io=‘lp’)?

If you are using the Python interface, then you might try looking at places where we call ‘setParam’ in the _apply_solver method in pyomo/solvers/plugins/solvers/gurobi_direct.py. It’s a pretty short piece of code. If you can figure out some changes there that solve the issue you are having, then let us know or perhaps open up a pull request on GitHub.

Gabe

--
You received this message because you are subscribed to the Google Groups "Pyomo Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyomo-forum...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Cord Kaldemeyer

unread,
Mar 13, 2018, 2:52:22 PM3/13/18
to Pyomo Forum
Hi Gabe,

thanks for your answer. I have used the LP-Interface so far and -to be honest- did not know about the other interfaces.

Do I understand it right from the docs that if a solver provides a Python-interface, this would be the faster solution as it does not create any LP-files?

If yes, I will switch and follow your suggestion (hopefully followed by a PR).

Cheers
Cord

Gabriel Hackebeil

unread,
Mar 13, 2018, 3:42:11 PM3/13/18
to Pyomo Forum
Do I understand it right from the docs that if a solver provides a Python-interface, this would be the faster solution as it does not create any LP-files?

For the most part, yes, unless the solver’s Python interface is slower than going through a file (this was the case with Cplex for a while).

Even going through the Python interface, you might still run into the issue of Gurobi writing a “gurobi.log” file into the working directory with each solve, which is why I pointed you to that code.

Also, we recently added persistent interfaces for Cplex and Gurobi. If you are doing repeated solves with very small changes to the model, they are worth checking out as they can provide a pretty huge performance benefit:


Gabe

Cord Kaldemeyer

unread,
Mar 15, 2018, 4:31:08 AM3/15/18
to Pyomo Forum
Thanks for your explanation! I'll try my luck and post my progress here.

Cheers
Cord

Cord Kaldemeyer

unread,
May 3, 2018, 9:05:59 AM5/3/18
to pyomo...@googlegroups.com
Hi Gabe,

it took me a while but now I want to test the gurobi Python interface against the persistent option you have implemented recently.

When I switch from calling solver = SolverFactory('gurobi', solver_io=‘lp’) to solver = SolverFactory('gurobi', solver_io=‘python’) I get an error:

 File "/home/cord/.anaconda3/lib/python3.6/site-packages/pyomo/solvers/plugins/solvers/direct_solver.py", line 68, in solve
   
self.available(exception_flag=True)
 
File "/home/cord/.anaconda3/lib/python3.6/site-packages/pyomo/solvers/plugins/solvers/direct_or_persistent_solver.py", line 277, in available
   
"plugin").format(type(self)))
pyutilib
.common._exceptions.ApplicationError: No Python bindings available for <class 'pyomo.solvers.plugins.solvers.gurobi_direct.GurobiDirect'> solver plugin

What am I missing here? Do I have to adapt the solver name to gurobi_python or something similar?

*edit*: Pyomo version is 5.4.3 on a linux machine.

Best
Cord

Am Dienstag, 13. März 2018 20:42:11 UTC+1 schrieb Gabriel Hackebeil:

Gabe Hackebeil

unread,
May 3, 2018, 9:31:27 AM5/3/18
to pyomo...@googlegroups.com
You need to find the Gurobi installation directory. Somewhere inside of that is a file named setup.py, which you need to execute using the command:

$ python setup.py install

If this worked, then you should be able to “import gurobipy” inside of a Python session. At this point, you should be able to use the persistent Gurobi interface in Pyomo.

Gabe

On May 3, 2018, at 9:05 AM, Cord Kaldemeyer <cord.ka...@hs-flensburg.de> wrote:

Hi Gabe,

it took me a while but now I want to test the gurobi Python interface against the persistent option you have implemented recently.

When I switch from calling solver = SolverFactory('gurobi', solver_io=‘lp’) to solver = SolverFactory('gurobi', solver_io=‘python’) I get an error:

 File "/home/cord/.anaconda3/lib/python3.6/site-packages/pyomo/solvers/plugins/solvers/direct_solver.py", line 68, in solve
   
self.available(exception_flag=True)
 
File "/home/cord/.anaconda3/lib/python3.6/site-packages/pyomo/solvers/plugins/solvers/direct_or_persistent_solver.py", line 277, in available
   
"plugin").format(type(self)))
pyutilib
.common._exceptions.ApplicationError: No Python bindings available for <class 'pyomo.solvers.plugins.solvers.gurobi_direct.GurobiDirect'> solver plugin

What am I missing here? Do I have to adapt the solver name to gurobi_python or something similar?

rbgmichael09

unread,
May 3, 2018, 9:35:29 AM5/3/18
to pyomo...@googlegroups.com
Cord,

It looks like you do not have the Python bindings for Gurobi installed. If you try "import gurobipy", do you get an import error? If so there are a couple ways to install the Gurobi Python bindings. I personally prefer option 2. 

Option 1:
  • Find the setup.py file wherever you have gurobi installed
  • run "python setup.py install" from the terminal
Option 2 (from the terminal):
Michael


-------- Original message --------
From: Cord Kaldemeyer <cord.ka...@hs-flensburg.de>
Date: 5/3/18 7:05 AM (GMT-07:00)
To: Pyomo Forum <pyomo...@googlegroups.com>
Subject: Re: Deactivating gurobi log files

Hi Gabe,

it took me a while but now I want to test the gurobi Python interface against the persistent option you have implemented recently.

When I switch from calling solver = SolverFactory('gurobi', solver_io=‘lp’) to solver = SolverFactory('gurobi', solver_io=‘python’) I get an error:

 File "/home/cord/.anaconda3/lib/python3.6/site-packages/pyomo/solvers/plugins/solvers/direct_solver.py", line 68, in solve
   
self.available(exception_flag=True)
 
File "/home/cord/.anaconda3/lib/python3.6/site-packages/pyomo/solvers/plugins/solvers/direct_or_persistent_solver.py", line 277, in available
   
"plugin").format(type(self)))
pyutilib
.common._exceptions.ApplicationError: No Python bindings available for <class 'pyomo.solvers.plugins.solvers.gurobi_direct.GurobiDirect'> solver plugin

What am I missing here? Do I have to adapt the solver name to gurobi_python or something similar?

Cord Kaldemeyer

unread,
May 3, 2018, 11:44:56 AM5/3/18
to Pyomo Forum
Works like a charm now. Thanks to both of you!

Cord Kaldemeyer

unread,
May 3, 2018, 12:32:39 PM5/3/18
to Pyomo Forum
By the way: the outputflag parameter (my initial question) is set correctly with solver_io='python' but not with solver_io='lp'.

Thanks again!
Reply all
Reply to author
Forward
0 new messages