Skip to content

Commit

Permalink
add Highs to requirements (#766)
Browse files Browse the repository at this point in the history
* add highs to requirements

Signed-off-by: Victor Garcia Reolid <[email protected]>

* docs: add changelog entry

Signed-off-by: Victor Garcia Reolid <[email protected]>

* fix: get results with infeasible termination status instead of RuntimeError

Signed-off-by: Victor Garcia Reolid <[email protected]>

* fx: avoid double solving

Signed-off-by: Victor Garcia Reolid <[email protected]>

* style: fix HiGHS capitalization

Signed-off-by: Victor Garcia Reolid <[email protected]>

* remove HiGHS from requirements

Signed-off-by: Victor Garcia Reolid <[email protected]>

* remove dependency

Signed-off-by: Victor Garcia Reolid <[email protected]>

* add dependency back

Signed-off-by: Victor Garcia Reolid <[email protected]>

* docs: document how to install HiGHS

Signed-off-by: Victor Garcia Reolid <[email protected]>

* add HIghs to Dockerfile

Signed-off-by: Victor Garcia Reolid <[email protected]>

* remove extra lines

Signed-off-by: Victor Garcia Reolid <[email protected]>

* fix typos

Signed-off-by: Victor Garcia Reolid <[email protected]>

* load solution when termination_condition!=infeasible

Signed-off-by: Victor Garcia Reolid <[email protected]>

* address some textual changes

Signed-off-by: Victor Garcia Reolid <[email protected]>

* fx CBC capitalization

Signed-off-by: Victor Garcia Reolid <[email protected]>

* fix grammar

Signed-off-by: Victor Garcia Reolid <[email protected]>

* check if there are results in a more robustly

Signed-off-by: Victor Garcia Reolid <[email protected]>

* update inline comment

Signed-off-by: F.N. Claessen <[email protected]>

---------

Signed-off-by: Victor Garcia Reolid <[email protected]>
Signed-off-by: F.N. Claessen <[email protected]>
Co-authored-by: F.N. Claessen <[email protected]>
  • Loading branch information
victorgarcia98 and Flix6x authored Jul 31, 2023
1 parent 4a68ba8 commit 654623e
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 25, 2023
============================
Expand Down
2 changes: 1 addition & 1 deletion documentation/configuration.rst
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
13 changes: 10 additions & 3 deletions documentation/host/deployment.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ 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.
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.
To compute schedules, FlexMeasures uses the `CBC <https://github.com/coin-or/Cbc>`_ (FlexMeasures solver by default) or `HiGHS <https://highs.dev/>`_ mixed integer linear optimization solver.
Solvers are 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.
CBC needs to be present on the server where FlexMeasures runs, under the ``cbc`` command.

You can install it on Debian like this:

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
20 changes: 17 additions & 3 deletions documentation/tut/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,12 @@ 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.

Installing Cbc can be done on Unix via:
CBC
*****

Installing CBC can be done on Unix via:

.. code-block:: bash
Expand All @@ -239,7 +242,18 @@ Installing Cbc can be done on Unix via:

We provide a script for installing from source (without requiring ``sudo`` rights) in the `ci` folder.

More information (e.g. for installing on Windows) on `the Cbc website <https://projects.coin-or.org/Cbc>`_.
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 be installed using pip:

.. 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
8 changes: 7 additions & 1 deletion flexmeasures/data/models/planning/linear_optimization.py
Original file line number Diff line number Diff line change
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 a feasible solution has been found
if len(results.solution) > 0:
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
Original file line number Diff line number Diff line change
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

0 comments on commit 654623e

Please sign in to comment.