I want to show information on the solution process when using the HiGHS solver with Pyomo.
Normally, for other solvers such as gurobi
or cbc
when setting the flag tee=True
more information on the problem, solver status, etc. ist shown. But for highs
it looks as the flag doesn't work and I couldn't find the right option in the HiGHS docs either.
Here's a small example adapted from the Pyomo forum:
from pyomo.environ import *
# Create model object
model = ConcreteModel()
# Declare decision variables
model.l = Var(within=NonNegativeReals)
model.g = Var(within=NonNegativeReals)
# Declare objective function
model.maximizeProfit = Objective(expr=200 * model.l + 300 * model.g,
sense=maximize)
# Declare constraints
# Farmer Brown has only 100 hours
model.LaborConstraint = Constraint(expr=3 * model.l + 2 * model.g <= 100)
# He only has $120 for medical
model.MedicalConstraint = Constraint(expr=2 * model.l + 4 * model.g <= 120)
# He only has 45 acres
model.LandConstraint = Constraint(expr=model.l + model.g <= 45)
# Show all available solvers
print(SolverFactory.__dict__["_cls"].keys())
print("")
# Test for availability of solver
my_solver = "highs"
if SolverFactory(my_solver).available():
print("Solver " + my_solver + " is available.")
else:
print("Solver " + my_solver + " is not available.")
optimizer = SolverFactory(my_solver)
optimizer.solve(model, options={"threads": 4}, tee=True)
model.display()
Respective requirements.txt
:
pyomo==6.7.1
highspy==1.5.3
Solver version:
AMPL/HiGHS Optimizer [1.5.1] (Windows AMD64), driver(20230227), MP(20221228)
Any hints on how to get the solver output?
Thanks in advance!
There are limitations with the current highspy
Python bindings that are preventing the normal functioning of the Pyomo tee
functionality. Pyomo's tee
option uses multiprocessing to monitor and redirect the solver output (both to the screen and to log files). Unfortunately, the current highspy
interface does not release the Python GIL during the solve. This means that the threads that would normally process the output stream and pass on the output are effectively deadlocked during the solve. At this moment, there isn't a great workaround.
This is being tracked in a number of Pyomo Issues (#3031 and #3084).