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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repos:
- id: mixed-line-ending
- id: check-case-conflict
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.12.0 # must match uv.lock
rev: v0.12.1 # must match uv.lock
hooks:
- id: ruff
- id: ruff-format
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ tests = [
"networkx>=3.2.1",
"geopandas>=1.0.0",
"pandapower>=3.1.2",
"types-networkx>=3.4.2",
]
dev = [
"ruff>=0.9.2",
Expand Down
4 changes: 3 additions & 1 deletion stubs/pandapower-stubs/estimation/algorithm/base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ from _typeshed import Incomplete

from pandapower.estimation.ppc_conversion import ExtendedPPCI

__all__ = ["WLSAlgorithm", "WLSZeroInjectionConstraintsAlgorithm", "IRWLSAlgorithm"]

class BaseAlgorithm:
tolerance: Incomplete
max_iterations: Incomplete
Expand All @@ -23,7 +25,7 @@ class WLSAlgorithm(BaseAlgorithm):
H: Incomplete
hx: Incomplete
def __init__(self, tolerance, maximum_iterations, logger=...) -> None: ...
def estimate(self, eppci: ExtendedPPCI, **kwargs): ...
def estimate(self, eppci: ExtendedPPCI, debug_mode: bool = False, **kwargs): ...

class WLSZeroInjectionConstraintsAlgorithm(BaseAlgorithm):
def estimate(self, eppci: ExtendedPPCI, **kwargs): ...
Expand Down
2 changes: 2 additions & 0 deletions stubs/pandapower-stubs/estimation/algorithm/matrix_base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ from _typeshed import Incomplete

from pandapower.estimation.ppc_conversion import ExtendedPPCI

__all__ = ["BaseAlgebra", "BaseAlgebraZeroInjConstraints"]

class BaseAlgebra:
eppci: Incomplete
fb: Incomplete
Expand Down
52 changes: 27 additions & 25 deletions stubs/pandapower-stubs/estimation/idx_brch.pyi
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
IM_FROM: int
IM_FROM_STD: int
IM_TO: int
IM_TO_STD: int
P_FROM: int
P_FROM_STD: int
P_TO: int
P_TO_STD: int
Q_FROM: int
Q_FROM_STD: int
Q_TO: int
Q_TO_STD: int
IM_FROM_IDX: int
P_FROM_IDX: int
Q_FROM_IDX: int
IM_TO_IDX: int
P_TO_IDX: int
Q_TO_IDX: int
IA_FROM: int
IA_FROM_STD: int
IA_TO: int
IA_TO_STD: int
IA_FROM_IDX: int
IA_TO_IDX: int
branch_cols_se: int
from typing import Final

IM_FROM: Final = 0
IM_FROM_STD: Final = 1
IM_TO: Final = 2
IM_TO_STD: Final = 3
P_FROM: Final = 4
P_FROM_STD: Final = 5
P_TO: Final = 6
P_TO_STD: Final = 7
Q_FROM: Final = 8
Q_FROM_STD: Final = 9
Q_TO: Final = 10
Q_TO_STD: Final = 11
IM_FROM_IDX: Final = 12
P_FROM_IDX: Final = 13
Q_FROM_IDX: Final = 14
IM_TO_IDX: Final = 15
P_TO_IDX: Final = 16
Q_TO_IDX: Final = 17
IA_FROM: Final = 18
IA_FROM_STD: Final = 19
IA_TO: Final = 20
IA_TO_STD: Final = 21
IA_FROM_IDX: Final = 22
IA_TO_IDX: Final = 23
branch_cols_se: Final = 24
30 changes: 16 additions & 14 deletions stubs/pandapower-stubs/estimation/idx_bus.pyi
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
VM: int
VM_STD: int
P: int
P_STD: int
Q: int
Q_STD: int
VM_IDX: int
P_IDX: int
Q_IDX: int
ZERO_INJ_FLAG: int
VA: int
VA_STD: int
VA_IDX: int
bus_cols_se: int
from typing import Final

VM: Final = 0
VM_STD: Final = 1
P: Final = 2
P_STD: Final = 3
Q: Final = 4
Q_STD: Final = 5
VM_IDX: Final = 6
P_IDX: Final = 7
Q_IDX: Final = 8
ZERO_INJ_FLAG: Final = 9
VA: Final = 10
VA_STD: Final = 11
VA_IDX: Final = 12
bus_cols_se: Final = 13
81 changes: 48 additions & 33 deletions stubs/pandapower-stubs/estimation/ppc_conversion.pyi
Original file line number Diff line number Diff line change
@@ -1,46 +1,61 @@
from _typeshed import Incomplete
from collections import UserDict
from collections.abc import Collection
from typing import (
Any,
Any as csr_matrix, # scipy.sparse.csr_matrix
Literal,
)

import numpy as np

from pandapower._typing import Array1D, Array2D
from pandapower.auxiliary import pandapowerNet

ZERO_INJECTION_STD_DEV: float
BR_SIDE: Incomplete
BR_MEAS_PPCI_IX: Incomplete
BUS_MEAS_PPCI_IX: Incomplete
BR_SIDE: dict[str, dict[str, str]]
BR_MEAS_PPCI_IX: dict[tuple[str, str], dict[str, int]]
BUS_MEAS_PPCI_IX: dict[str, dict[str, int]]

def pp2eppci(
net,
v_start: Incomplete | None = None,
delta_start: Incomplete | None = None,
net: pandapowerNet,
v_start: Collection[float] | str | None = None,
delta_start: Collection[float] | str | None = None,
calculate_voltage_angles: bool = True,
zero_injection: str = "aux_bus",
ppc: Incomplete | None = None,
eppci: Incomplete | None = None,
): ...
algorithm: str = "wls",
ppc: dict[str, Any] | None = None,
eppci: ExtendedPPCI | None = None,
) -> tuple[pandapowerNet, dict[str, Any] | None, ExtendedPPCI]: ...

