oemof / oemof-solph

A model generator for energy system modelling and optimisation (LP/MILP).
https://oemof.org
MIT License
283 stars 124 forks source link

Support of HiGHS solver #855

Open Bachibouzouk opened 2 years ago

Bachibouzouk commented 2 years ago

@sasa821 contacted the devs of HiGHS to ask whether they would make it work with pyomo. They replied that a pyomo-HiGHS interface is being developed as it was wished by both teams. However it is not ready yet. The best one can do is to use pyomo to write a out the model as an .mps file and then call HiGHS from the command line or from python.

On pyomo, the only open issue mentionning HiGHS is https://github.com/Pyomo/pyomo/issues/2094

This would be a great improvement if we can use HiGHS over cbc, and both @sasa821 and I are motivated to try it out, would anyone else also be interested to help?

jnnr commented 2 years ago

Thanks for opening the issue, @Bachibouzouk! We are using cbc and gurobi to solve the scenarios in https://github.com/rl-institut/oemof-B3. Could use the model to benchmark performance. To start, a small example is better, though. Would be interested to try HiGHS, but will have capacities earliest later this summer.

gitfeldhase commented 1 year ago

Hello everyone,

i was also wondering if it is possible to implement the HiGHS for oemof and found this existing issue. I am using oemof.dhnx and did not find the HiGHS listed in the usable/installable solvers.

Are there any changes so far about its implementation?

thanks!

Bachibouzouk commented 1 year ago

Are there any changes so far about its implementation?

@gitfeldhase - not that I know of, maybe it was discussed in the latest oemof dev meeting

ckaldemeyer commented 1 year ago

Has anybody tested highs during the last months?

You can download the latest executables for Windows and OSX on the AMPL website which most probably means that it has AMPL bindings.

As for the SCIP solver, I know that it works only with Pyomo with integrated AMPL bindings (see my issue) which have been added per default in the latest versions. Thus, my suggestion would be that Highs might work now as well..

ckaldemeyer commented 1 year ago

Okay, I just downloaded the Highs executable from the AMPL site and tested it on my Windows 10 machine. and it does not work in the following setup.

Example execution (pyomo error):

(venv) PS C:\Users\FooBar\Documents\Programmierung\oemof-solph> python examples\start_and_shutdown_costs\startup_shutdown.py
WARNING: DEPRECATED: Using __getitem__ to return a set value from its      
    (ordered) position is deprecated.  Please use at()  (deprecated in 6.1,
    will be removed in (or after) 7.0) (called from
    c:\users\FooBar\documents\programmierung\oemof-
    solph\src\oemof\solph\flows\_non_convex_flow_block.py:513)
WARNING: DEPRECATED: Using __getitem__ to return a set value from its
    (ordered) position is deprecated.  Please use at()  (deprecated in 6.1,
    will be removed in (or after) 7.0) (called from
    c:\users\FooBar\documents\programmierung\oemof-
    solph\src\oemof\solph\flows\_non_convex_flow_block.py:487)
Traceback (most recent call last):
  File "c:\Users\FooBar\Documents\Programmierung\oemof-solph\examples\start_and_shutdown_costs\startup_shutdown.py", line 127, in <module>
    main()
  File "c:\Users\FooBar\Documents\Programmierung\oemof-solph\examples\start_and_shutdown_costs\startup_shutdown.py", line 99, in main     
    om.solve(solver="highs", solve_kwargs={"tee": True})
  File "c:\users\FooBar\documents\programmierung\oemof-solph\src\oemof\solph\_models.py", line 243, in solve
    solver_results = opt.solve(self, **solve_kwargs)
  File "c:\Users\FooBar\Documents\Programmierung\oemof-solph\venv\lib\site-packages\pyomo\opt\base\solvers.py", line 106, in solve        
    self._solver_error('solve')
  File "c:\Users\FooBar\Documents\Programmierung\oemof-solph\venv\lib\site-packages\pyomo\opt\base\solvers.py", line 123, in _solver_error
    raise RuntimeError("""Attempting to use an unavailable solver.
RuntimeError: Attempting to use an unavailable solver.

The SolverFactory was unable to create the solver "highs"
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: highs
        solver_io: lp
        type: highs
        _args: ()
        options: {}

pip list:

(venv) PS C:\Users\FooBar\Documents\Programmierung\oemof-solph> pip list
Package             Version    Editable project location
------------------- ---------- -----------------------------------------------------------------------
black               23.1.0
blinker             1.5
click               8.1.3
colorama            0.4.6
contourpy           1.0.7
cycler              0.11.0
dill                0.3.6
fonttools           4.39.0
importlib-resources 5.12.0
kiwisolver          1.4.4
matplotlib          3.7.1
mypy-extensions     1.0.0
networkx            3.0
numpy               1.24.2
oemof.network       0.5.0a1
oemof.solph         0.5.1.dev0 c:\users\FooBar\documents\programmierung\oemof-solph\src
oemof.tools         0.4.2
packaging           23.0
pandas              1.5.3
pathspec            0.11.0
Pillow              9.4.0
pip                 23.0.1
platformdirs        3.1.1
ply                 3.11
Pyomo               6.5.0
pyparsing           3.0.9
PyQt5               5.15.9
PyQt5-Qt5           5.15.2
PyQt5-sip           12.11.1
python-dateutil     2.8.2
pytz                2022.7.1
setuptools          67.4.0
six                 1.16.0
tomli               2.0.1
typing_extensions   4.5.0
wheel               0.38.4
zipp                3.15.0
Bachibouzouk commented 10 months ago

Some people at Reiner Lemoine Institut tried using oemof with HIGHS and it was successful some of the examples. What they did was to install HIGHS with

pip install highspy

and then to replace

model.solve(solver="cbc")

with following lines:

from pyomo.contrib import appsi
opt = appsi.solvers.Highs()
results = opt.solve(model)
ckaldemeyer commented 1 week ago

I am currently using it with pyomo only but there still seems to be an issue with streaming the solver output which I have addressed here: https://github.com/ERGO-Code/HiGHS/issues/1834

p-snft commented 1 week ago

I considered to add official support but as the structure of the results differs a lot, it will not work as a drop-in replacement.