Skip to content

Commit

Permalink
Merge branch 'main' into add-new-shortcircuit-parameters-and-results
Browse files Browse the repository at this point in the history
  • Loading branch information
EtienneLt authored Jan 11, 2024
2 parents 3a488fb + 5af67a3 commit 7882f8f
Show file tree
Hide file tree
Showing 46 changed files with 412 additions and 181 deletions.
15 changes: 12 additions & 3 deletions .github/workflows/dev-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
manylinux_build:
name: Build linux ${{ matrix.python.name }} wheel
runs-on: ubuntu-latest
container: quay.io/pypa/manylinux2014_x86_64:2022-11-01-e47a7a6
container: quay.io/pypa/manylinux_2_24_x86_64:2022-12-26-0d38463
strategy:
matrix:
python:
Expand All @@ -23,7 +23,16 @@ jobs:

steps:
- name: Install Linux packages
run: yum install -y rh-maven33-maven zlib-devel.x86_64
run: |
echo "deb http://archive.debian.org/debian stretch main contrib non-free" > /etc/apt/sources.list
apt-get update
apt install -y wget
- name: Install Maven
run: |
wget https://dlcdn.apache.org/maven/maven-3/3.9.6/binaries/apache-maven-3.9.6-bin.tar.gz -P /tmp
tar xf /tmp/apache-maven-*.tar.gz -C /opt
echo /opt/apache-maven-3.9.6/bin >> $GITHUB_PATH
- name: Setup GraalVM
uses: graalvm/setup-graalvm@v1
Expand All @@ -45,7 +54,7 @@ jobs:

