Skip to content

Commit

Permalink
Merge branch 'master' into enh/remove-numpy-pin
Browse files Browse the repository at this point in the history
  • Loading branch information
lkstrp authored Aug 14, 2024
2 parents 15c3813 + b0ff7eb commit e848cf1
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 17 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ jobs:

- name: Install package and dependencies
run: |
python -m pip install "$(ls dist/*.whl)[dev,solvers]"
python -m pip install uv
uv pip install --system "$(ls dist/*.whl)[dev,solvers]"
- name: Test with pytest
env:
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ repos:
- id: trailing-whitespace
- id: check-merge-conflict
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.4
rev: v0.5.7
hooks:
- id: ruff
args: [--fix]
Expand All @@ -33,7 +33,7 @@ repos:
- id: jupyter-notebook-cleanup
exclude: examples/solve-on-remote.ipynb
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.11.0
rev: v1.11.1
hooks:
- id: mypy
files: ^(linopy|test)/
Expand Down
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,23 @@
[![doc](https://readthedocs.org/projects/linopy/badge/?version=latest)](https://linopy.readthedocs.io/en/latest/)
[![codecov](https://codecov.io/gh/PyPSA/linopy/branch/master/graph/badge.svg?token=TT4EYFCCZX)](https://codecov.io/gh/PyPSA/linopy)



        **L**inear\
        **I**nteger\
        **N**on-linear\
        **O**ptimization in\
        **P Y**thon

**linopy** is an open-source python package that facilitates **optimization** with **real world data**. It builds a bridge between data analysis packages like [xarray](https://github.com/pydata/xarray) & [pandas](https://pandas.pydata.org/) and problem solvers like [cbc](https://projects.coin-or.org/Cbc), [gurobi](https://www.gurobi.com/) (see the full list below). **Linopy** supports **Linear, Integer, Mixed-Integer and Quadratic Programming** while aiming to make linear programming in Python easy, highly-flexible and performant.



## Benchmarks

**linopy** is designed to be fast and efficient. The following benchmark compares the performance of **linopy** with the alternative popular optimization packages.

![Performance Benchmark](https://private-user-images.githubusercontent.com/19226431/311655091-e3b8a6b9-da72-407b-bd37-7c80ada39d46.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTQ3NDY1NzYsIm5iZiI6MTcxNDc0NjI3NiwicGF0aCI6Ii8xOTIyNjQzMS8zMTE2NTUwOTEtZTNiOGE2YjktZGE3Mi00MDdiLWJkMzctN2M4MGFkYTM5ZDQ2LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA1MDMlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNTAzVDE0MjQzNlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWQ3M2Q5MTMxY2EzNTI4OTUzNDViMzUzZTkyOGQ0MzliYTYxNjc2ODdhNDFjODRiNmE4OGIwNWI0MWZlNDZmMWUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.WFHwXmalW05hSm0oxWGmAEnVvcdFyCvQMxDJB7v3yBk)
![Performance Benchmark](doc/benchmark_resource-overhead.png)


## Main features
Expand Down
Binary file added doc/benchmark_resource-overhead.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions doc/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ Release Notes
Upcoming Version
----------------

Version 0.3.14
--------------

* Ensure compatibility with xarray >= v2024.07.0, which has drop the ``squeeze`` argument from the ``groupby`` function.

Version 0.3.13
--------------
Expand Down
7 changes: 1 addition & 6 deletions linopy/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1212,7 +1212,6 @@ def diff(self, dim: str, n: int = 1) -> LinearExpression:
def groupby(
self,
group: DataFrame | Series | DataArray,
squeeze: bool = True,
restore_coord_dims: bool | None = None,
**kwargs,
) -> LinearExpressionGroupby:
Expand All @@ -1227,10 +1226,6 @@ def groupby(
group : str, DataArray or IndexVariable
Array whose unique values should be used to group this array. If a
string, must be the name of a variable contained in this dataset.
squeeze : bool, optional
If "group" is a dimension of any arrays in this dataset, `squeeze`
controls whether the subarrays have a dimension of length 1 along
that dimension or if the dimension is squeezed out.
restore_coord_dims : bool, optional
If True, also restore the dimension order of multi-dimensional
coordinates.
Expand All @@ -1242,7 +1237,7 @@ def groupby(
the correct return type.
"""
ds = self.data
kwargs = dict(squeeze=squeeze, restore_coord_dims=restore_coord_dims, **kwargs)
kwargs = dict(restore_coord_dims=restore_coord_dims, **kwargs)
return LinearExpressionGroupby(ds, group, model=self.model, kwargs=kwargs)

def rolling(
Expand Down
2 changes: 1 addition & 1 deletion linopy/solvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ def get_solver_solution() -> Solution:
dual_ = [str(d) for d in m.getConstraint()]
dual = pd.Series(m.getDual(dual_), index=dual_, dtype=float)
dual = set_int_index(dual)
except xpress.SolverError:
except (xpress.SolverError, SystemError):
logger.warning("Dual values of MILP couldn't be parsed")
dual = pd.Series(dtype=float)

Expand Down
7 changes: 1 addition & 6 deletions linopy/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,6 @@ def dot(self, other: ndarray | Variable) -> QuadraticExpression | LinearExpressi
def groupby(
self,
group: DataArray,
squeeze: bool = True,
restore_coord_dims: bool | None = None,
) -> LinearExpressionGroupby:
"""
Expand All @@ -530,10 +529,6 @@ def groupby(
group : str, DataArray or IndexVariable
Array whose unique values should be used to group this array. If a
string, must be the name of a variable contained in this dataset.
squeeze : bool, optional
If "group" is a dimension of any arrays in this dataset, `squeeze`
controls whether the subarrays have a dimension of length 1 along
that dimension or if the dimension is squeezed out.
restore_coord_dims : bool, optional
If True, also restore the dimension order of multi-dimensional
coordinates.
Expand All @@ -545,7 +540,7 @@ def groupby(
the correct return type.
"""
return self.to_linexpr().groupby(
group=group, squeeze=squeeze, restore_coord_dims=restore_coord_dims
group=group, restore_coord_dims=restore_coord_dims
)

def rolling(
Expand Down

0 comments on commit e848cf1

Please sign in to comment.