class ExtendedPPCI(UserDict[str, Incomplete]):
data: Incomplete
z: Incomplete
r_cov: Incomplete
pp_meas_indices: Incomplete
non_nan_meas_mask: Incomplete
non_nan_meas_selector: Incomplete
class ExtendedPPCI(UserDict[str, Any]):
data: dict[str, Any]
algorithm: Literal["wls", "wls_with_zero_constraint", "opt", "irwls", "lp", "af-wls"]
z: Array2D[np.float64] | None
r_cov: Array2D[np.float64] | None
pp_meas_indices: Array2D[np.int64] | None
non_nan_meas_mask: dict[str, Array1D[np.int64]] | None
non_nan_meas_selector: Array1D[np.int64] | None
idx_non_imeas: Array1D[np.int64] | None
any_i_meas: bool
any_degree_meas: bool
non_slack_buses: Incomplete
non_slack_bus_mask: Incomplete
num_non_slack_bus: Incomplete
delta_v_bus_mask: Incomplete
delta_v_bus_selector: Incomplete
v_init: Incomplete
delta_init: Incomplete
E_init: Incomplete
v: Incomplete
delta: Incomplete
E: Incomplete
def __init__(self, ppci) -> None: ...
non_slack_buses: Array1D[np.int64]
non_slack_bus_mask: Array1D[np.bool]
num_non_slack_bus: np.int64
delta_v_bus_mask: Array1D[np.bool]
delta_v_bus_selector: Array1D[np.int64]
v_init: Array1D[np.float64]
delta_init: Array1D[np.float64]
E_init: Array1D[np.float64]
v: Array1D[np.float64]
delta: Array1D[np.float64]
E: Array1D[np.float64]
def __init__(
self, ppci: dict[str, Any], algorithm: Literal["wls", "wls_with_zero_constraint", "opt", "irwls", "lp", "af-wls"]
) -> None: ...
def update_meas(self) -> None: ...
@property
def V(self): ...
def V(self) -> Array1D[np.complex128]: ...
def reset(self) -> None: ...
def update_E(self, E) -> None: ...
def E2V(self, E): ...
def get_Y(self): ...
def update_E(self, E: Array1D[np.float64]) -> None: ...
def E2V(self, E: Array1D[np.float64]) -> Array1D[np.complex128]: ...
def get_Y(self) -> tuple[csr_matrix, csr_matrix, csr_matrix]: ...
5 changes: 4 additions & 1 deletion stubs/pandapower-stubs/estimation/results.pyi
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
def eppci2pp(net, ppc, eppci): ...
from pandapower.auxiliary import pandapowerNet
from pandapower.estimation.ppc_conversion import ExtendedPPCI

def eppci2pp(net: pandapowerNet, ppc, eppci: ExtendedPPCI) -> pandapowerNet: ...
121 changes: 83 additions & 38 deletions stubs/pandapower-stubs/estimation/state_estimation.pyi
Original file line number Diff line number Diff line change
@@ -1,73 +1,118 @@
from _typeshed import Incomplete
import logging
from collections.abc import Collection
from typing import Any, Literal, overload

ALGORITHM_MAPPING: Incomplete
ALLOWED_OPT_VAR: Incomplete
from pandapower.auxiliary import pandapowerNet
from pandapower.estimation.algorithm.base import BaseAlgorithm

ALGORITHM_MAPPING: dict[str, type[BaseAlgorithm]]
ALLOWED_OPT_VAR: set[str]

