Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable usage of Highs solver #766

Merged
merged 22 commits into from Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
62a3c21
add highs to requirements
victorgarcia98 Jul 19, 2023
150a951
Merge branch 'main' into dependencies/add-highspy
victorgarcia98 Jul 20, 2023
d615b25
Merge branch 'main' into dependencies/add-highspy
victorgarcia98 Jul 21, 2023
ebbc65a
docs: add changelog entry
victorgarcia98 Jul 21, 2023
51a3148
fix: get results with infeasible termination status instead of Runtim…
victorgarcia98 Jul 23, 2023
a699c16
fx: avoid double solving
victorgarcia98 Jul 24, 2023
f6b3772
style: fix HiGHS capitalization
victorgarcia98 Jul 24, 2023
6d9c2a6
remove HiGHS from requirements
victorgarcia98 Jul 24, 2023
58b24e3
remove dependency
victorgarcia98 Jul 24, 2023
bb00d3a
add dependency back
victorgarcia98 Jul 24, 2023
d2809ad
docs: document how to install HiGHS
victorgarcia98 Jul 24, 2023
2a94530
add HIghs to Dockerfile
victorgarcia98 Jul 24, 2023
ffacf30
remove extra lines
victorgarcia98 Jul 24, 2023
ce969db
fix typos
victorgarcia98 Jul 24, 2023
ae09379
load solution when termination_condition!=infeasible
victorgarcia98 Jul 24, 2023
c8cb457
Merge branch 'main' into dependencies/add-highspy
victorgarcia98 Jul 24, 2023
3d249ce
address some textual changes
victorgarcia98 Jul 24, 2023
97d9bde
fx CBC capitalization
victorgarcia98 Jul 24, 2023
9a253df
fix grammar
victorgarcia98 Jul 24, 2023
ca7a0e6
check if there are results in a more robustly
victorgarcia98 Jul 24, 2023
aea59bb
update inline comment
Flix6x Jul 25, 2023
2fffe45
Merge branch 'main' into dependencies/add-highspy
victorgarcia98 Jul 31, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Expand Up @@ -12,7 +12,7 @@ WORKDIR /app
COPY requirements /app/requirements

# py dev tooling
RUN python3 -m pip install --no-cache-dir --upgrade pip && python3 --version && pip3 install --no-cache-dir --upgrade setuptools && pip3 install --no-cache-dir -r requirements/app.txt -r requirements/dev.txt -r requirements/test.txt
RUN python3 -m pip install --no-cache-dir --upgrade pip && python3 --version && pip3 install --no-cache-dir --upgrade setuptools && pip3 install highspy && pip3 install --no-cache-dir -r requirements/app.txt -r requirements/dev.txt -r requirements/test.txt

# Copy code and meta/config data
COPY setup.* .flaskenv wsgi.py /app/
Expand Down
3 changes: 1 addition & 2 deletions documentation/changelog.rst
Expand Up @@ -27,8 +27,7 @@ Infrastructure / Support
* Add support for profiling Flask API calls using ``pyinstrument`` (if installed). Can be enabled by setting the environment variable ``FLEXMEASURES_PROFILE_REQUESTS`` to ``True`` [see `PR #722 <https://www.github.com/FlexMeasures/flexmeasures/pull/722>`_]
* The endpoint `[POST] /health/ready <api/v3_0.html#get--api-v3_0-health-ready>`_ returns the status of the Redis connection, if configured [see `PR #699 <https://www.github.com/FlexMeasures/flexmeasures/pull/699>`_]
* Document the `device_scheduler` linear program [see `PR #764 <https://www.github.com/FlexMeasures/flexmeasures/pull/764>`_].

/api/v3_0/health/ready
* Add support for `HiGHS <https://highs.dev/>`_ solver [see `PR #766 <https://www.github.com/FlexMeasures/flexmeasures/pull/766>`_].

v0.14.2 | July 21, 2023
============================
Expand Down
2 changes: 1 addition & 1 deletion documentation/configuration.rst
Expand Up @@ -55,7 +55,7 @@ Default: ``False``
FLEXMEASURES_LP_SOLVER
^^^^^^^^^^^^^^^^^^^^^^

The command to run the scheduling solver. This is the executable command which FlexMeasures calls via the `pyomo library <http://www.pyomo.org/>`_. Other values might be ``cplex`` or ``glpk``. Consult `their documentation <https://pyomo.readthedocs.io/en/stable/solving_pyomo_models.html#supported-solvers>`_ to learn more.
The command to run the scheduling solver. This is the executable command which FlexMeasures calls via the `pyomo library <http://www.pyomo.org/>`_. Other values might be ``cplex``, ``glpk`` or ``appsi_highs`` for `HiGHS <https://highs.dev/>`_. Consult `their documentation <https://pyomo.readthedocs.io/en/stable/solving_pyomo_models.html#supported-solvers>`_ to learn more.

