Pyomo not loading solvers ('couenne', 'bonmin') from ampl

23 Views Asked by At

When I want to perform an optimisation with pyomo, using one of the solvers I installed via the AMPL license tool, I get an error when just checking the availability of the solver.

This happens for the 'couenne' and 'bonmin' solver. Other solvers seem to work okay.

If anybody knows a solution to the problem, or a suggestion for a different way to use the couenne solver, I would appreciate it

So for example when running the following command,

from pyomo.environ import SolverFactory
SolverFactory('couenne').available()

I get the following error:

Exception in thread Thread-12:
Traceback (most recent call last):
  File "C:\Users\VictorVerbist\anaconda3\envs\energylib\lib\threading.py", line 980, in _bootstrap_inner
    self.run()
  File "C:\Users\VictorVerbist\anaconda3\envs\energylib\lib\threading.py", line 917, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\VictorVerbist\anaconda3\envs\energylib\lib\subprocess.py", line 1495, in _readerthread
    buffer.append(fh.read())
  File "C:\Users\VictorVerbist\anaconda3\envs\energylib\lib\encodings\cp1252.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 38: character maps to <undefined>

Traceback (most recent call last):

  Cell In[6], line 1
    SolverFactory('Couenne').available()

  File ~\anaconda3\envs\energylib\lib\site-packages\pyomo\solvers\plugins\solvers\ASL.py:123 in available
    return self.version() is not None

  File ~\anaconda3\envs\energylib\lib\site-packages\pyomo\opt\base\solvers.py:443 in version
    self._version = self._get_version()

  File ~\anaconda3\envs\energylib\lib\site-packages\pyomo\solvers\plugins\solvers\ASL.py:109 in _get_version
    ver = _extract_version(results.stdout)

  File ~\anaconda3\envs\energylib\lib\site-packages\pyomo\opt\base\solvers.py:47 in _extract_version
    m = re.search('[t,T]runk', x)

  File ~\anaconda3\envs\energylib\lib\re.py:201 in search
    return _compile(pattern, flags).search(string)

TypeError: expected string or bytes-like object
1

There are 1 best solutions below

0
fdabrandao On

You can use AMPL solver modules with Pyomo as follows:

from amplpy import modules
import pyomo.environ as pyo
solver = pyo.SolverFactory(modules.find("couenne"), solve_io="nl") 

For more information, see the documentation at: https://dev.ampl.com/ampl/python/modules.html#using-from-pyomo

In order to use couenne or other COIN-OR solvers you need to install the coin module as follows:

$ python -m amplpy.modules install coin