@overload
def estimate(
net,
algorithm: str = "wls",
init: str = "flat",
net: pandapowerNet,
algorithm: Literal["wls", "af-wls"] = "wls",
init: Literal["flat", "results", "slack"] = "flat",
tolerance: float = 1e-06,
maximum_iterations: int = 10,
calculate_voltage_angles: bool = True,
zero_injection: str = "aux_bus",
fuse_buses_with_bb_switch: str = "all",
maximum_iterations: int = 50,
zero_injection: Collection[int] | str = "aux_bus",
fuse_buses_with_bb_switch: Collection[int] | Literal["all"] = "all",
debug_mode: bool = False,
**opt_vars,
): ...
) -> dict[str, Any]: ...
@overload
def estimate(
net: pandapowerNet,
algorithm: Literal["wls_with_zero_constraint", "opt", "irwls", "lp"],
init: Literal["flat", "results", "slack"] = "flat",
tolerance: float = 1e-06,
maximum_iterations: int = 50,
zero_injection: Collection[int] | str = "aux_bus",
fuse_buses_with_bb_switch: Collection[int] | Literal["all"] = "all",
debug_mode: bool = False,
**opt_vars,
) -> bool: ...
def remove_bad_data(
net,
init: str = "flat",
net: pandapowerNet,
init: Literal["flat", "results", "slack"] = "flat",
tolerance: float = 1e-06,
maximum_iterations: int = 10,
calculate_voltage_angles: bool = True,
rn_max_threshold: float = 3.0,
): ...
) -> bool: ...
def chi2_analysis(
net,
init: str = "flat",
tolerance: float = 1e-06,
maximum_iterations: int = 10,
calculate_voltage_angles: bool = True,
chi2_prob_false: float = 0.05,
): ...
) -> bool | None: ...

class StateEstimation:
net: Incomplete
solver: Incomplete
ppc: Incomplete
eppci: Incomplete
recycle: Incomplete
delta: Incomplete
bad_data_present: Incomplete
logger: logging.Logger
net: pandapowerNet
solver: BaseAlgorithm
ppc: dict[str, Any] | None
eppci: dict[str, Any] | None
recycle: bool
algorithm: Literal["wls", "wls_with_zero_constraint", "opt", "irwls", "lp", "af-wls"]
delta: None # not currently used
bad_data_present: bool | None
def __init__(
self,
net,
net: pandapowerNet,
tolerance: float = 1e-06,
maximum_iterations: int = 10,
algorithm: str = "wls",
logger: Incomplete | None = None,
maximum_iterations: int = 50,
algorithm: Literal["wls", "wls_with_zero_constraint", "opt", "irwls", "lp", "af-wls"] = "wls",
logger: logging.Logger | None = None,
recycle: bool = False,
) -> None: ...
@overload
def estimate(
self,
v_start: str = "flat",
delta_start: str = "flat",
calculate_voltage_angles: bool = True,
zero_injection: Incomplete | None = None,
fuse_buses_with_bb_switch: str = "all",
v_start: Collection[float] | str = "flat",
delta_start: Collection[float] | str = "flat",
zero_injection: Collection[int] | str | None = None,
fuse_buses_with_bb_switch: Collection[int] | Literal["all"] = "all",
algorithm: Literal["wls", "af-wls"] = "wls",
debug_mode: bool = False,
**opt_vars,
) -> dict[str, Any]: ...
@overload # algorithm positional
def estimate(
self,
v_start: Collection[float] | str,
delta_start: Collection[float] | str,
zero_injection: Collection[int] | str | None,
fuse_buses_with_bb_switch: Collection[int] | Literal["all"],
algorithm: Literal["wls_with_zero_constraint", "opt", "irwls", "lp"],
debug_mode: bool = False,
**opt_vars,
) -> bool: ...
@overload # algorithm keyword
def estimate(
self,
v_start: Collection[float] | str = "flat",
delta_start: Collection[float] | str = "flat",
zero_injection: Collection[int] | str | None = None,
fuse_buses_with_bb_switch: Collection[int] | Literal["all"] = "all",
*,
algorithm: Literal["wls_with_zero_constraint", "opt", "irwls", "lp"],
debug_mode: bool = False,
**opt_vars,
): ...
) -> bool: ...
def perform_chi2_test(
self,
v_in_out: Incomplete | None = None,
delta_in_out: Incomplete | None = None,
v_in_out: Collection[float] | str | None = None,
delta_in_out: Collection[float] | str | None = None,
calculate_voltage_angles: bool = True,
chi2_prob_false: float = 0.05,
): ...
) -> bool | None: ...
def perform_rn_max_test(
self,
v_in_out: Incomplete | None = None,
delta_in_out: Incomplete | None = None,
v_in_out: Collection[float] | str | None = None,
delta_in_out: Collection[float] | str | None = None,
calculate_voltage_angles: bool = True,
rn_max_threshold: float = 3.0,
): ...
) -> bool: ...
Loading