Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions benchmarks/cli/introspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def _row(label: str, value: object) -> None:
_row("features:", sorted(spec.features))
_row("phases:", sorted(spec.phases))
_row("quick:", spec.quick_subset)
_row("long_threshold:", spec.long_threshold)
_row("long:", ", ".join(str(s) for s in spec.long_sizes) or "—")
if spec.requires:
_row("requires:", list(spec.requires))
return
Expand All @@ -106,7 +106,7 @@ def _row(label: str, value: object) -> None:
_row("description:", pattern.description)
_row("phases:", sorted(pattern.phases))
_row("quick:", pattern.quick_subset)
_row("long_threshold:", pattern.long_threshold)
_row("long:", ", ".join(str(s) for s in pattern.long_sizes) or "—")
if pattern.requires:
_row("requires:", list(pattern.requires))
return
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def run(
bool,
typer.Option(
"--long",
help="Include the slowest sizes (above each spec's long_threshold).",
help="Include the slowest sizes (each spec's long_sizes).",
),
] = False,
phase: Annotated[
Expand Down Expand Up @@ -136,7 +136,7 @@ def run(
them sequentially. Results print to the terminal; pass ``--json PATH``
to also save a snapshot (one rule for both metrics).

Without ``--quick``/``--long``, sizes above each spec's ``long_threshold``
Without ``--quick``/``--long``, each spec's ``long_sizes`` (the heaviest)
are skipped — keeps the wall-clock manageable. ``--size``/``--severity``
pin exact values on either axis.

Expand Down
4 changes: 2 additions & 2 deletions benchmarks/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def pytest_addoption(parser: pytest.Parser) -> None:
action="store_true",
default=False,
help=(
"Include the slowest sizes (above each spec's long_threshold). "
"Include the slowest sizes (each spec's long_sizes). "
"Default runs skip them."
),
)
Expand Down Expand Up @@ -86,7 +86,7 @@ def maybe_skip(request: pytest.FixtureRequest, spec: BenchSpec, size: int) -> No
- ``--size N`` / ``--severity S`` → run only the listed values for that
axis (models read ``--size``, patterns ``--severity``); overrides tiers.
- ``--quick`` → only ``spec.quick_subset``
- default (no flag) → skip ``size > long_threshold``
- default (no flag) → skip sizes in ``spec.long_sizes``
- ``--long`` → no size cap

A manual axis flag wins over ``--quick``/``--long``; ``--quick`` in turn
Expand Down
5 changes: 4 additions & 1 deletion benchmarks/models/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from benchmarks.registry import CONTINUOUS, ModelSpec, register

SIZES = (10, 50, 100, 250, 500, 1000, 1600)
QUICK_SIZES = (10, 250)
LONG_SIZES = (1000, 1600)


def build_basic(n: int) -> linopy.Model:
Expand All @@ -24,7 +26,8 @@ def build_basic(n: int) -> linopy.Model:
name="basic",
build=build_basic,
sizes=SIZES,
quick_sizes=QUICK_SIZES,
long_sizes=LONG_SIZES,
features=frozenset({CONTINUOUS}),
long_threshold=500,
)
)
5 changes: 4 additions & 1 deletion benchmarks/models/expression_arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from benchmarks.registry import CONTINUOUS, ModelSpec, register

SIZES = (10, 50, 100, 250, 500, 1000)
QUICK_SIZES = (10, 250)
LONG_SIZES = (1000,)


def build_expression_arithmetic(n: int) -> linopy.Model:
Expand Down Expand Up @@ -36,7 +38,8 @@ def build_expression_arithmetic(n: int) -> linopy.Model:
name="expression_arithmetic",
build=build_expression_arithmetic,
sizes=SIZES,
quick_sizes=QUICK_SIZES,
long_sizes=LONG_SIZES,
features=frozenset({CONTINUOUS}),
long_threshold=500,
)
)
5 changes: 4 additions & 1 deletion benchmarks/models/knapsack.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from benchmarks.registry import BINARY, DEFAULT_PHASES, ModelSpec, register

SIZES = (100, 1_000, 10_000, 100_000, 1_000_000)
QUICK_SIZES = (100, 10_000)
LONG_SIZES = (100_000, 1_000_000)


def build_knapsack(n: int) -> linopy.Model:
Expand All @@ -29,8 +31,9 @@ def build_knapsack(n: int) -> linopy.Model:
name="knapsack",
build=build_knapsack,
sizes=SIZES,
quick_sizes=QUICK_SIZES,
long_sizes=LONG_SIZES,
features=frozenset({BINARY}),
phases=DEFAULT_PHASES, # HiGHS handles binary; matrices handles MILP
long_threshold=10_000,
)
)
5 changes: 4 additions & 1 deletion benchmarks/models/masked.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
)

SIZES = (10, 50, 100, 500, 1000)
QUICK_SIZES = (10, 100)
LONG_SIZES = (1000,)


def build_masked(n: int) -> linopy.Model:
Expand Down Expand Up @@ -83,8 +85,9 @@ def build_masked(n: int) -> linopy.Model:
name="masked",
build=build_masked,
sizes=SIZES,
quick_sizes=QUICK_SIZES,
long_sizes=LONG_SIZES,
features=frozenset({CONTINUOUS, MASKED}),
phases=DEFAULT_PHASES,
long_threshold=500,
)
)
5 changes: 4 additions & 1 deletion benchmarks/models/milp.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
)

SIZES = (10, 25, 50, 100, 200)
QUICK_SIZES = (10, 50)
LONG_SIZES = (200,)


