Skip to content

Commit

Permalink
Many fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Geoffroy Jamgotchian <geoffroy.jamgotchian@rte-france.com>
  • Loading branch information
geofjamg committed Jan 10, 2024
1 parent e042543 commit ceaeece
Show file tree
Hide file tree
Showing 19 changed files with 39 additions and 55 deletions.
1 change: 0 additions & 1 deletion cpp/src/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ void voltageInitializerBinding(py::module_& m) {
m.def("voltage_initializer_add_specific_low_voltage_limits", &pypowsybl::voltageInitializerAddSpecificLowVoltageLimits, py::arg("params_handle"), py::arg("voltage_level_id"), py::arg("is_relative"), py::arg("limit"));
m.def("voltage_initializer_add_specific_high_voltage_limits", &pypowsybl::voltageInitializerAddSpecificHighVoltageLimits, py::arg("params_handle"), py::arg("voltage_level_id"), py::arg("is_relative"), py::arg("limit"));

m.def("voltage_initializer_add_algorithm_param", &pypowsybl::voltageInitializerAddAlgorithmParam, py::arg("params_handle"), py::arg("key_ptr"), py::arg("value_ptr"));
m.def("voltage_initializer_set_objective", &pypowsybl::voltageInitializerSetObjective, py::arg("params_handle"), py::arg("c_objective"));
m.def("voltage_initializer_set_objective_distance", &pypowsybl::voltageInitializerSetObjectiveDistance, py::arg("params_handle"), py::arg("dist"));
m.def("run_voltage_initializer", &pypowsybl::runVoltageInitializer, py::arg("debug"), py::arg("network_handle"), py::arg("params_handle"));
Expand Down
4 changes: 0 additions & 4 deletions cpp/src/pypowsybl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1517,10 +1517,6 @@ void voltageInitializerAddVariableTwoWindingsTransformers(const JavaHandle& para
pypowsybl::callJava(::voltageInitializerAddVariableTwoWindingsTransformers, paramsHandle, (char*) idPtr.c_str());
}

void voltageInitializerAddAlgorithmParam(const JavaHandle& paramsHandle, const std::string& keyPtr, const std::string& valuePtr) {
pypowsybl::callJava(::voltageInitializerAddAlgorithmParam, paramsHandle, (char*) keyPtr.c_str(), (char*) valuePtr.c_str());
}

void voltageInitializerSetObjective(const JavaHandle& paramsHandle, VoltageInitializerObjective cObjective) {
pypowsybl::callJava(::voltageInitializerSetObjective, paramsHandle, cObjective);
}
Expand Down
1 change: 0 additions & 1 deletion cpp/src/pypowsybl.h
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,6 @@ void voltageInitializerAddSpecificHighVoltageLimits(const JavaHandle& paramsHand
void voltageInitializerAddVariableShuntCompensators(const JavaHandle& paramsHandle, const std::string& idPtr);
void voltageInitializerAddConstantQGenerators(const JavaHandle& paramsHandle, const std::string& idPtr);
void voltageInitializerAddVariableTwoWindingsTransformers(const JavaHandle& paramsHandle, const std::string& idPtr);
void voltageInitializerAddAlgorithmParam(const JavaHandle& paramsHandle, const std::string& keyPtr, const std::string& valuePtr);
void voltageInitializerSetObjective(const JavaHandle& paramsHandle, VoltageInitializerObjective cObjective);
void voltageInitializerSetObjectiveDistance(const JavaHandle& paramsHandle, double dist);
void voltageInitializerApplyAllModifications(const JavaHandle& resultHandle, const JavaHandle& networkHandle);
Expand Down
1 change: 0 additions & 1 deletion docs/reference/voltage_initializer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ VoltageInitializerParameters : How to parameterize the tool
VoltageInitializerParameters.add_variable_two_windings_transformers
VoltageInitializerParameters.add_specific_low_voltage_limits
VoltageInitializerParameters.add_specific_high_voltage_limits
VoltageInitializerParameters.add_algorithm_param
VoltageInitializerParameters.set_objective
VoltageInitializerParameters.set_objective_distance

Expand Down
4 changes: 2 additions & 2 deletions docs/user_guide/network.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ The supported formats are the following:
.. doctest::

>>> pp.network.get_import_formats()
['CGMES', 'MATPOWER', 'IEEE-CDF', 'PSS/E', 'UCTE', 'XIIDM', 'POWER-FACTORY']
['CGMES', 'JIIDM', 'MATPOWER', 'IEEE-CDF', 'PSS/E', 'UCTE', 'XIIDM', 'POWER-FACTORY']

.. Note::

Expand Down Expand Up @@ -87,7 +87,7 @@ The supported formats are:
.. doctest::

>>> pp.network.get_export_formats()
['AMPL', 'CGMES', 'MATPOWER', 'PSS/E', 'UCTE', 'XIIDM']
['AMPL', 'CGMES', 'JIIDM', 'MATPOWER', 'PSS/E', 'UCTE', 'XIIDM']

.. Note::

Expand Down
6 changes: 3 additions & 3 deletions docs/user_guide/security.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ the violations created by the contingency, they are collected by contingency in
>>> result.limit_violations
subject_name limit_type limit_name limit acceptable_duration limit_reduction value side
contingency_id subject_id
NHV1_NHV2_1 CURRENT 500.0 2147483647 1.0 623.568946 ONE
NHV1_NHV2_2 CURRENT 500.0 2147483647 1.0 655.409876 TWO
NHV1_NHV2_1 CURRENT permanent 500.0 2147483647 1.0 623.568946 ONE
NHV1_NHV2_2 CURRENT permanent 500.0 2147483647 1.0 655.409876 TWO
VLHV1 LOW_VOLTAGE 400.0 2147483647 1.0 398.917401
First contingency NHV1_NHV2_2 CURRENT 20' 1200.0 60 1.0 1438.021676 ONE
NHV1_NHV2_2 CURRENT 500.0 2147483647 1.0 1477.824335 TWO
NHV1_NHV2_2 CURRENT permanent 500.0 2147483647 1.0 1477.824335 TWO
VLHV1 LOW_VOLTAGE 400.0 2147483647 1.0 392.158685


Expand Down
1 change: 0 additions & 1 deletion docs/user_guide/voltage_initializer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ Here is a simple starting example:
some_2wt_id = n.get_2_windings_transformers().iloc[0].name
params.add_variable_two_windings_transformers([some_2wt_id])
params.add_algorithm_param({"foo": "bar", "bar": "bar2"})
params.set_objective(VoltageInitializerObjective.SPECIFIC_VOLTAGE_PROFILE)
results = v_init.run(n, params)
Expand Down
2 changes: 1 addition & 1 deletion java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
<mapdb.version>3.0.8</mapdb.version>
<maven-dependency-plugin.version>3.6.0</maven-dependency-plugin.version>
<powsybl-dependencies.version>2023.4.0</powsybl-dependencies.version>
<powsybl-open-reac.version>0.3.0</powsybl-open-reac.version>
<powsybl-open-reac.version>0.5.0</powsybl-open-reac.version>
<zstdjni.version>1.5.5-3</zstdjni.version>
</properties>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,6 @@ public static void addVariableTwoWindingsTransformers(IsolateThread thread, Obje
doCatch(exceptionHandlerPtr, () -> params.addVariableTwoWindingsTransformers(List.of(id)));
}

@CEntryPoint(name = "voltageInitializerAddAlgorithmParam")
public static void addAlgorithmParam(IsolateThread thread, ObjectHandle paramsHandle, CCharPointer keyPtr,
CCharPointer valuePtr, PyPowsyblApiHeader.ExceptionHandlerPointer exceptionHandlerPtr) {
OpenReacParameters params = ObjectHandles.getGlobal().get(paramsHandle);
doCatch(exceptionHandlerPtr,
() -> params.addAlgorithmParam(CTypeUtil.toString(keyPtr), CTypeUtil.toString(valuePtr)));
}

@CEntryPoint(name = "voltageInitializerSetObjective")
public static void setObjective(IsolateThread thread, ObjectHandle paramsHandle,
VoltageInitializerObjective cObjective, PyPowsyblApiHeader.ExceptionHandlerPointer exceptionHandlerPtr) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
[
{
"name":"com.powsybl.math.MathException",
"methods":[{"name":"<init>","parameterTypes":["java.lang.String"] }]
},
{
"name":"com.powsybl.math.solver.KinsolContext",
"methods":[{"name":"logError","parameterTypes":["int","java.lang.String","java.lang.String","java.lang.String"] }, {"name":"logInfo","parameterTypes":["java.lang.String","java.lang.String","java.lang.String"] }, {"name":"updateFunc","parameterTypes":["double[]"] }, {"name":"updateJac","parameterTypes":[] }]
},
{
"name":"com.powsybl.math.solver.KinsolResult",
"methods":[{"name":"<init>","parameterTypes":["int","long"] }]
},
{
"name":"com.powsybl.math.matrix.SparseMatrix",
"methods":[{"name":"<init>","parameterTypes":["int","int","int[]","int[]","double[]"] }]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"includes":[
{"pattern":"\\Qnatives/linux_64/libmath.so\\E"},
{"pattern":"\\Qnatives/osx_64/libmath.dylib\\E"},
{"pattern":"\\Qnatives/osx_arm64/libmath.dylib\\E"},
{"pattern":"\\Qnatives/windows_64/math.dll\\E"}
]}
}
4 changes: 0 additions & 4 deletions pypowsybl/_pypowsybl.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -756,10 +756,6 @@ def voltage_initializer_add_specific_low_voltage_limits(
def voltage_initializer_add_specific_high_voltage_limits(
params_handle: JavaHandle, voltage_level_id: str, is_relative: bool, limit: float) -> None: ...

def voltage_initializer_add_algorithm_param(
params_handle: JavaHandle, key_ptr: str, value_ptr: str) -> None: ...


def voltage_initializer_set_objective(
params_handle: JavaHandle, objective: VoltageInitializerObjective) -> None: ...

Expand Down
11 changes: 0 additions & 11 deletions pypowsybl/voltage_initializer/impl/voltage_initializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
voltage_initializer_add_variable_two_windings_transformers,
voltage_initializer_add_specific_low_voltage_limits,
voltage_initializer_add_specific_high_voltage_limits,
voltage_initializer_add_algorithm_param,
VoltageInitializerObjective,
voltage_initializer_set_objective,
voltage_initializer_set_objective_distance,
Expand Down Expand Up @@ -109,16 +108,6 @@ def add_specific_voltage_limits(self, limits: Dict[str, Tuple[float, float]]) ->
self.add_specific_low_voltage_limits([(key, True, limits[key][0])])
self.add_specific_high_voltage_limits([(key, True, limits[key][1])])

def add_algorithm_param(self, parameters_dict: Dict[str, str]) -> None:
'''
Add list of entries to VoltageInitializer. Danger zone as it tweaks the model directly.
Args:
parameters_dict: algorithm params are stored as (key, values) like a dict
'''
for key in parameters_dict:
voltage_initializer_add_algorithm_param(self._handle, key, parameters_dict[key])

def set_objective(self, objective: VoltageInitializerObjective) -> None:
'''
If you use BETWEEN_HIGH_AND_LOW_VOLTAGE_LIMIT, you also need to call :func:`~VoltageInitializerParameters.set_objective_distance`.
Expand Down
4 changes: 2 additions & 2 deletions tests/battery.xiidm
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
<iidm:load id="LOAD" loadType="UNDEFINED" p0="600.0" q0="200.0" bus="NBAT" connectableBus="NBAT"/>
</iidm:voltageLevel>
</iidm:substation>
<iidm:line id="NHV1_NHV2_1" r="3.0" x="33.0" g1="0.0" b1="1.93E-4" g2="0.0" b2="1.93E-4" bus1="NGEN" connectableBus1="NGEN" voltageLevelId1="VLGEN" bus2="NBAT" connectableBus2="NBAT" voltageLevelId2="VLBAT"/>
<iidm:line id="NHV1_NHV2_2" r="3.0" x="33.0" g1="0.0" b1="1.93E-4" g2="0.0" b2="1.93E-4" bus1="NGEN" connectableBus1="NGEN" voltageLevelId1="VLGEN" bus2="NBAT" connectableBus2="NBAT" voltageLevelId2="VLBAT"/>
<iidm:line id="NHV1_NHV2_1" r="3.0" x="33.0" g1="0.0" b1="1.93E-4" g2="0.0" b2="1.93E-4" voltageLevelId1="VLGEN" bus1="NGEN" connectableBus1="NGEN" voltageLevelId2="VLBAT" bus2="NBAT" connectableBus2="NBAT"/>
<iidm:line id="NHV1_NHV2_2" r="3.0" x="33.0" g1="0.0" b1="1.93E-4" g2="0.0" b2="1.93E-4" voltageLevelId1="VLGEN" bus1="NGEN" connectableBus1="NGEN" voltageLevelId2="VLBAT" bus2="NBAT" connectableBus2="NBAT"/>
</iidm:network>
6 changes: 4 additions & 2 deletions tests/test_loadflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,15 @@ def test_get_provider_parameters_names():
'linePerUnitMode',
'useLoadModel',
'dcApproximationType',
'simulateAutomationSystems'
'simulateAutomationSystems',
'maxNewtonKrylovIterations',
'newtonKrylovLineSearch'
]


def test_get_provider_parameters():
specific_parameters = pp.loadflow.get_provider_parameters('OpenLoadFlow')
assert 56 == len(specific_parameters)
assert 58 == len(specific_parameters)
assert 'Slack bus selection mode' == specific_parameters['description']['slackBusSelectionMode']
assert 'STRING' == specific_parameters['type']['slackBusSelectionMode']
assert 'MOST_MESHED' == specific_parameters['default']['slackBusSelectionMode']
Expand Down
3 changes: 2 additions & 1 deletion tests/test_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ def test_save_ampl():
'ampl_network_substations.txt', 'ampl_network_tct.txt', 'ampl_network_loads.txt',
'ampl_network_lcc_converter_stations.txt', 'ampl_network_static_var_compensators.txt',
'ampl_network_hvdc.txt', 'ampl_network_limits.txt', 'ampl_network_shunts.txt',
'ampl_network_batteries.txt', 'ampl_network_ptc.txt', 'ampl_network_buses.txt']
'ampl_network_batteries.txt', 'ampl_network_ptc.txt', 'ampl_network_buses.txt',
'ampl_headers.txt']
assert len(file_names) == len(file_names_expected)
for file_name in file_names:
assert file_name in file_names_expected
Expand Down
16 changes: 8 additions & 8 deletions tests/test_network_modification.py
Original file line number Diff line number Diff line change
Expand Up @@ -673,10 +673,10 @@ def test_create_coupling_device():
])
pp.network.create_coupling_device(n, coupling_device)
switches = n.get_switches()
assert len(switches.index) == 7
assert len(switches[switches["kind"] == "DISCONNECTOR"].index) == 6
assert len(switches.index) == 5
assert len(switches[switches["kind"] == "DISCONNECTOR"].index) == 4
assert len(switches[switches["kind"] == "BREAKER"].index) == 1
assert len(switches[switches["open"] == True].index) == 4
assert len(switches[switches["open"] == True].index) == 2
assert len(switches[switches["open"] == False].index) == 3


Expand All @@ -696,10 +696,10 @@ def test_create_coupling_device_kwargs():
assert len(n.get_switches().index) == 0
pp.network.create_coupling_device(n, bus_or_busbar_section_id_1='BBS1', bus_or_busbar_section_id_2='BBS2', switch_prefix_id='sw')
switches = n.get_switches()
assert len(switches.index) == 7
assert len(switches[switches["kind"] == "DISCONNECTOR"].index) == 6
assert len(switches.index) == 5
assert len(switches[switches["kind"] == "DISCONNECTOR"].index) == 4
assert len(switches[switches["kind"] == "BREAKER"].index) == 1
assert len(switches[switches["open"] == True].index) == 4
assert len(switches[switches["open"] == True].index) == 2
assert len(switches[switches["open"] == False].index) == 3


Expand Down Expand Up @@ -730,9 +730,9 @@ def test_remove_feeder_bay():
pp.network.create_line_bays(n, df)
assert 'new_line' in n.get_lines().index
assert 'new_line1_BREAKER' in n.get_switches().index
assert 'new_line1_DISCONNECTOR' in n.get_switches().index
assert 'new_line1_DISCONNECTOR_25_0' in n.get_switches().index
assert 'new_line2_BREAKER' in n.get_switches().index
assert 'new_line2_DISCONNECTOR' in n.get_switches().index
assert 'new_line2_DISCONNECTOR_8_0' in n.get_switches().index
pp.network.remove_feeder_bays(n, 'new_line')
assert 'new_line1_BREAKER' not in n.get_switches().index
assert 'new_line1_DISCONNECTOR' not in n.get_switches().index
Expand Down
8 changes: 4 additions & 4 deletions tests/test_security_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def test_ac_security_analysis():
columns=['contingency_id', 'subject_id', 'subject_name', 'limit_type', 'limit_name',
'limit', 'acceptable_duration', 'limit_reduction', 'value', 'side'],
data=[
['First contingency', 'NHV1_NHV2_2', '', 'CURRENT', '', 500, 2147483647, 1, 1047.825769, 'TWO'],
['First contingency', 'NHV1_NHV2_2', '', 'CURRENT', 'permanent', 500, 2147483647, 1, 1047.825769, 'TWO'],
['First contingency', 'VLHV1', '', 'LOW_VOLTAGE', '', 400, 2147483647, 1, 398.264725, ''],
])
pd.testing.assert_frame_equal(expected, sa_result.limit_violations, check_dtype=False)
Expand Down Expand Up @@ -207,8 +207,8 @@ def test_security_analysis_parameters():
index=['contingency_id', 'subject_id'],
columns=['contingency_id', 'subject_id', 'subject_name', 'limit_type', 'limit_name',
'limit', 'acceptable_duration', 'limit_reduction', 'value', 'side'],
data=[['', 'NHV1_NHV2_1', '', 'CURRENT', '', 400, 2147483647, 1, 456.77, 'ONE'],
['First contingency', 'NHV1_NHV2_1', '', 'CURRENT', '', 400, 2147483647, 1, 1008.93, 'ONE'],
data=[['', 'NHV1_NHV2_1', '', 'CURRENT', 'permanent', 400, 2147483647, 1, 456.77, 'ONE'],
['First contingency', 'NHV1_NHV2_1', '', 'CURRENT', 'permanent', 400, 2147483647, 1, 1008.93, 'ONE'],
['First contingency', 'VLHV1', '', 'LOW_VOLTAGE', '', 400, 2147483647, 1, 398.26, '']])
pd.testing.assert_frame_equal(expected, result.limit_violations, check_dtype=False, atol=1e-2)

Expand All @@ -220,7 +220,7 @@ def test_security_analysis_parameters():
index=['contingency_id', 'subject_id'],
columns=['contingency_id', 'subject_id', 'subject_name', 'limit_type', 'limit_name',
'limit', 'acceptable_duration', 'limit_reduction', 'value', 'side'],
data=[['', 'NHV1_NHV2_1', '', 'CURRENT', '', 400, 2147483647, 1, 456.77, 'ONE'],
data=[['', 'NHV1_NHV2_1', '', 'CURRENT', 'permanent', 400, 2147483647, 1, 456.77, 'ONE'],
['First contingency', 'VLHV1', '', 'LOW_VOLTAGE', '', 400, 2147483647, 1, 398.26, '']])
pd.testing.assert_frame_equal(expected, result.limit_violations, check_dtype=False, atol=1e-2)

Expand Down
1 change: 0 additions & 1 deletion tests/test_voltage_initializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ def test_parameters():
params.add_constant_q_generators(["gen1", "gen2"])
params.add_variable_two_windings_transformers(["twt1", "twt2"])

params.add_algorithm_param({"foo": "bar", "bar": "bar2"})
params.add_specific_voltage_limits({"vl_id": (0.5, 1.2)})

params.add_specific_low_voltage_limits([("vl_id", True, 0.5)])
Expand Down

0 comments on commit ceaeece

Please sign in to comment.