Skip to content

Commit 5b36589

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 0007fad commit 5b36589

1 file changed

Lines changed: 14 additions & 9 deletions

File tree

benchmark/scripts/benchmark_matrix_gen.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ def build_synthetic(n: int):
9797

9898

9999
def build_solve_synthetic(n_snapshots: int, n_components: int):
100-
"""Return a linopy Model sized like a realistic energy-system dispatch problem.
100+
"""
101+
Return a linopy Model sized like a realistic energy-system dispatch problem.
101102
102103
This model is designed to exercise the solution-unpacking path benchmarked
103104
by PR #619. It uses two 2-D variable arrays (snapshot × component) with
@@ -222,7 +223,8 @@ def do_full():
222223

223224

224225
def benchmark_solve(model, solver_name: str = "highs", repeats: int = 3) -> list[dict]:
225-
"""Benchmark the solve + solution-unpacking path on a linopy Model.
226+
"""
227+
Benchmark the solve + solution-unpacking path on a linopy Model.
226228
227229
PR #619 replaces an iterative Python loop (one xarray assignment per
228230
variable label) with a single vectorised numpy gather. This function
@@ -267,6 +269,7 @@ def _timed_run(h):
267269
# Also patch it in the linopy.solvers module namespace that Highs._solve
268270
# already has a reference to — use the module-level name via the module.
269271
import linopy.solvers as _sol_module
272+
270273
_sol_module._run_highs_with_keyboard_interrupt = _timed_run
271274

272275
try:
@@ -390,7 +393,8 @@ def run_benchmarks(model_type: str, quick: bool, repeats: int) -> list[dict]:
390393

391394

392395
def run_solve_benchmarks(quick: bool, repeats: int, solver_name: str) -> list[dict]:
393-
"""Run solve + solution-unpacking benchmarks; return flat list of results.
396+
"""
397+
Run solve + solution-unpacking benchmarks; return flat list of results.
394398
395399
Uses a pure-linopy synthetic model (no PyPSA required) sized to approximate
396400
a realistic energy-system dispatch LP.
@@ -402,8 +406,8 @@ def run_solve_benchmarks(quick: bool, repeats: int, solver_name: str) -> list[di
402406
sizes = SOLVE_SIZES_QUICK if quick else SOLVE_SIZES_FULL
403407

404408
for n_snap, n_comp in sizes:
405-
n_vars_total = 2 * n_snap * n_comp # p + s arrays
406-
n_cons_total = n_snap # one balance constraint per snapshot
409+
n_vars_total = 2 * n_snap * n_comp # p + s arrays
410+
n_cons_total = n_snap # one balance constraint per snapshot
407411

408412
print(f"\n{'=' * 60}")
409413
print(f"Solve benchmark T={n_snap}, C={n_comp}")
@@ -412,8 +416,10 @@ def run_solve_benchmarks(quick: bool, repeats: int, solver_name: str) -> list[di
412416
print(f"{'=' * 60}")
413417

414418
model = build_solve_synthetic(n_snap, n_comp)
415-
print(f" {len(model.variables.flat):,} variable labels, "
416-
f"{len(model.constraints.flat):,} constraint labels")
419+
print(
420+
f" {len(model.variables.flat):,} variable labels, "
421+
f"{len(model.constraints.flat):,} constraint labels"
422+
)
417423

418424
for r in benchmark_solve(model, solver_name=solver_name, repeats=repeats):
419425
r.update(
@@ -462,8 +468,7 @@ def format_comparison(before: list[dict], after: list[dict]) -> str:
462468
def main():
463469
parser = argparse.ArgumentParser(
464470
description=(
465-
"Benchmark linopy matrix generation and solution unpacking "
466-
"(PRs #616–#619)"
471+
"Benchmark linopy matrix generation and solution unpacking (PRs #616–#619)"
467472
)
468473
)
469474
parser.add_argument(

0 commit comments

Comments
 (0)