[codex] Fix load polynomial cost signs#3036
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #3036 +/- ##
===========================================
- Coverage 71.98% 71.98% -0.01%
===========================================
Files 352 352
Lines 38591 38590 -1
===========================================
- Hits 27779 27778 -1
Misses 10812 10812 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| signs = array([-1 if element in ["load", "storage", "dcline"] else 1 for element in cost.et]) | ||
| if is_quadratic: | ||
| c2 = cost["cp2_eur_per_mw2"] | ||
| c2 = cost["cp2_eur_per_mw2"].values |
There was a problem hiding this comment.
.values should not be used.
https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.values.html
There was a problem hiding this comment.
Fixed in the rebased branch: the new code uses .to_numpy() for the OPF cost coefficient arrays instead of .values.
There was a problem hiding this comment.
Follow-up: I expanded the cleanup before pushing again, so _fill_gencost_poly() now uses .to_numpy() for the active and reactive polynomial cost coefficient arrays (cp* and cq*). The focused OPF and converter tests still pass locally.
|
Hi @Kkkakania , thanks for the PR. But since this convention is in pandapower already a long time, I first want to check other OPF tools. pypower is only one of many possible, and I would not prefer to break all the others just for pypower. |
a753e99 to
b434044
Compare
|
Rebased onto the current develop branch, so the PR no longer has merge conflicts. The earlier scipy-stubs pin change is no longer part of this branch because develop already includes the upstream dependency update.\n\nLocal checks after the rebase:\n\n- uv run pytest pandapower/test/opf/test_costs_pol.py::test_controllable_load_polynomial_cost_signs pandapower/test/opf/test_pandamodels_converter.py::test_controllable_load_polynomial_cost_signs_for_powermodels -q\n- uv run pytest pandapower/test/opf/test_costs_pol.py -q\n- uv run pytest pandapower/test/opf/test_pandamodels_converter.py -q\n\nOn the backend-compatibility concern: the remaining patch keeps the sign convention limited to the generated OPF cost coefficients. The added tests cover both the PYPOWER conversion path and the PowerModels converter output. The intended behavior is that controllable load active power uses the opposite sign for the linear term, while the constant and quadratic coefficients stay in the user-provided cost convention. If the preferred project policy is to keep the historical coefficient convention for compatibility, I can narrow this further to a documentation/test-only change instead of changing the generated coefficients. |
d51542c to
02f5382
Compare
|
Added a focused reactive polynomial-cost regression test for the PYPOWER q-cost rows. This covers the Fresh local checks:
I also checked the failing |
02f5382 to
d15df89
Compare
|
I trimmed the implementation diff to keep this PR focused on the coefficient sign behavior only. The Fresh local checks after the force-push:
This should also make the patch easier for Codecov to evaluate. |
|



Summary
This fixes the polynomial active-power cost conversion for controllable loads and other elements that are represented with the opposite active-power sign in PYPOWER.
For a controllable load, pandapower cost coefficients describe the load-side power
P, while PYPOWER represents it with-P. The transformed polynomial should therefore be:a * (-P)^2 + b * (-P) + c = a * P^2 - b * P + cSo only the linear active-power coefficient changes sign. The quadratic and constant terms should keep their original signs.
Changes
cp2_eur_per_mw2unchanged when fillinggencost.cp0_eurunchanged for both quadratic and linear polynomial costs.cp1_eur_per_mw.gencostlayouts.scipy-stubsbelow1.18for the typing extra, because the current1.18stubs use Python 3.12typestatement syntax whilemypy.iniintentionally checks withpython_version = 3.10.Fixes #2954.
Validation
python -m pytest pandapower/test/opf/test_costs_pol.py -qpython -m pytest pandapower/test/opf/test_costs_mixed.py pandapower/test/opf/test_basic.py::test_storage_opf pandapower/test/opf/test_dcline.py -qpython -m mypygit diff --checkRemote checks after the second push:
tutorial_warnings_tests.warnings (3.14, *)jobs fail with the samepandapower/test/plotting/test_geo.py/tap_dependency_tableDeprecationWarningthat is present on the currentdevelopworkflow run. I verified this againstdeveloprun27626832854, job81693439589.