Default: ``"cbc"``

Expand Down
5 changes: 5 additions & 0 deletions documentation/dev/introduction.rst
Expand Up @@ -54,6 +54,11 @@ Go into the ``flexmeasures`` folder and install all dependencies including the o

$ apt-get install coinor-cbc

Alternatively, HiGHS solver can be installed with pip:

.. code-block:: bash

$ pip install highspy

Configuration
^^^^^^^^^^^^^^^^^^^^
Expand Down
9 changes: 8 additions & 1 deletion documentation/host/deployment.rst
Expand Up @@ -48,7 +48,7 @@ Keep in mind that FlexMeasures is based on `Flask <https://flask.palletsprojects
Install the linear solver on the server
---------------------------------------

To compute schedules, FlexMeasures uses the `Cbc <https://github.com/coin-or/Cbc>`_ mixed integer linear optimization solver.
To compute schedules, FlexMeasures uses the `Cbc <https://github.com/coin-or/Cbc>`_ or `HiGHS <https://highs.dev/>`_ mixed integer linear optimization solvers.
victorgarcia98 marked this conversation as resolved.
Show resolved Hide resolved
It is used through `Pyomo <http://www.pyomo.org>`_\ , so in principle supporting a `different solver <https://pyomo.readthedocs.io/en/stable/solving_pyomo_models.html#supported-solvers>`_ would be possible.

Cbc needs to be present on the server where FlexMeasures runs, under the ``cbc`` command.
Expand All @@ -66,3 +66,10 @@ pass a directory for the installation.

In case you want to install a later version, adapt the version in the script.

HiGHS can be installed using pip:

.. code-block:: bash

$ pip install highspy


16 changes: 15 additions & 1 deletion documentation/tut/installation.rst
Expand Up @@ -226,7 +226,10 @@ For FlexMeasures to be able to send email to users (e.g. for resetting passwords
Install an LP solver
^^^^^^^^^^^^^^^^^^^^

For planning balancing actions, the FlexMeasures platform uses a linear program solver. Currently that is the Cbc solver. See :ref:`solver-config` if you want to change to a different solver.
For planning balancing actions, the FlexMeasures platform uses a linear program solver. Currently that is the Cbc or HiGHS solvers. See :ref:`solver-config` if you want to change to a different solver.
victorgarcia98 marked this conversation as resolved.
Show resolved Hide resolved

CBC
*****

Installing Cbc can be done on Unix via:

Expand All @@ -241,6 +244,17 @@ We provide a script for installing from source (without requiring ``sudo`` right

More information (e.g. for installing on Windows) on `the Cbc website <https://projects.coin-or.org/Cbc>`_.

HiGHS
******

HiGHS is a modern LP solver that aims at solving large problems. It can installed using pip:
victorgarcia98 marked this conversation as resolved.
Show resolved Hide resolved

.. code-block:: bash

$ pip install highspy

More information (e.g. for installing on Windows) on `the HiGHS website <https://highs.dev/>`_.


Install and configure Redis
^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
10 changes: 8 additions & 2 deletions flexmeasures/data/models/planning/linear_optimization.py
Expand Up @@ -18,7 +18,7 @@
)
from pyomo.environ import UnknownSolver # noqa F401
from pyomo.environ import value
from pyomo.opt import SolverFactory, SolverResults
from pyomo.opt import SolverFactory, SolverResults, TerminationCondition

from flexmeasures.data.models.planning.utils import initialize_series
from flexmeasures.utils.calculations import apply_stock_changes_and_losses
Expand Down Expand Up @@ -339,10 +339,16 @@ def cost_function(m):
model.costs = Objective(rule=cost_function, sense=minimize)

# Solve

# load_solutions=False to avoid a RuntimeError exception in appsi solvers when solving an infeasible problem.
results = SolverFactory(current_app.config.get("FLEXMEASURES_LP_SOLVER")).solve(
model
model, load_solutions=False
)

# load the results only if the termination conditions is not infeasible
victorgarcia98 marked this conversation as resolved.
Show resolved Hide resolved
if results.solver.termination_condition != TerminationCondition.infeasible:
victorgarcia98 marked this conversation as resolved.
Show resolved Hide resolved
model.solutions.load_from(results)

planned_costs = value(model.costs)
planned_power_per_device = []
for d in model.d:
Expand Down
2 changes: 1 addition & 1 deletion requirements/app.in
Expand Up @@ -67,4 +67,4 @@ Flask-SQLAlchemy>=2.4.3,<3
# flask should be after all the flask plugins, because setup might find they ARE flask
# <2.3: https://github.com/Parallels/rq-dashboard/issues/417 and https://github.com/FlexMeasures/flexmeasures/issues/754 and flask-login 0.6.1 not compatible
flask>=1.0, <=2.1.2
werkzeug<=2.1
werkzeug<=2.1