Pyomo / pyomo

An object-oriented algebraic modeling language in Python for structured optimization problems.
https://www.pyomo.org
Other
2k stars 514 forks source link

HiGHS solver fails as LegacySolver is not available #2774

Open SolverMax opened 1 year ago

SolverMax commented 1 year ago

Summary

Calling the solver appsi_highs produces the error message: ApplicationError: Solver <class 'pyomo.contrib.appsi.base.SolverFactoryClass.register..decorator..LegacySolver'> is not available (NotFound).

Steps to reproduce the issue

Sample model at: https://github.com/SolverMax/Random/tree/main/HiGHS-testing/Case-001

The sample model runs correctly when called using the cbc solver (specified in the data file), but fails when using appsi_highs. A few weeks ago it ran correctly with appsi_highs, but Pyomo and HiGHS versions have been upgraded since then.

Information on your system

Pyomo version: Pyomo 6.5.0 (CPython 3.9.7 on Windows 10) Python version: 3.9.7 How Pyomo was installed (PyPI, conda, source): PyPI Solver (if applicable): HiGHs v1.5.1

michaelbynum commented 1 year ago

How did you install HiGHS? Did you install the python bindings as well? It does not look like highspy 1.5.1 is on PyPI yet, so we are not testing against it yet. I did install the latest version of HiGHS locally, and everything seems to be working.

SolverMax commented 1 year ago

HiGHS was originally installed using: pip install highspy It was recently upgraded using: pip install highspy --upgrade Testing the solvers using: pyomo help --solvers used to indicate appsi_highs was available by marking it with a + but it no longer does. The HiGHS version says 1.5.0.dev0 I'm not sure why I thought it was 1.5.1

michaelbynum commented 1 year ago

Can you try:

>>> import highspy

in a python console?

SolverMax commented 1 year ago

After downgrading to 1.4.0dev I get this: import highspy highspy <module 'highspy' from 'D:\OneDrive\Python\blog\lib\site-packages\highspy\init.py'>

After reinstalling 1.5.0dev I get this: import highspy Traceback (most recent call last): File "", line 1, in File "D:\OneDrive\Python\blog\lib\site-packages\highspy__init__.py", line 30, in from .highs import ( File "D:\OneDrive\Python\blog\lib\site-packages\highspy\highs.py", line 1, in from .highs_bindings import ( ImportError: DLL load failed while importing highs_bindings: The specified procedure could not be found.

michaelbynum commented 1 year ago

If you look in the highspy directory in your python site-packages, do you see any dll files?

SolverMax commented 1 year ago

No DLLs

michaelbynum commented 1 year ago

Sounds like the DLL is not getting copied from the wheel into your site-packages. I'll create an issue on the HiGHS repo. In the meantime, you can probably manually download the correct wheel from here (https://pypi.org/project/highspy/#files), unzip the wheel, and put the DLL in your site packages.

michaelbynum commented 1 year ago

Sorry - can you check one more thing? Are there any ".pyd" files in your site-packages?

michaelbynum commented 1 year ago

I think you need the ".pyd" rather than the DLL. I'm not sure though.

SolverMax commented 1 year ago

I have .\Lib\site-packages\highspy\highs_bindings.cp39-win_amd64.pyd Looking around I also have .\Lib\site-packages\highspy.libs\msvcp140.dll

These appear to be the same filenames that v1.4.0dev has.

michaelbynum commented 1 year ago

Strange...

michaelbynum commented 1 year ago

It looks like there is also a highs-*.dll in the wheel under highspy.libs. Do you see anything like that?

SolverMax commented 1 year ago

Yes, that's there too, along with .load-order-highspy-1.5.0.dev0

michaelbynum commented 1 year ago

Then I am stumped.

SolverMax commented 1 year ago

When I downgrade to 1.4.0dev my test model solves OK, but not with 1.5.0dev. I'll continuing using 1.4.0dev in the meantime.