def build_milp(n: int) -> linopy.Model:
Expand Down Expand Up @@ -72,8 +74,9 @@ def build_milp(n: int) -> linopy.Model:
name="milp",
build=build_milp,
sizes=SIZES,
quick_sizes=QUICK_SIZES,
long_sizes=LONG_SIZES,
features=frozenset({INTEGER, CONTINUOUS}),
phases=DEFAULT_PHASES,
long_threshold=100,
)
)
5 changes: 4 additions & 1 deletion benchmarks/models/piecewise.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
)

SIZES = (10, 100, 1_000, 5_000)
QUICK_SIZES = (10, 1_000)
LONG_SIZES = (5_000,)

_API_AVAILABLE = hasattr(linopy.Model, "add_piecewise_formulation") and hasattr(
linopy, "EvolvingAPIWarning"
Expand Down Expand Up @@ -81,12 +83,13 @@ def build_piecewise(n_gens: int) -> linopy.Model:
name="piecewise",
build=build_piecewise,
sizes=SIZES,
quick_sizes=QUICK_SIZES,
long_sizes=LONG_SIZES,
features=frozenset({CONTINUOUS, PIECEWISE}),
# Monotonic breakpoints + ``method="auto"`` → incremental
# reformulation (pure MILP with binaries), which every supported
# solver handles.
phases=DEFAULT_PHASES,
long_threshold=1_000,
)
)
else:
Expand Down
9 changes: 4 additions & 5 deletions benchmarks/models/pypsa_scigrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import linopy

SIZES = (10, 50, 100, 200)
QUICK_SIZES = () # out of --quick entirely (PyPSA import dominates the smoke)
LONG_SIZES = (100, 200) # only the bigger networks under --long


def build_pypsa_scigrid(snapshots: int = 100) -> linopy.Model:
Expand All @@ -31,12 +33,9 @@ def build_pypsa_scigrid(snapshots: int = 100) -> linopy.Model:
name="pypsa_scigrid",
build=build_pypsa_scigrid,
sizes=SIZES,
quick_sizes=QUICK_SIZES,
long_sizes=LONG_SIZES,
features=frozenset({CONTINUOUS}),
# quick_sizes=() keeps pypsa_scigrid out of --quick entirely — PyPSA
# import + example loading dominates the smoke wall-clock otherwise.
# It still runs in default and --long modes.
quick_sizes=(),
long_threshold=50,
requires=("pypsa",),
)
)
5 changes: 4 additions & 1 deletion benchmarks/models/qp.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
)

SIZES = (10, 100, 1_000, 5_000, 20_000)
QUICK_SIZES = (10, 1_000)
LONG_SIZES = (5_000, 20_000)


def build_qp(n_assets: int) -> linopy.Model:
Expand Down Expand Up @@ -58,8 +60,9 @@ def build_qp(n_assets: int) -> linopy.Model:
name="qp",
build=build_qp,
sizes=SIZES,
quick_sizes=QUICK_SIZES,
long_sizes=LONG_SIZES,
features=frozenset({CONTINUOUS, QUADRATIC}),
phases=DEFAULT_PHASES,
long_threshold=1_000,
)
)
5 changes: 4 additions & 1 deletion benchmarks/models/sos.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
)

SIZES = (10, 100, 1_000, 10_000)
QUICK_SIZES = (10, 1_000)
LONG_SIZES = (10_000,)

_N_MODES = 5
_API_AVAILABLE = hasattr(linopy.Model, "add_sos_constraints")
Expand Down Expand Up @@ -78,6 +80,8 @@ def build_sos(n_gens: int) -> linopy.Model:
name="sos",
build=build_sos,
sizes=SIZES,
quick_sizes=QUICK_SIZES,
long_sizes=LONG_SIZES,
features=frozenset({CONTINUOUS, SOS}),
# HiGHS / Mosek lack native SOS in linopy — would need
# ``reformulate_sos=True``, which mutates the model and defeats
Expand All @@ -93,7 +97,6 @@ def build_sos(n_gens: int) -> linopy.Model:
TO_XPRESS,
}
),
long_threshold=1_000,
)
)
else:
Expand Down
5 changes: 4 additions & 1 deletion benchmarks/models/sparse_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from benchmarks.registry import CONTINUOUS, ModelSpec, register

SIZES = (10, 50, 100, 250, 500, 1000)
QUICK_SIZES = (10, 250)
LONG_SIZES = (1000,)


def build_sparse_network(n_buses: int) -> linopy.Model:
Expand Down Expand Up @@ -56,7 +58,8 @@ def build_sparse_network(n_buses: int) -> linopy.Model:
name="sparse_network",
build=build_sparse_network,
sizes=SIZES,
quick_sizes=QUICK_SIZES,
long_sizes=LONG_SIZES,
features=frozenset({CONTINUOUS}),
long_threshold=500,
)
)
5 changes: 4 additions & 1 deletion benchmarks/models/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
from benchmarks.registry import CONTINUOUS, ModelSpec, register

SIZES = (10, 50, 100, 250, 500, 1000)
QUICK_SIZES = (10, 250)
LONG_SIZES = (1000,)
N_TIME = 168
DECAY = 0.99
ETA = 0.95
Expand Down Expand Up @@ -49,8 +51,9 @@ def build_storage(n_storage: int) -> linopy.Model:
name="storage",
build=build_storage,
sizes=SIZES,
quick_sizes=QUICK_SIZES,
long_sizes=LONG_SIZES,
features=frozenset({CONTINUOUS}),
long_threshold=500,
description="storage SoC recursion via .shift() — bidiagonal intertemporal coupling",
)
)
Loading
Loading