Hello, community of open energy modelers!
As the scale of energy system models increases rapidly for multi-period, multi-region, multi-sector and multi-scenario cases, the performance of modeling software is vital for efficient construction and optimization of energy models.
According to the wiki page, the major open source modeling software widely used by open energy models are Pyomo in Python and JuMP.jl in Julia. The performance of JuMP.jl has been proved to be top-notch and significantly faster than Pyomo. There have been multiple attempts to accelerate modeling in Python, including the excellent linopy project by PyPSA team and python-mip. However, existing Python solutions are still slower than JuMP.jl on large scale models as shown by their benchmarks: linopy, python-mip.
Therefore, we recently release an efficient modeling language in Python named PyOptInterface:
- Source code: GitHub - metab0t/PyOptInterface: Efficient modeling interface for optimization problems in Python
- Documentation: PyOptInterface documentation
The key features of PyOptInterface that might be useful for open model energy models includes:
-
Fast speed to construct large scale models:
It uses the C API of the optimizer directly instead of relying on official Python bindings like gurobipy, so the speed to construct optimization model is extremely fast. The benchmark comparing PyOptInterface with some other modeling interfaces can be found here.
PyOptInterface is among the fastest modeling interfaces in terms of model construction time: 10β20x faster than Pyomo, comparable with JuMP.jl and faster than some official Python bindings provided by vendors of optimizer. -
Native support for multidimensional structure:
In energy models, we often need to handle complex variables and constraints nested in multiple dimensions, such as time, region and scenario.
In PyOptInterface, we provide a convenienttupledict
to store and select N-D variables and constraints easily. Compared withxarray
or other packages,tupledict
is just a lightweight extended version of built-indict
in Python and has excellent indexing performance.
Additionally, the variables and constraints in PyOptInterface are just lightweight handles that can be stored in Numpyndarrays
directly to form a N-D array. The link shows how we use a 2-Dndarray
of variables to solve N-queens problem. -
Fine-grained manipulation of optimization model:
PyOptInterface maintains a persistent model that can be incrementally modified and re-solved without rebuilding it from scratch.
It supports adding/removing variables or constraints, changing objective function, changing the right-hand side of constraint, change the linear coefficient of a variable in constraint, etc.
This feature is especially useful for multi-scenario analysis where we need to solve a lot of models with small modifications sequentially.
This is a simple example where we change the load curve in economic dispatch and re-solve it instantly.
Currently, PyOptInterface supports the following problem types:
- Linear Programming (LP)
- Mixed-Integer Linear Programming (MILP)
- Quadratic Programming (QP)
- Mixed-Integer Quadratic Programming (MIQP)
- Quadratically Constrained Quadratic Programming (QCQP)
- Mixed-Integer Quadratically Constrained Quadratic Programming (MIQCQP)
- Second-Order Cone Programming (SOCP)
- Mixed-Integer Second-Order Cone Programming (MISOCP)
And supports the following optimizers:
The coverage of supported problem types and optimizers can satisfy a large portion of needs for open energy modeling.
We have released PyOptInterface on PyPI for Windows, Linux and macOS. It can be installed via pip:
pip install pyoptinterface
PyOptInterface has no dependencies other than Python itself. However, to use it with a specific optimizer, you need to install the corresponding optimizer manually. The details can be found on the configurations of optimizers.
It can also be installed with pre-built HiGHS:
pip install pyoptinterface[highs]
This package is still new and any forms of feedback are welcome. We sincerely hope this package to be useful for researchers in open energy modeling field and accelerate your computational work flow.
If you find this package useful or interesting, please also give us a star on Github to support the following development.
Best regards.