Skip to content

Commit

Permalink
Merge pull request PyPSA#339 from PyPSA/pre-commit-ci-update-config
Browse files Browse the repository at this point in the history
[pre-commit.ci] pre-commit autoupdate
  • Loading branch information
FabianHofmann authored Aug 20, 2024
2 parents b0ff7eb + a758a27 commit cff0360
Show file tree
Hide file tree
Showing 13 changed files with 148 additions and 116 deletions.
2 changes: 1 addition & 1 deletion .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.7
rev: v0.6.1
hooks:
- id: ruff
args: [--fix]
Expand Down
64 changes: 41 additions & 23 deletions benchmark/notebooks/plot-benchmarks.py.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"import seaborn as sns\n",
"\n",
"sns.set_theme(\"paper\", \"white\")\n",
"#plt.rc('text', usetex=True)\n",
"#plt.rc('font', family='sans-serif')"
"# plt.rc('text', usetex=True)\n",
"# plt.rc('font', family='sans-serif')"
]
},
{
Expand All @@ -24,8 +24,8 @@
"outputs": [],
"source": [
"data = pd.read_csv(snakemake.input[0], index_col=0)\n",
"cols = ['Time', 'Memory']\n",
"df = data.melt(id_vars=data.columns.drop(cols), value_vars=cols, var_name='kind')"
"cols = [\"Time\", \"Memory\"]\n",
"df = data.melt(id_vars=data.columns.drop(cols), value_vars=cols, var_name=\"kind\")"
]
},
{
Expand All @@ -35,21 +35,31 @@
"metadata": {},
"outputs": [],
"source": [
"if snakemake.wildcards[\"kind\"] == 'overhead':\n",
" labels = ['Overhead time (s)', 'Overhead memory (MB)']\n",
"if snakemake.wildcards[\"kind\"] == \"overhead\":\n",
" labels = [\"Overhead time (s)\", \"Overhead memory (MB)\"]\n",
"else:\n",
" labels = ['Time (s)', 'Memory (MB)']\n",
" labels = [\"Time (s)\", \"Memory (MB)\"]\n",
"\n",
"g = sns.FacetGrid(data=df, row=\"kind\", sharey=False, height=2., aspect=2)\n",
"g.map_dataframe(sns.lineplot, x=\"Number of Variables\", y='value', hue='API', style='API',\n",
" marker='.', legend='full', zorder=8)\n",
"g = sns.FacetGrid(data=df, row=\"kind\", sharey=False, height=2.0, aspect=2)\n",
"g.map_dataframe(\n",
" sns.lineplot,\n",
" x=\"Number of Variables\",\n",
" y=\"value\",\n",
" hue=\"API\",\n",
" style=\"API\",\n",
" marker=\".\",\n",
" legend=\"full\",\n",
" zorder=8,\n",
")\n",
"for ax, label in zip(g.axes.ravel(), labels):\n",
" ax.set_ylabel(label)\n",
" ax.set_title(\"\")\n",
" ax.grid(axis='y', lw=0.2, color='grey', zorder=3, alpha=0.4)\n",
" ax.grid(axis=\"y\", lw=0.2, color=\"grey\", zorder=3, alpha=0.4)\n",
"g.fig.tight_layout()\n",
"g.add_legend()\n",
"g.fig.savefig(snakemake.output.time_memory, bbox_inches='tight', pad_inches=0.1, dpi=300)"
"g.fig.savefig(\n",
" snakemake.output.time_memory, bbox_inches=\"tight\", pad_inches=0.1, dpi=300\n",
")"
]
},
{
Expand All @@ -59,25 +69,33 @@
"metadata": {},
"outputs": [],
"source": [
"if snakemake.wildcards[\"kind\"] == 'overhead':\n",
" label = 'Computational overhead [MBs]'\n",
"if snakemake.wildcards[\"kind\"] == \"overhead\":\n",
" label = \"Computational overhead [MBs]\"\n",
"else:\n",
" label = 'Computational resource [MBs]'\n",
" label = \"Computational resource [MBs]\"\n",
"\n",
"df = data.assign(Resource = data[\"Time\"] * data[\"Memory\"])\n",
"cols = ['Resource']\n",
"df = df.melt(id_vars=df.columns.drop(cols), value_vars=cols, var_name='kind')\n",
"df = data.assign(Resource=data[\"Time\"] * data[\"Memory\"])\n",
"cols = [\"Resource\"]\n",
"df = df.melt(id_vars=df.columns.drop(cols), value_vars=cols, var_name=\"kind\")\n",
"\n",
"fig, ax = plt.subplots(figsize=(6, 3))\n",
"sns.lineplot(data=df, x=\"Number of Variables\", y='value', hue='API', style='API',\n",
" marker='.', legend='full', zorder=8)\n",
"sns.lineplot(\n",
" data=df,\n",
" x=\"Number of Variables\",\n",
" y=\"value\",\n",
" hue=\"API\",\n",
" style=\"API\",\n",
" marker=\".\",\n",
" legend=\"full\",\n",
" zorder=8,\n",
")\n",
"sns.despine()\n",
"ax.set_ylabel(label)\n",
"ax.set_title(\"\")\n",
"plt.ticklabel_format(axis='both', style='sci', scilimits=(3,3))\n",
"ax.grid(axis='y', lw=0.2, color='grey', zorder=3, alpha=0.4)\n",
"plt.ticklabel_format(axis=\"both\", style=\"sci\", scilimits=(3, 3))\n",
"ax.grid(axis=\"y\", lw=0.2, color=\"grey\", zorder=3, alpha=0.4)\n",
"fig.tight_layout()\n",
"fig.savefig(snakemake.output.resource, bbox_inches='tight', pad_inches=0.1, dpi=300)"
"fig.savefig(snakemake.output.resource, bbox_inches=\"tight\", pad_inches=0.1, dpi=300)"
]
}
],
Expand Down
20 changes: 12 additions & 8 deletions examples/create-a-model-with-coordinates.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,14 @@
"source": [
"import pandas as pd\n",
"\n",
"time = pd.Index(range(10), name='time')\n",
"time = pd.Index(range(10), name=\"time\")\n",
"\n",
"x = m.add_variables(lower=0, coords=[time], name='x', )\n",
"y = m.add_variables(lower=0, coords=[time], name='y')"
"x = m.add_variables(\n",
" lower=0,\n",
" coords=[time],\n",
" name=\"x\",\n",
")\n",
"y = m.add_variables(lower=0, coords=[time], name=\"y\")"
]
},
{
Expand All @@ -97,7 +101,7 @@
"source": [
"factor = pd.Series(time, index=time)\n",
"\n",
"3*x + 7*y >= 10*factor"
"3 * x + 7 * y >= 10 * factor"
]
},
{
Expand All @@ -115,8 +119,8 @@
"metadata": {},
"outputs": [],
"source": [
"con1 = m.add_constraints(3*x + 7*y >= 10*factor, name='con1')\n",
"con2 = m.add_constraints(5*x + 2*y >= 3*factor, name='con2')\n",
"con1 = m.add_constraints(3 * x + 7 * y >= 10 * factor, name=\"con1\")\n",
"con2 = m.add_constraints(5 * x + 2 * y >= 3 * factor, name=\"con2\")\n",
"m"
]
},
Expand All @@ -135,7 +139,7 @@
"metadata": {},
"outputs": [],
"source": [
"obj = (x + 2*y).sum()\n",
"obj = (x + 2 * y).sum()\n",
"m.add_objective(obj)"
]
},
Expand Down Expand Up @@ -164,7 +168,7 @@
"metadata": {},
"outputs": [],
"source": [
"m.solution.to_dataframe().plot(grid=True, ylabel='Optimal Value');"
"m.solution.to_dataframe().plot(grid=True, ylabel=\"Optimal Value\");"
]
},
{
Expand Down
14 changes: 7 additions & 7 deletions examples/create-a-model.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@
"metadata": {},
"outputs": [],
"source": [
"x = m.add_variables(lower=0, name='x')\n",
"y = m.add_variables(lower=0, name='y');"
"x = m.add_variables(lower=0, name=\"x\")\n",
"y = m.add_variables(lower=0, name=\"y\");"
]
},
{
Expand Down Expand Up @@ -132,7 +132,7 @@
"metadata": {},
"outputs": [],
"source": [
"3*x + 7*y >= 10"
"3 * x + 7 * y >= 10"
]
},
{
Expand All @@ -151,7 +151,7 @@
"metadata": {},
"outputs": [],
"source": [
"3*x + 7*y - 10 >= 0"
"3 * x + 7 * y - 10 >= 0"
]
},
{
Expand All @@ -172,8 +172,8 @@
"metadata": {},
"outputs": [],
"source": [
"m.add_constraints(3*x + 7*y >= 10)\n",
"m.add_constraints(5*x + 2*y >= 3);"
"m.add_constraints(3 * x + 7 * y >= 10)\n",
"m.add_constraints(5 * x + 2 * y >= 3);"
]
},
{
Expand All @@ -194,7 +194,7 @@
"metadata": {},
"outputs": [],
"source": [
"m.add_objective(x + 2*y)"
"m.add_objective(x + 2 * y)"
]
},
{
Expand Down
9 changes: 4 additions & 5 deletions examples/creating-constraints.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"metadata": {},
"outputs": [],
"source": [
"\n",
"from linopy import Model\n",
"\n",
"m = Model()"
Expand Down Expand Up @@ -56,7 +55,7 @@
"metadata": {},
"outputs": [],
"source": [
"x = m.add_variables(name='x')"
"x = m.add_variables(name=\"x\")"
]
},
{
Expand Down Expand Up @@ -121,7 +120,7 @@
"metadata": {},
"outputs": [],
"source": [
"c = m.add_constraints(con, name='my-constraint')\n",
"c = m.add_constraints(con, name=\"my-constraint\")\n",
"c"
]
},
Expand All @@ -140,7 +139,7 @@
"metadata": {},
"outputs": [],
"source": [
"m.add_constraints(3 * x <= 10, name='the-same-constraint')"
"m.add_constraints(3 * x <= 10, name=\"the-same-constraint\")"
]
},
{
Expand Down Expand Up @@ -230,7 +229,7 @@
"metadata": {},
"outputs": [],
"source": [
"m.constraints['my-constraint']"
"m.constraints[\"my-constraint\"]"
]
}
],
Expand Down
12 changes: 6 additions & 6 deletions examples/creating-expressions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@
"\n",
"import linopy\n",
"\n",
"time = pd.Index(range(10), name='time')\n",
"port = pd.Index(list('abcd'), name='port')\n",
"time = pd.Index(range(10), name=\"time\")\n",
"port = pd.Index(list(\"abcd\"), name=\"port\")\n",
"\n",
"m = linopy.Model()\n",
"x = m.add_variables(lower=0, coords=[time], name='x')\n",
"y = m.add_variables(lower=0, coords=[time, port], name='y')\n",
"x = m.add_variables(lower=0, coords=[time], name=\"x\")\n",
"y = m.add_variables(lower=0, coords=[time, port], name=\"y\")\n",
"m"
]
},
Expand Down Expand Up @@ -172,8 +172,8 @@
"metadata": {},
"outputs": [],
"source": [
"other_time = pd.Index(range(10, 20), name='time')\n",
"b = m.add_variables(coords=[other_time], name='b')\n",
"other_time = pd.Index(range(10, 20), name=\"time\")\n",
"b = m.add_variables(coords=[other_time], name=\"b\")\n",
"b"
]
},
Expand Down
Loading

0 comments on commit cff0360

Please sign in to comment.