Pyomo cannot find solver CVXOPT despite it is installed in Conda

98 Views Asked by At

I am attempting to solve an optimization problem coded with Python / Pyomon, using the solver CVXOPT.

My full script is :

import pyomo.environ as pyo
import cvxopt

Horizon = 3

model = pyo.ConcreteModel()


model.T = pyo.RangeSet(0, Horizon)

model.u = pyo.Var(model.T, within=pyo.NonNegativeReals)
model.x = pyo.Var(model.T, within = pyo.NonNegativeReals)

def transition(model, t) -> float :
    if t == model.T.first():
        return model.x[t] == model.u[t]
    else:
        return model.x[t] == model.x[model.T.prev(t)] + model.u[t]

model.transition = pyo.Constraint(model.T, rule=transition)

def objective(model):

    return sum(1 + model.x[t] - model.u[t]**2 for t in model.T)

model.obj = pyo.Objective(rule = objective, sense = pyo.maximize)

opt = pyo.SolverFactory('cvxopt')

opt.solve(model) 

I installed it using conda, it appears in my Anaconda environment package list, and when I import the solver at the beginning of my code, there is no error. Yet, when I attempt to solve the model, the console (in Spyder) displays the following error message:


WARNING: Failed to create solver with name 'CVXOPT': Failed to set executable
for solver asl. File with name=CVXOPT either does not exist or it is not
executable. To skip this validation, call set_executable with validate=False.
Traceback (most recent call last):
  File "C:\Users\gal\AppData\Local\anaconda3\Lib\site-packages\pyomo\opt\base\solvers.py", line 165, in __call__
    opt = self._cls[_implicit_solvers[mode]](**kwds)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\gal\AppData\Local\anaconda3\Lib\site-packages\pyomo\solvers\plugins\solvers\ASL.py", line 45, in __init__
    SystemCallSolver.__init__(self, **kwds)
  File "C:\Users\gal\AppData\Local\anaconda3\Lib\site-packages\pyomo\opt\solver\shellcmd.py", line 67, in __init__
    self.set_executable(name=executable, validate=validate)
  File "C:\Users\gal\AppData\Local\anaconda3\Lib\site-packages\pyomo\opt\solver\shellcmd.py", line 116, in set_executable
    raise ValueError(
ValueError: Failed to set executable for solver asl. File with name=CVXOPT either does not exist or it is not executable. To skip this validation, call set_executable with validate=False.
Traceback (most recent call last):

  File ~\AppData\Local\anaconda3\Lib\site-packages\spyder_kernels\py3compat.py:356 in compat_exec
    exec(code, globals, locals)

  File c:\users\gal\dropbox\thèse\code\modèle_pyo.py:45
    opt.solve(model)

  File ~\AppData\Local\anaconda3\Lib\site-packages\pyomo\opt\base\solvers.py:102 in solve
    self._solver_error('solve')

  File ~\AppData\Local\anaconda3\Lib\site-packages\pyomo\opt\base\solvers.py:119 in _solver_error
    raise RuntimeError(

RuntimeError: Attempting to use an unavailable solver.

The SolverFactory was unable to create the solver "CVXOPT"
and returned an UnknownSolver object.  This error is raised at the point
where the UnknownSolver object was used as if it were valid (by calling
method "solve").

The original solver was created with the following parameters:
    executable: CVXOPT
    type: CVXOPT
    _args: ()
    options: {}

Do you know what causes my script to be unable to find the solver, and how can I solve it ?

0

There are 0 best solutions below