- name: Build wheel
run: |
scl enable rh-maven33 'python3 setup.py bdist_wheel'
python3 setup.py bdist_wheel
auditwheel repair dist/*.whl
- name: Install wheel
Expand Down
15 changes: 12 additions & 3 deletions .github/workflows/full-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
manylinux_build:
name: Build linux ${{ matrix.python.name }} wheel
runs-on: ubuntu-latest
container: quay.io/pypa/manylinux2014_x86_64:2022-11-01-e47a7a6
container: quay.io/pypa/manylinux_2_24_x86_64:2022-12-26-0d38463
strategy:
matrix:
python:
Expand All @@ -38,7 +38,16 @@ jobs:

steps:
- name: Install Linux packages
run: yum install -y rh-maven33-maven zlib-devel.x86_64
run: |
echo "deb http://archive.debian.org/debian stretch main contrib non-free" > /etc/apt/sources.list
apt-get update
apt install -y wget
- name: Install Maven
run: |
wget https://dlcdn.apache.org/maven/maven-3/3.9.6/binaries/apache-maven-3.9.6-bin.tar.gz -P /tmp
tar xf /tmp/apache-maven-*.tar.gz -C /opt
echo /opt/apache-maven-3.9.6/bin >> $GITHUB_PATH
- name: Setup GraalVM
uses: graalvm/setup-graalvm@v1
Expand All @@ -60,7 +69,7 @@ jobs:

- name: Build wheel
run: |
scl enable rh-maven33 'python3 setup.py bdist_wheel'
python3 setup.py bdist_wheel
auditwheel repair dist/*.whl
- name: Install wheel
Expand Down
11 changes: 9 additions & 2 deletions 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 Expand Up @@ -475,7 +474,15 @@ PYBIND11_MODULE(_pypowsybl, m) {

py::class_<pypowsybl::NadParameters>(m, "NadParameters")
.def(py::init(&pypowsybl::createNadParameters))
.def_readwrite("edge_name_displayed", &pypowsybl::NadParameters::edge_name_displayed);
.def_readwrite("edge_name_displayed", &pypowsybl::NadParameters::edge_name_displayed)
.def_readwrite("edge_info_along_edge", &pypowsybl::NadParameters::edge_info_along_edge)
.def_readwrite("power_value_precision", &pypowsybl::NadParameters::power_value_precision)
.def_readwrite("current_value_precision", &pypowsybl::NadParameters::current_value_precision)
.def_readwrite("angle_value_precision", &pypowsybl::NadParameters::angle_value_precision)
.def_readwrite("voltage_value_precision", &pypowsybl::NadParameters::voltage_value_precision)
.def_readwrite("id_displayed", &pypowsybl::NadParameters::id_displayed)
.def_readwrite("bus_legend", &pypowsybl::NadParameters::bus_legend)
.def_readwrite("substation_description_displayed", &pypowsybl::NadParameters::substation_description_displayed);

m.def("write_single_line_diagram_svg", &pypowsybl::writeSingleLineDiagramSvg, "Write single line diagram SVG",
py::arg("network"), py::arg("container_id"), py::arg("svg_file"), py::arg("metadata_file"), py::arg("sld_parameters"));
Expand Down
8 changes: 8 additions & 0 deletions cpp/src/pypowsybl-api.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,14 @@ typedef struct sld_parameters_struct {

typedef struct nad_parameters_struct {
unsigned char edge_name_displayed;
unsigned char edge_info_along_edge;
unsigned char id_displayed;
int power_value_precision;
int current_value_precision;
int angle_value_precision;
int voltage_value_precision;
unsigned char substation_description_displayed;
unsigned char bus_legend;
} nad_parameters;

typedef enum {
Expand Down
20 changes: 16 additions & 4 deletions cpp/src/pypowsybl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1252,6 +1252,14 @@ SldParameters::SldParameters(sld_parameters* src) {

NadParameters::NadParameters(nad_parameters* src) {
edge_name_displayed = (bool) src->edge_name_displayed;
edge_info_along_edge = (bool) src->edge_info_along_edge;
id_displayed = (bool) src->id_displayed;
power_value_precision = src->power_value_precision;
current_value_precision = src->current_value_precision;
angle_value_precision = src->angle_value_precision;
voltage_value_precision = src->voltage_value_precision;
substation_description_displayed = src->substation_description_displayed;
bus_legend = src->bus_legend;
}

void SldParameters::sld_to_c_struct(sld_parameters& res) const {
Expand All @@ -1266,6 +1274,14 @@ void SldParameters::sld_to_c_struct(sld_parameters& res) const {

void NadParameters::nad_to_c_struct(nad_parameters& res) const {
res.edge_name_displayed = (unsigned char) edge_name_displayed;
res.edge_info_along_edge = (unsigned char) edge_info_along_edge;
res.id_displayed = (unsigned char) id_displayed;
res.power_value_precision = power_value_precision;
res.current_value_precision = current_value_precision;
res.angle_value_precision = angle_value_precision;
res.voltage_value_precision = voltage_value_precision;
res.substation_description_displayed = substation_description_displayed;
res.bus_legend = bus_legend;
}

std::shared_ptr<sld_parameters> SldParameters::to_c_struct() const {
Expand Down Expand Up @@ -1517,10 +1533,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
9 changes: 8 additions & 1 deletion cpp/src/pypowsybl.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,14 @@ class NadParameters {
void nad_to_c_struct(nad_parameters& params) const;

bool edge_name_displayed;
bool edge_info_along_edge;
bool id_displayed;
int power_value_precision;
int current_value_precision;
int angle_value_precision;
int voltage_value_precision;
bool bus_legend;
bool substation_description_displayed;
};

char* copyStringToCharPtr(const std::string& str);
Expand Down Expand Up @@ -584,7 +592,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
17 changes: 17 additions & 0 deletions docs/user_guide/network_visualization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,23 @@ Note that similarly to single-line diagrams, a loadflow can be run before writin
>>> result = pp.loadflow.run_ac(network)
>>> network.write_network_area_diagram_svg('ieee9.svg')
Network-area diagrams can be customized through NadParameters :

.. code-block:: python
>>> network = pp.network.create_ieee14()
>>> nad = network.get_network_area_diagram('VL6', nad_parameters=NadParameters(edge_name_displayed=True, id_displayed=True, edge_info_along_edge=False, power_value_precision=1, angle_value_precision=0, current_value_precision=1, voltage_value_precision=0, bus_legend=False, substation_description_displayed=True))
- edge_name_displayed: if true, names along lines and transformer legs are displayed (default value false)
- id_displayed: if true, the equipment ids are displayed. If false, the equipment names are displayed (if a name is null, then the id is displayed) (default value false)
- edge_info_along_edge: if true, the edge information (P or Q values for example) is displayed alongside the edge. If false, the edge information is displayed perpendicularly to the edge (default value true)
- power_value_precision: number of digits after the decimal point for power values (default value 0)
- angle_value_precision: number of digits after the decimal point for angle values (default value 1)
- current_value_precision: number of digits after the decimal point for current values (default value 0)
- voltage_value_precision: number of digits after the decimal point for voltage values(default value 1)
- bus_legend: if true, angle and voltage values associated to a voltage level are displayed in a text box. If false, only the voltage level name is displayed (default value true)
- substation_description_displayed : if true, the substation name is added to the voltage level info on the diagram (default value false)
In order to get a list of the displayed voltage levels from an input voltage level (or an input list of voltage levels) and a depth:
.. code-block:: python
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
6 changes: 3 additions & 3 deletions java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@
<junit-jupiter.version>5.5.2</junit-jupiter.version>
<mapdb.version>3.0.8</mapdb.version>
<maven-dependency-plugin.version>3.6.0</maven-dependency-plugin.version>
<powsybl-dependencies.version>2023.3.2</powsybl-dependencies.version>
<powsybl-open-reac.version>0.3.0</powsybl-open-reac.version>
<powsybl-dependencies.version>2023.4.0</powsybl-dependencies.version>
<powsybl-open-reac.version>0.5.0</powsybl-open-reac.version>
<zstdjni.version>1.5.5-3</zstdjni.version>
</properties>

Expand Down Expand Up @@ -313,7 +313,7 @@
</dependency>
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-iidm-xml-converter</artifactId>
<artifactId>powsybl-iidm-serde</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import com.powsybl.dataframe.network.adders.SeriesUtils;
import com.powsybl.dataframe.update.StringSeries;
import com.powsybl.dataframe.update.UpdatingDataframe;
import com.powsybl.python.dynamic.DynamicModelMapper;
import com.powsybl.python.dynamic.PythonDynamicModelsSupplier;

/**
* @author Nicolas Pierre <nicolas.pierre@artelys.com>
Expand Down Expand Up @@ -50,13 +50,13 @@ public StringSeries getParameterSetId() {

@FunctionalInterface
protected interface AddBlackBoxToModelMapping {
void addToModel(DynamicModelMapper modelMapping, String staticId, String parameterSetId);
void addToModel(PythonDynamicModelsSupplier modelMapping, String staticId, String parameterSetId);
}

protected abstract AddBlackBoxToModelMapping getAddBlackBoxToModelMapping();

@Override
public void addElements(DynamicModelMapper modelMapping, UpdatingDataframe dataframe) {
public void addElements(PythonDynamicModelsSupplier modelMapping, UpdatingDataframe dataframe) {
BlackBoxSeries series = new BlackBoxSeries(dataframe);
AddBlackBoxToModelMapping adder = getAddBlackBoxToModelMapping();
for (int row = 0; row < dataframe.getRowCount(); row++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import com.powsybl.dataframe.update.UpdatingDataframe;
import com.powsybl.python.commons.PyPowsyblApiHeader;
import com.powsybl.python.commons.Util;
import com.powsybl.python.dynamic.DynamicModelMapper;
import com.powsybl.python.dynamic.PythonDynamicModelsSupplier;

/**
* @author Nicolas Pierre <nicolas.pierre@artelys.com>
Expand Down Expand Up @@ -59,7 +59,7 @@ public IntSeries getBranchSide() {
}

@Override
public void addElements(DynamicModelMapper modelMapping, UpdatingDataframe dataframe) {
public void addElements(PythonDynamicModelsSupplier modelMapping, UpdatingDataframe dataframe) {
CurrentLimitAutomatonSeries series = new CurrentLimitAutomatonSeries(dataframe);
for (int row = 0; row < dataframe.getRowCount(); row++) {
modelMapping.addCurrentLimitAutomaton(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import com.powsybl.dataframe.SeriesMetadata;
import com.powsybl.dataframe.update.UpdatingDataframe;
import com.powsybl.python.dynamic.DynamicModelMapper;
import com.powsybl.python.dynamic.PythonDynamicModelsSupplier;

import java.util.List;

Expand All @@ -28,6 +28,6 @@ public interface DynamicMappingAdder {
* The first dataframe is considered the "primary" dataframe, other dataframes
* can provide additional data.
*/
void addElements(DynamicModelMapper modelMapping, UpdatingDataframe dataframe);
void addElements(PythonDynamicModelsSupplier modelMapping, UpdatingDataframe dataframe);

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import com.powsybl.dataframe.network.adders.SeriesUtils;
import com.powsybl.dataframe.update.StringSeries;
import com.powsybl.dataframe.update.UpdatingDataframe;
import com.powsybl.python.dynamic.DynamicModelMapper;
import com.powsybl.python.dynamic.PythonDynamicModelsSupplier;

