Skip to content

Commit

Permalink
chore: apply pre-commit hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
pre-commit-ci[bot] authored and afuetterer committed Jul 18, 2024
1 parent f69f1fe commit 756928f
Show file tree
Hide file tree
Showing 65 changed files with 514 additions and 549 deletions.
8 changes: 4 additions & 4 deletions benchmark/notebooks/plot-benchmarks.py.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
"metadata": {},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
"import pandas as pd\n",
"import seaborn as sns\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
"sns.set_theme(\"paper\", \"white\")\n",
"#plt.rc('text', usetex=True)\n",
"#plt.rc('font', family='sans-serif')"
Expand All @@ -37,7 +37,7 @@
"source": [
"if snakemake.wildcards[\"kind\"] == 'overhead':\n",
" labels = ['Overhead time (s)', 'Overhead memory (MB)']\n",
"else: \n",
"else:\n",
" labels = ['Time (s)', 'Memory (MB)']\n",
"\n",
"g = sns.FacetGrid(data=df, row=\"kind\", sharey=False, height=2., aspect=2)\n",
Expand All @@ -61,7 +61,7 @@
"source": [
"if snakemake.wildcards[\"kind\"] == 'overhead':\n",
" label = 'Computational overhead [MBs]'\n",
"else: \n",
"else:\n",
" label = 'Computational resource [MBs]'\n",
"\n",
"df = data.assign(Resource = data[\"Time\"] * data[\"Memory\"])\n",
Expand Down
8 changes: 4 additions & 4 deletions benchmark/scripts/benchmark_cvxpy.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import cvxpy as cp
import numpy as np
from common import profile
from numpy.random import randint, seed
from numpy.random import default_rng

# Random seed for reproducibility
seed(125)
rng = default_rng(125)


def basic_model(n, solver):
Expand All @@ -26,8 +26,8 @@ def basic_model(n, solver):

def knapsack_model(n, solver):
# Define the variables
weight = randint(1, 100, size=n)
value = randint(1, 100, size=n)
weight = rng.integers(1, 100, size=n)
value = rng.integers(1, 100, size=n)

x = cp.Variable(n, boolean=True)

Expand Down
8 changes: 4 additions & 4 deletions benchmark/scripts/benchmark_gurobipy.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import gurobipy as gp
import numpy as np
from common import profile
from numpy.random import randint, seed
from numpy.random import default_rng

# Random seed for reproducibility
seed(125)
rng = default_rng(125)


def basic_model(n, solver):
Expand Down Expand Up @@ -32,8 +32,8 @@ def knapsack_model(n, solver):
# Create a new model
m = gp.Model()

weight = randint(1, 100, size=n)
value = randint(1, 100, size=n)
weight = rng.integers(1, 100, size=n)
value = rng.integers(1, 100, size=n)

# Create variables
x = m.addMVar(n, vtype=gp.GRB.BINARY, name="x")
Expand Down
10 changes: 4 additions & 6 deletions benchmark/scripts/benchmark_linopy.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Nov 19 17:40:33 2021.
@author: fabian
"""


from common import profile
from numpy import arange
from numpy.random import randint, seed
from numpy.random import default_rng

from linopy import Model

# Random seed for reproducibility
seed(125)
rng = default_rng(125)


def basic_model(n, solver):
Expand All @@ -33,8 +31,8 @@ def basic_model(n, solver):
def knapsack_model(n, solver):
m = Model()
packages = m.add_variables(coords=[arange(n)], binary=True)
weight = randint(1, 100, size=n)
value = randint(1, 100, size=n)
weight = rng.integers(1, 100, size=n)
value = rng.integers(1, 100, size=n)
m.add_constraints((weight * packages).sum() <= 200)
m.add_objective(-(value * packages).sum()) # use minus because of minimization
m.solve(solver_name=solver)
Expand Down
8 changes: 4 additions & 4 deletions benchmark/scripts/benchmark_ortools.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from common import profile
from numpy.random import randint, seed
from numpy.random import default_rng
from ortools.linear_solver import pywraplp

# Random seed for reproducibility
seed(125)
rng = default_rng(125)


def model(n, solver):
Expand Down Expand Up @@ -41,8 +41,8 @@ def knapsack_model(n, solver):
# Create a new linear solver
solver = pywraplp.Solver("LinearExample", pywraplp.Solver.GUROBI_LINEAR_PROGRAMMING)

weight = randint(1, 100, size=n)
value = randint(1, 100, size=n)
weight = rng.integers(1, 100, size=n)
value = rng.integers(1, 100, size=n)

x = {i: solver.BoolVar("x_%d" % i) for i in range(n)}
# Create constraints
Expand Down
9 changes: 4 additions & 5 deletions benchmark/scripts/benchmark_pulp.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import pulp
from common import profile
from numpy import arange
from numpy.random import randint, seed
from numpy.random import default_rng

# Random seed for reproducibility
seed(125)
rng = default_rng(125)


def basic_model(n, solver):
Expand Down Expand Up @@ -34,8 +33,8 @@ def knapsack_model(n, solver):
m.i = list(range(n))

# Define the variables
weight = randint(1, 100, size=n)
value = randint(1, 100, size=n)
weight = rng.integers(1, 100, size=n)
value = rng.integers(1, 100, size=n)

x = pulp.LpVariable.dicts("x", (m.i,), lowBound=0, upBound=1, cat=pulp.LpInteger)

Expand Down
11 changes: 4 additions & 7 deletions benchmark/scripts/benchmark_pyomo.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Nov 19 17:40:33 2021.
@author: fabian
"""


from common import profile
from numpy import arange
from numpy.random import randint, seed
from numpy.random import default_rng
from pyomo.environ import (
Binary,
ConcreteModel,
Expand All @@ -18,12 +16,11 @@
Set,
Var,
maximize,
value,
)
from pyomo.opt import SolverFactory

# Random seed for reproducibility
seed(125)
rng = default_rng(125)


def basic_model(n, solver):
Expand Down Expand Up @@ -57,8 +54,8 @@ def knapsack_model(n, solver):
m.i = Set(initialize=arange(n))

m.x = Var(m.i, domain=Binary)
m.weight = randint(1, 100, size=n)
m.value = randint(1, 100, size=n)
m.weight = rng.integers(1, 100, size=n)
m.value = rng.integers(1, 100, size=n)

def bound1(m):
return sum(m.x[i] * m.weight[i] for i in m.i) <= 200
Expand Down
1 change: 0 additions & 1 deletion benchmark/scripts/benchmarks-pypsa-eur/benchmark-linopy.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Feb 15 16:20:51 2022.
Expand Down
3 changes: 1 addition & 2 deletions benchmark/scripts/benchmarks-pypsa-eur/benchmark-pyomo.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Feb 15 16:20:51 2022.
Expand All @@ -18,7 +17,7 @@ def solve():
n.generators.p_nom_max.fillna(np.inf, inplace=True)
n.snapshots = n.snapshots[:NSNAPSHOTS]

m = n.lopf(
m = n.lopf( # noqa: F841
solver_options=SOLVER_PARAMS, formulation="kirchhoff", solver_name=SOLVER
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Feb 15 16:20:51 2022.
Expand All @@ -18,7 +17,7 @@ def solve():
n.generators.p_nom_max.fillna(np.inf, inplace=True)
n.snapshots = n.snapshots[:NSNAPSHOTS]

m = n.lopf(solver_options=SOLVER_PARAMS, pyomo=False, solver_name=SOLVER)
m = n.lopf(solver_options=SOLVER_PARAMS, pyomo=False, solver_name=SOLVER) # noqa: F841


solve()
1 change: 0 additions & 1 deletion benchmark/scripts/benchmarks-pypsa-eur/plot-benchmarks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Feb 15 17:11:01 2022.
Expand Down
1 change: 0 additions & 1 deletion benchmark/scripts/concat-benchmarks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Feb 9 09:34:00 2022.
Expand Down
5 changes: 1 addition & 4 deletions benchmark/scripts/leftovers/benchmark-linopy.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Nov 19 17:40:33 2021.
@author: fabian
"""


import pandas as pd
from common import profile
from numpy import arange, cos, sin
from numpy import arange

from linopy import Model

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Feb 15 16:20:51 2022.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Feb 15 16:20:51 2022.
Expand All @@ -18,7 +17,7 @@ def solve():
n.generators.p_nom_max.fillna(np.inf, inplace=True)
n.snapshots = n.snapshots[:NSNAPSHOTS]

m = n.lopf(
m = n.lopf( # noqa: F841
solver_options=SOLVER_PARAMS, formulation="kirchhoff", solver_name=SOLVER
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Feb 15 16:20:51 2022.
Expand All @@ -18,7 +17,7 @@ def solve():
n.generators.p_nom_max.fillna(np.inf, inplace=True)
n.snapshots = n.snapshots[:NSNAPSHOTS]

m = n.lopf(solver_options=SOLVER_PARAMS, pyomo=False, solver_name=SOLVER)
m = n.lopf(solver_options=SOLVER_PARAMS, pyomo=False, solver_name=SOLVER) # noqa: F841


solve()
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Feb 15 17:11:01 2022.
Expand Down
4 changes: 0 additions & 4 deletions benchmark/scripts/merge-benchmarks.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Feb 14 18:00:44 2022.
@author: fabian
"""


from pathlib import Path

import pandas as pd

df = [pd.read_csv(fn, index_col=0) for fn in snakemake.input.benchmarks]
Expand Down
1 change: 0 additions & 1 deletion benchmark/scripts/plot-benchmarks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Jan 26 23:37:38 2022.
Expand Down
1 change: 0 additions & 1 deletion benchmark/scripts/run-linopy.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Nov 19 17:40:33 2021.
Expand Down
2 changes: 0 additions & 2 deletions benchmark/scripts/run-pyomo.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Nov 19 17:40:33 2021.
@author: fabian
"""


from benchmark_pyomo import basic_model, knapsack_model

if snakemake.config["benchmark"] == "basic":
Expand Down
9 changes: 4 additions & 5 deletions benchmark/scripts/write-lp-file.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import pandas as pd
from numpy import arange
from numpy.random import randint, seed
from numpy.random import default_rng

from linopy import Model

# Random seed for reproducibility
seed(125)
rng = default_rng(125)


if snakemake.config["benchmark"] == "basic":
Expand All @@ -25,8 +24,8 @@ def create_model(n):
def create_model(n):
m = Model()
packages = m.add_variables(coords=[arange(n)], binary=True)
weight = randint(1, 100, size=n)
value = randint(1, 100, size=n)
weight = rng.integers(1, 100, size=n)
value = rng.integers(1, 100, size=n)
m.add_constraints((weight * packages).sum() <= 200)
m.add_objective(-(value * packages).sum()) # use minus because of minimization
return m
Expand Down
1 change: 0 additions & 1 deletion doc/logo.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Oct 17 12:08:47 2021.
Expand Down
1 change: 1 addition & 0 deletions examples/create-a-model-with-coordinates.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"outputs": [],
"source": [
"import pandas as pd\n",
"\n",
"time = pd.Index(range(10), name='time')\n",
"\n",
"x = m.add_variables(lower=0, coords=[time], name='x', )\n",
Expand Down
1 change: 1 addition & 0 deletions examples/create-a-model.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"outputs": [],
"source": [
"from linopy import Model\n",
"\n",
"m = Model()"
]
},
Expand Down
Loading

0 comments on commit 756928f

Please sign in to comment.