Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix stand_by_cost implementation in optimization #793

Merged
merged 4 commits into from
Dec 3, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ Upcoming Release

* Enhancement: Allow optimising dispatch of only a subset of investment periods.

* Bugfix: Fix stand-by-costs optimization, which now works with linopy and native.

PyPSA 0.25.2 (30th September 2023)
==================================

Expand Down
2 changes: 1 addition & 1 deletion pypsa/optimization/optimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def define_objective(n, sns):
)
stand_by_cost.columns.name = f"{c}-com"
status = n.model.variables[f"{c}-status"].loc[:, stand_by_cost.columns]
m.objective = m.objective + (status * stand_by_cost).sum()
objective.append((status * stand_by_cost).sum())

# investment
for c, attr in nominal_attrs.items():
Expand Down
8 changes: 6 additions & 2 deletions test/test_stand_by_cost.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
import numpy as np
import pandas as pd
import pytest
from conftest import SUPPORTED_APIS, optimize
from conftest import optimize
from numpy.testing import assert_array_almost_equal as equal

import pypsa

SUPPORTED_APIS_STAND_BY_COST = ["linopy", "native"]

@pytest.mark.parametrize("api", SUPPORTED_APIS)

@pytest.mark.parametrize("api", SUPPORTED_APIS_STAND_BY_COST)
def test_stand_by_cost(api):
cfvescovo marked this conversation as resolved.
Show resolved Hide resolved
"""
This test is based on https://pypsa.readthedocs.io/en/latest/examples/unit-
Expand Down Expand Up @@ -58,3 +60,5 @@ def test_stand_by_cost(api):
expected_cost = np.array([80000, 120000, 100000, 56010], dtype=float).T

equal(cost.sum(1), expected_cost)

equal(sum(expected_cost), n.objective)