/**
* @author Nicolas Pierre <nicolas.pierre@artelys.com>
Expand Down Expand Up @@ -56,7 +56,7 @@ public StringSeries getGeneratorLib() {
}

@Override
public void addElements(DynamicModelMapper modelMapping, UpdatingDataframe dataframe) {
public void addElements(PythonDynamicModelsSupplier modelMapping, UpdatingDataframe dataframe) {
GeneratorSynchronousSeries series = new GeneratorSynchronousSeries(dataframe);
for (int row = 0; row < dataframe.getRowCount(); row++) {
modelMapping.addGeneratorSynchronous(series.getStaticId().get(row),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
*/
package com.powsybl.dataframe.loadflow.validation;

import com.powsybl.iidm.network.Branch;
import com.powsybl.iidm.network.StaticVarCompensator;
import com.powsybl.iidm.network.TwoSides;
import com.powsybl.iidm.network.util.TwtData;
import com.powsybl.loadflow.validation.io.ValidationWriter;

Expand Down Expand Up @@ -82,7 +82,7 @@ public void write(String shuntId, double q, double expectedQ, double p, int curr
}

@Override
public void write(String twtId, double error, double upIncrement, double downIncrement, double rho, double rhoPreviousStep, double rhoNextStep, int tapPosition, int lowTapPosition, int highTapPosition, double targetV, Branch.Side regulatedSide, double v, boolean connected, boolean mainComponent, boolean validated) throws IOException {
public void write(String twtId, double error, double upIncrement, double downIncrement, double rho, double rhoPreviousStep, double rhoNextStep, int tapPosition, int lowTapPosition, int highTapPosition, double targetV, TwoSides regulatedSide, double v, boolean connected, boolean mainComponent, boolean validated) throws IOException {
twtData.add(new TwtValidationData(twtId, error, upIncrement, downIncrement, rho, rhoPreviousStep, rhoNextStep, tapPosition, lowTapPosition, highTapPosition, targetV, regulatedSide, v, connected, mainComponent, validated));
}

Expand Down
Loading

0 comments on commit 7882f8f

Please sign in to comment.