Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix ComponentMode change + complete build
Signed-off-by: Hugo KULESZA <hugo.kulesza@rte-france.com>
  • Loading branch information
HugoKulesza committed Dec 17, 2025
commit cc70421aad07aa47d20080c3b61af08403c9b473
6 changes: 6 additions & 0 deletions cpp/powsybl-cpp/powsybl-cpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,12 @@ enum BalanceType {
PROPORTIONAL_TO_CONFORM_LOAD,
};

enum ComponentMode {
MAIN_CONNECTED = 0,
ALL_CONNECTED,
MAIN_SYNCHRONOUS,
};

enum ConnectedComponentMode {
MAIN = 0,
ALL,
Expand Down
5 changes: 5 additions & 0 deletions cpp/pypowsybl-cpp/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,11 @@ PYBIND11_MODULE(_pypowsybl, m) {
.value("ALL", pypowsybl::ConnectedComponentMode::ALL, "Run on all connected components")
.value("MAIN", pypowsybl::ConnectedComponentMode::MAIN, "Run only on the main connected component");

py::enum_<pypowsybl::ComponentMode>(m, "ComponentMode", "Define which network components to run on.")
.value("ALL_CONNECTED", pypowsybl::ComponentMode::ALL_CONNECTED, "Run on all connected components")
.value("MAIN_CONNECTED", pypowsybl::ComponentMode::MAIN_CONNECTED, "Run only on the main connected component")
.value("MAIN_SYNCHRONOUS", pypowsybl::ComponentMode::MAIN_SYNCHRONOUS, "Run only on the main synchronous component");

py::class_<array_struct, std::shared_ptr<array_struct>>(m, "ArrayStruct")
.def(py::init());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1242,9 +1242,10 @@ public static SldParameters convertSldParameters(SldParametersPointer sldParamet
.setActivePowerUnit(CTypeUtil.toString(sldParametersPtr.getActivePowerUnit()))
.setReactivePowerUnit(CTypeUtil.toString(sldParametersPtr.getReactivePowerUnit()))
.setCurrentUnit(CTypeUtil.toString(sldParametersPtr.getCurrentUnit()));
boolean displayCurrentInfo = sldParametersPtr.isDisplayCurrentFeederInfo();
sldParameters.setLabelProviderFactory((n, s, layoutParameters, svgParameters) -> {
com.powsybl.sld.svg.DefaultLabelProvider provider = new com.powsybl.sld.svg.DefaultLabelProvider(n, s, layoutParameters, svgParameters);
provider.setDisplayCurrent(sldParametersPtr.isDisplayCurrentFeederInfo());
provider.setDisplayCurrent(displayCurrentInfo);
return provider;
});

Expand All @@ -1270,13 +1271,17 @@ public static NadParameters convertNadParameters(NadParametersPointer nadParamet
.setCurrentValuePrecision(nadParametersPointer.getCurrentValuePrecision())
.setAngleValuePrecision(nadParametersPointer.getAngleValuePrecision())
.setVoltageValuePrecision(nadParametersPointer.getVoltageValuePrecision());
EdgeInfoEnum middleInfo = nadParametersPointer.isEdgeNameDisplayed() ? NAME : EMPTY;
boolean idDisplayed = nadParametersPointer.isIdDisplayed();
boolean busLegend = nadParametersPointer.isBusLegend();
boolean substationDescription = nadParametersPointer.isSubstationDescriptionDisplayed();
nadParameters.setLabelProviderFactory((n, s) -> new DefaultLabelProvider(n,
new EdgeInfoParameters(edgeInfo, nadParametersPointer.isEdgeNameDisplayed() ? NAME : EMPTY, EMPTY, EMPTY),
new EdgeInfoParameters(edgeInfo, middleInfo, EMPTY, EMPTY),
s.createValueFormatter(),
new LabelProviderParameters()
.setIdDisplayed(nadParametersPointer.isIdDisplayed())
.setBusLegend(nadParametersPointer.isBusLegend())
.setSubstationDescriptionDisplayed(nadParametersPointer.isSubstationDescriptionDisplayed())));
.setIdDisplayed(idDisplayed)
.setBusLegend(busLegend)
.setSubstationDescriptionDisplayed(substationDescription)));
nadParameters.getLayoutParameters()
.setInjectionsAdded(nadParametersPointer.isInjectionsAdded());
return nadParameters;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ void testStateMonitors() {
BranchResult branchResult = result.getPreContingencyResult().getNetworkResult().getBranchResults().get(0);
var eps = Offset.offset(1e-12);
assertThat(branchResult.getP1()).isCloseTo(302.44404914466014, eps);
assertThat(branchResult.getQ1()).isCloseTo(98.74027438014933, eps);
assertThat(branchResult.getI1()).isCloseTo(456.7689759899916, eps);
assertThat(branchResult.getQ1()).isCloseTo(98.74027438015084, eps);
assertThat(branchResult.getI1()).isCloseTo(456.7689759899928, eps);
assertThat(branchResult.getP2()).isCloseTo(-300.43389523337316, eps);
assertThat(branchResult.getQ2()).isCloseTo(-137.18849307164064, eps);
assertThat(branchResult.getI2()).isCloseTo(488.99279636727357, eps);
assertThat(branchResult.getQ2()).isCloseTo(-137.18849307164206, eps);
assertThat(branchResult.getI2()).isCloseTo(488.9927963672751, eps);
assertThat(result.getPostContingencyResults()).hasSize(1);
assertThat(result.getPreContingencyResult().getNetworkResult().getBranchResults()).hasSize(1);
branchResult = result.getPostContingencyResults().get(0).getNetworkResult().getBranchResults().get(0);
Expand Down
2 changes: 1 addition & 1 deletion pypowsybl/_pypowsybl.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class ComponentMode:
__members__: ClassVar[Dict[str, ComponentMode]] = ... # read-only
ALL_CONNECTED: ClassVar[ComponentMode] = ...
MAIN_CONNECTED: ClassVar[ComponentMode] = ...
MAIN_SYCNHRONOUS: ClassVar[ComponentMode] = ...
MAIN_SYNCHRONOUS: ClassVar[ComponentMode] = ...
def __init__(self, arg0: int) -> None: ...
def __eq__(self, arg0: object) -> bool: ...
def __getstate__(self) -> int: ...
Expand Down
28 changes: 21 additions & 7 deletions pypowsybl/loadflow/impl/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
ComponentMode.__module__ = __name__

import pypowsybl._pypowsybl
from pypowsybl.loadflow.impl.util import _convert_to_component_mode, _convert_to_connected_component_mode


class Parameters: # pylint: disable=too-few-public-methods
Expand Down Expand Up @@ -125,8 +124,8 @@ def __init__(self, voltage_init_mode: Optional[VoltageInitMode] = None,
if component_mode is not None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe an exception if we set both of them ?

self.component_mode = component_mode
if connected_component_mode is not None:
warnings.deprecated("connected_component_mode is deprecated, use component_mode parameter instead")
self.component_mode = _convert_to_component_mode(connected_component_mode)
warnings.warn("connected_component_mode is deprecated, use component_mode parameter instead", DeprecationWarning)
self._convert_to_component_mode(connected_component_mode)
if hvdc_ac_emulation is not None:
self.hvdc_ac_emulation = hvdc_ac_emulation
if dc_power_factor is not None:
Expand Down Expand Up @@ -179,13 +178,28 @@ def _to_c_parameters(self) -> LoadFlowParameters:

@property
def connected_component_mode(self) -> Optional[ConnectedComponentMode]:
warnings.deprecated("connected_component_mode is deprecated, use component_mode parameter instead")
return _convert_to_connected_component_mode(self.component_mode)
warnings.warn("connected_component_mode is deprecated, use component_mode parameter instead", DeprecationWarning)
return self._convert_to_connected_component_mode()

@connected_component_mode.setter
def connected_component_mode(self, connected_component_mode: ConnectedComponentMode) -> None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ConnectedComponentMode class should also be flagged deprecated ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not found a good way to do it (the class is declared in the bindings in cpp not in python)...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

warnings.deprecated("connected_component_mode is deprecated, use component_mode parameter instead")
self.component_mode = _convert_to_component_mode(connected_component_mode)
warnings.warn("connected_component_mode is deprecated, use component_mode parameter instead", DeprecationWarning)
self._convert_to_component_mode(connected_component_mode)

def _convert_to_component_mode(self, connected_component_mode: ConnectedComponentMode) -> ComponentMode:
if connected_component_mode == ConnectedComponentMode.MAIN:
self.component_mode = ComponentMode.MAIN_CONNECTED
else:
self.component_mode = ComponentMode.ALL_CONNECTED

@staticmethod
def _convert_to_connected_component_mode(self) -> Optional[ConnectedComponentMode]:
if self.component_mode == ComponentMode.MAIN_CONNECTED:
return ConnectedComponentMode.MAIN
elif self.component_mode == ComponentMode.ALL_CONNECTED:
return ConnectedComponentMode.ALL
else:
return None

@staticmethod
def from_json(json_str: str) -> "Parameters":
Expand Down
18 changes: 0 additions & 18 deletions pypowsybl/loadflow/impl/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# SPDX-License-Identifier: MPL-2.0
#
from typing import Optional

from pypowsybl import _pypowsybl
from pypowsybl._pypowsybl import ConnectedComponentMode, ComponentMode

from .parameters import Parameters


Expand All @@ -19,17 +15,3 @@ def parameters_from_c(c_parameters: _pypowsybl.LoadFlowParameters) -> Parameters
res = Parameters.__new__(Parameters)
res._init_from_c(c_parameters) # pylint: disable=protected-access
return res

def _convert_to_component_mode(connected_component_mode: ConnectedComponentMode) -> ComponentMode:
if connected_component_mode == ConnectedComponentMode.MAIN:
return ComponentMode.MAIN_CONNECTED
else:
return ComponentMode.ALL_CONNECTED

def _convert_to_connected_component_mode(component_mode: ComponentMode) -> Optional[ConnectedComponentMode]:
if component_mode == ComponentMode.MAIN_CONNECTED:
return ConnectedComponentMode.MAIN
elif component_mode == ComponentMode.ALL_CONNECTED:
return ConnectedComponentMode.ALL
else:
return None
2 changes: 1 addition & 1 deletion tests/test_loadflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def test_lf_parameters():
'balance_type': [lf.BalanceType.PROPORTIONAL_TO_CONFORM_LOAD, lf.BalanceType.PROPORTIONAL_TO_GENERATION_P],
'dc_use_transformer_ratio': [True, False],
'countries_to_balance': [['FR'], ['BE']],
'component_mode': [lf.ComponentMode.MAIN_CONNECTED, lf.ComponentMode.ALL_CONNECTED, lf.ComponentMode.MAIN_SYCNHRONOUS],
'component_mode': [lf.ComponentMode.MAIN_CONNECTED, lf.ComponentMode.ALL_CONNECTED, lf.ComponentMode.MAIN_SYNCHRONOUS],
'dc_power_factor': [1.0, 0.95]
}

Expand Down
Loading