PyPSA / PyPSA/PyPSA

Feature Request: Add distribute_slack support to Linear Power Flow (lpf())

Open
#1,767 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

AC power flow
Dominant language
Python
Stars
2.2k
Forks
699
Avg merge
2d 10h
Merged PRs (30d)
13

Description

Description
Currently, distributed slack is supported for the non-linear power flow (n.pf()) via the distribute_slack and slack_weights parameters. However, these parameters are nonexistent for linear power flow (n.lpf()).

If a network has an active power mismatch prior to running n.lpf(), the entire imbalance is absorbed by the single slack bus. This can produce unrealistic power flows radiating from a single node. While the original feature request for distributed slack (Issue #10) mentioned both lpf and pf, PR 107 only implemented it for the non-linear module. Currently, the only workaround for linear power flow is to manually calculate the system mismatch and adjust the generator p_set values before calling n.lpf(), a feature which can be added directly to the lpf() function through adding a distribute_slack and slack_weights parameters to the linear power flow functions, mimicking similar behavior found in pf().

Proposed Solution
Bring feature parity to n.lpf() by adding the distribute_slack (boolean) and slack_weights parameters to the linear power flow API, mimicking the behavior already present in n.pf().

  • Update the function signatures for n.lpf(), pypsa.pf.network_lpf(), and pypsa.pf.sub_network_lpf() to accept distribute_slack=False and slack_weights=None as default keyword arguments.
  • If distribute_slack=True, compute and allocate the total active power mismatch to the active power injections of generators based on the provided slack_weights (defaulting to proportional to p_set or p_nom, matching the n.pf() logic).
  • Proceed with the standard DC power flow calculation

All of this can be done manually outside of PyPSA, but adding it as a feature would streamline my workflow. Curious if others would find this feature valuable. I am happy to open a PR to implement the feature if so.

Thanks!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the existing distributed-slack behavior in n.pf() and the implementations of pypsa.pf.network_lpf() and pypsa.pf.sub_network_lpf(). Trace how the linear power-flow entry points handle active-power mismatch, then add matching keyword arguments and verify that weighted allocation and the standard DC calculation behave consistently with n.pf().

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend-api-design
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.