I am trying to use gurobi 8.0 with pyomo 5.5. When solving a simple model as a test I get the following error: ERROR: Solver log: Unrecognized flag or missing argument: -AMPL
from pyomo.environ import *
model = ConcreteModel()
model.x = Var([1,2], domain=NonNegativeReals)
model.OBJ = Objective(expr = 2*model.x[1] + 3*model.x[2])
model.Constraint1 = Constraint(expr = 3*model.x[1] + 4*model.x[2] >= 1)
solver = SolverFactory("gurobi_cl")
results = solver.solve(model) #error here
model.solutions.store_to(results)
print(results)
The Pyomo SolverFactory
works by first looking to see if it has a custom solver interface registered under the name you provide to the factory. If it does, it returns that solver interface. If it doesn't, then it looks to see if it can find an executable on your PATH matching that name, and if it does, it assumes that the executable is an AMPL solver and returns the ASL interface. If both of these fail, it returns an UnknownSolver object.
In your specific case, you are hitting the second branch. Unfortunately, gurobi_cl
is not an ASL binary, resulting in the error you see.
There are several ways to interface with Gurobi: through LP files, through NL files, and directly through the Python bindings (in either a one-shot or persistent mode). Each of these routes use different executables. The SolverFactory("gurobi")
is actually a wrapper that returns one of these specialized solvers, based on the solver_io
flag. The default is the LP file interface, which relies on the gurobi.sh
interactive shell.
If you don't have gurobi.sh
in your Gurobi install, you can use the other interfaces (the NL interface requires the gurobi_ampl
executable, and the direct interface requires that the Python bindings are installed into your Python environment). For your install, I would start with the "direct" interface:
solver = SolverFactory("gurobi", solver_io="direct")
# (or `solver_io="python"` in older Pyomo releases)