Rolling horizon: option to pin storage SoC at window seams

Offen
#1,997 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 2 Tagen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Anfängerfreundlichkeit
35/100
Issue-Typ
Feature
Klarheit
Größtenteils klar
Aktivitätsstatus
Aktiv
Tech-Stack
python
Bereich
backend

Rechercherichtung

Start with optimize_with_rolling_horizon() in abstract.py and read the existing rolling-horizon example and water-value example (#1492). The issue describes the desired seam calculation, option behavior, and prototype tests, but asks whether the feature belongs in the API and whether to wait for related changes (#1973, #1987, #1934). Confirm that direction with maintainers before implementing; done means seam SoC is pinned while overlap remains free and existing settings are restored even if a solve raises.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

Note: AI-assisted. Claims about the current behaviour and the prototype were machine-checked: the upstream code was read at e74a67ee, and the numbers below come from running the prototype branch with HiGHS.

Describe the feature you'd like to see

optimize_with_rolling_horizon() has no foresight past the end of a window. When a window is shorter than the natural storage cycle, energy left in storage at the end of the window has no value to the LP, so it tends to discharge it. The next window then starts with storage that is too low.

The water-value example (#1492) fixes this by giving the store a time-varying marginal_cost taken from a perfect-foresight run. That works well, but it needs the perfect-foresight run first, which is exactly what rolling horizon is meant to avoid on large models.

I'd like a cheaper option: fix the state of charge at each window seam to a fraction of capacity. Every window then behaves as a closed cycle that ends where the next one starts.

n.optimize.optimize_with_rolling_horizon(
    horizon=24, overlap=6, pin_terminal_soc=True, boundary_soc=0.5
)

The pin goes on the last snapshot a window commits (start + horizon - overlap - 1), not on the last snapshot of the window, so the overlap stays free as lookahead. It uses the existing state_of_charge_set and e_set, temporarily switches off cyclic_state_of_charge / e_cyclic, and restores both flags and set points after the run, also when a solve raises.

Users can do this today by computing the seams themselves and filling e_set, but it's easy to get wrong with overlap > 0. My own first version pinned the window end instead of the seam, and the store still drained at every seam.

I have a working prototype with tests on my fork: MaykThewessen/PyPSA@feat/rolling-horizon-closed-cycle (+112/-27 lines in abstract.py, plus tests).

Two questions before I open a PR:

  1. Is this something you want in optimize_with_rolling_horizon(), or would you rather see it as a short recipe in the rolling-horizon example next to the water values?
  2. If it goes in, should I wait until #1973 / #1987 land? Both change the same function. I also see #1934 moving storage to Store, so I could restrict it to stores only if that fits the plan better.
Prototype details (AI-generated summary)
  • boundary_soc is a float in [0, 1], applied as a fraction of p_nom * max_hours (StorageUnit) or e_nom (Store).
  • Existing user set points in state_of_charge_set / e_set are kept; the frames are reindexed, not rebuilt.
  • Probe with horizon 8, overlap 3, 24 snapshots and one 10 MW / 4 h battery against a sinusoidal price: with the pin on the window end instead of the seam, SoC at the seams (snapshots 4, 9, 14, 19) was 0, 30, 30, 0 MWh; with seam pinning it is 20 MWh (50 %) at each.
  • Tests: pin holds at the seams for overlap 0 and 3, with StorageUnit and Store alone and together; user set points survive; flags and set points are restored after success and after a raised solve; out-of-range boundary_soc raises.
Vorherrschende Sprache
Python
Sterne
2.2k
Forks
732
Ø Merge
3 T. 59 Min.
Gemergte PRs (30 T.)
58

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus PyPSA/PyPSA

Alle Issues in PyPSA/PyPSA

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.