Skip to content

Commit

Permalink
Merge branch 'main' into misc-minor-doc
Browse files Browse the repository at this point in the history
  • Loading branch information
jeandemanged authored Dec 17, 2024
2 parents 3c68f8d + d980e81 commit 984a78f
Show file tree
Hide file tree
Showing 27 changed files with 256 additions and 74 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/release-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
release:
types:
- created
- released

permissions:
contents: write
Expand Down Expand Up @@ -82,6 +83,12 @@ jobs:
name: darwin,
os: macos-13,
}
- {
name: darwin-arm64,
os: macos-14,
macosx_deployment_target: "11", # first arm64 version of macosx
bdist_wheel_args: "--plat-name macosx-11.0-arm64", # needed to avoid the wheel to be named -universal2
}
- {
name: windows,
os: windows-2022,
Expand Down
16 changes: 16 additions & 0 deletions .github/workflows/scripts/build_module.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

MODULE_NAME=$1
COMMAND=$2

echo "Building $MODULE_NAME..."
$COMMAND
BUILD_EXIT=$?

if [ $BUILD_EXIT -ne 0 ]; then
echo "$MODULE_NAME build FAILED" >> $BUILD_STATUS
else
echo "$MODULE_NAME build SUCCESS" >> $BUILD_STATUS
fi

exit $BUILD_EXIT
59 changes: 54 additions & 5 deletions .github/workflows/snapshot-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@ on:
schedule:
- cron: '0 3 * * *'

env:
BUILD_STATUS: ${{ github.workspace }}/build_status.txt

jobs:
build_pypowsybl:
name: Build ${{ matrix.config.name }} ${{ matrix.python.name }} wheel
runs-on: ${{ matrix.config.os }}
outputs:
build_status_output: ${{ steps.build_status_step.outputs.build_status_output }} #Output job with build_status.txt content created in Read Build Status step

strategy:
matrix:
config:
Expand Down Expand Up @@ -92,7 +98,8 @@ jobs:
run: mvn versions:set-property -Dproperty=powsybl-core.version -DnewVersion=${{ env.CORE_VERSION}} -DgenerateBackupPoms=false
working-directory: ./powsybl-open-loadflow
- name: Build LOADFLOW
run: mvn -batch-mode --no-transfer-progress clean install
continue-on-error: true
run: ${{ env.SCRIPTS_PATH }}/build_module.sh "LOADFLOW" "mvn -batch-mode --no-transfer-progress clean install"
working-directory: ./powsybl-open-loadflow
- name: Get LOADFLOW_VERSION
run: echo "LOADFLOW_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_ENV
Expand All @@ -111,7 +118,8 @@ jobs:
run: mvn versions:set-property -Dproperty=powsybl-core.version -DnewVersion=${{ env.CORE_VERSION}} -DgenerateBackupPoms=false
working-directory: ./powsybl-diagram
- name: Build DIAGRAM
run: mvn -batch-mode --no-transfer-progress clean install
continue-on-error: true
run: ${{ env.SCRIPTS_PATH }}/build_module.sh "DIAGRAM" "mvn -batch-mode --no-transfer-progress clean install"
working-directory: ./powsybl-diagram
- name: Get DIAGRAM_VERSION version
run: echo "DIAGRAM_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_ENV
Expand All @@ -132,7 +140,8 @@ jobs:
mvn versions:set-property -Dproperty=powsyblopenloadflow.version -DnewVersion=${{ env.LOADFLOW_VERSION}} -DgenerateBackupPoms=false
working-directory: ./powsybl-entsoe
- name: Build ENTSOE
run: mvn -batch-mode --no-transfer-progress clean install
continue-on-error: true
run: ${{ env.SCRIPTS_PATH }}/build_module.sh "ENTSOE" "mvn -batch-mode --no-transfer-progress clean install"
working-directory: ./powsybl-entsoe
- name: Get ENTSOE_VERSION
run: echo "ENTSOE_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_ENV
Expand All @@ -154,7 +163,8 @@ jobs:
mvn versions:set-property -Dproperty=powsybl.openloadflow.version -DnewVersion=${{ env.LOADFLOW_VERSION}} -DgenerateBackupPoms=false
working-directory: ./powsybl-openrao
- name: Build OPENRAO
run: mvn -batch-mode --no-transfer-progress clean install
continue-on-error: true
run: ${{ env.SCRIPTS_PATH }}/build_module.sh "OPENRAO" "mvn -batch-mode --no-transfer-progress clean install"
working-directory: ./powsybl-openrao
- name: Get OPENRAO_VERSION
run: echo "OPENRAO_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_ENV
Expand All @@ -173,7 +183,8 @@ jobs:
run: mvn versions:set-property -Dproperty=powsybl-core.version -DnewVersion=${{ env.CORE_VERSION}} -DgenerateBackupPoms=false
working-directory: ./powsybl-dynawo
- name: Build DYNAWO
run: mvn -batch-mode --no-transfer-progress clean install
continue-on-error: true
run: ${{ env.SCRIPTS_PATH }}/build_module.sh "DYNAWO" "mvn -batch-mode --no-transfer-progress clean install"
working-directory: ./powsybl-dynawo
- name: Get DYNAWO_VERSION
run: echo "DYNAWO_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_ENV
Expand Down Expand Up @@ -202,6 +213,7 @@ jobs:
working-directory: ./powsybl-dependencies

- name: Install powsybl-dependencies
continue-on-error: true
run: mvn -batch-mode --no-transfer-progress clean install
working-directory: ./powsybl-dependencies

Expand Down Expand Up @@ -238,3 +250,40 @@ jobs:
with:
name: pypowsybl-wheel-${{ matrix.config.name }}-${{ matrix.python.name }}
path: dist/*.whl

- name: Record Job Name
if: failure()
run: |
echo "Failed job : Build ${{ matrix.config.name }} ${{ matrix.python.name }} wheel" >> $BUILD_STATUS
- name: Read Build Status
if: always()
id: build_status_step
run: |
echo "=== BUILD STATUS REPORT ==="
cat $BUILD_STATUS
echo "=========================="
echo "build_status_output<<EOF" >> $GITHUB_OUTPUT
cat $BUILD_STATUS >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
#SLACK NOTIFICATION ON FAILURE
notify_slack:
needs: build_pypowsybl
runs-on: ubuntu-latest
if: failure()
steps:
- name: Send Slack Notification
uses: 8398a7/action-slack@v3
with:
status: ${{ job.status }}
text: |
:x: *Failed workflow ${{ github.workflow }}*
*Failure details:*
```
${{ needs.build_pypowsybl.outputs.build_status_output }}
```
See logs: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

3 changes: 3 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ sphinx:
python:
install:
- requirements: requirements.txt

formats:
- pdf
3 changes: 2 additions & 1 deletion cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ endif()

if(BUILD_PYTHON_BINDINGS)
#Build pythin bindings
add_subdirectory(lib/pybind11)
set(PYBIND11_FINDPYTHON ON)
find_package(pybind11 CONFIG REQUIRED)
add_subdirectory(pypowsybl-cpp)
endif()
1 change: 0 additions & 1 deletion cpp/lib/pybind11
Submodule pybind11 deleted from 3e9dfa
3 changes: 2 additions & 1 deletion cpp/pypowsybl-cpp/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,8 @@ PYBIND11_MODULE(_pypowsybl, m) {
.value("AREA", element_type::AREA)
.value("AREA_VOLTAGE_LEVELS", element_type::AREA_VOLTAGE_LEVELS)
.value("AREA_BOUNDARIES", element_type::AREA_BOUNDARIES)
.value("INTERNAL_CONNECTION", element_type::INTERNAL_CONNECTION);
.value("INTERNAL_CONNECTION", element_type::INTERNAL_CONNECTION)
.value("PROPERTIES", element_type::PROPERTIES);

py::enum_<filter_attributes_type>(m, "FilterAttributesType")
.value("ALL_ATTRIBUTES", filter_attributes_type::ALL_ATTRIBUTES)
Expand Down
3 changes: 2 additions & 1 deletion cpp/pypowsybl-java/powsybl-api.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ typedef enum {
AREA,
AREA_VOLTAGE_LEVELS,
AREA_BOUNDARIES,
INTERNAL_CONNECTION
INTERNAL_CONNECTION,
PROPERTIES
} element_type;

typedef enum {
Expand Down
1 change: 1 addition & 0 deletions docs/reference/network.rst
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ Network elements can be modified using dataframes:
Network.update_switches
Network.update_voltage_levels
Network.update_vsc_converter_stations
Network.get_elements_properties
Network.add_elements_properties
Network.remove_elements_properties
Network.add_aliases
Expand Down
7 changes: 7 additions & 0 deletions java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
<properties>
<java.version>17</java.version>
<commons-collections4.version>4.4</commons-collections4.version>
<commons-csv.version>1.11.0</commons-csv.version>

<graalvm.version>23.0.0</graalvm.version>
<janino.version>3.1.0</janino.version>
<junit-jupiter.version>5.10.0</junit-jupiter.version>
Expand Down Expand Up @@ -179,6 +181,11 @@
<artifactId>logback-core</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-csv</artifactId>
<version>${commons-csv.version}</version>
</dependency>
<!-- workaround for https://github.com/oracle/graal/issues/1943 -->
<dependency>
<groupId>org.codehaus.janino</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,6 @@ public enum DataframeElementType {
AREA,
AREA_VOLTAGE_LEVELS,
AREA_BOUNDARIES,
INTERNAL_CONNECTION
INTERNAL_CONNECTION,
PROPERTIES
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import java.util.*;
import java.util.function.*;
import java.util.stream.IntStream;
import java.util.stream.Stream;

import static com.powsybl.dataframe.MappingUtils.*;
Expand Down Expand Up @@ -93,6 +94,7 @@ private static Map<DataframeElementType, NetworkDataframeMapper> createMappers()
mappers.put(DataframeElementType.INJECTION, injections());
mappers.put(DataframeElementType.BRANCH, branches());
mappers.put(DataframeElementType.TERMINAL, terminals());
mappers.put(DataframeElementType.PROPERTIES, properties());
return Collections.unmodifiableMap(mappers);
}

Expand Down Expand Up @@ -437,7 +439,9 @@ static NetworkDataframeMapper shuntsNonLinear() {
.filter(sc -> sc.getModelType() == ShuntCompensatorModelType.NON_LINEAR)
.flatMap(shuntCompensator -> {
ShuntCompensatorNonLinearModel model = (ShuntCompensatorNonLinearModel) shuntCompensator.getModel();
return model.getAllSections().stream().map(section -> Triple.of(shuntCompensator, section, model.getAllSections().indexOf(section)));
// careful: shunt section number starts at 1, but position in array starts at 0
var allSections = model.getAllSections();
return IntStream.range(0, allSections.size()).mapToObj(i -> Triple.of(shuntCompensator, allSections.get(i), i + 1));
});
return NetworkDataframeMapperBuilder.ofStream(nonLinearShunts, NetworkDataframes::getShuntSectionNonlinear)
.stringsIndex("id", triple -> triple.getLeft().getId())
Expand All @@ -457,7 +461,12 @@ static Triple<ShuntCompensator, ShuntCompensatorNonLinearModel.Section, Integer>
} else {
int section = dataframe.getIntValue("section", index)
.orElseThrow(() -> new PowsyblException("section is missing"));
return Triple.of(shuntCompensator, shuntNonLinear.getAllSections().get(section), section);
// careful: shunt section number starts at 1, but position in array starts at 0
List<ShuntCompensatorNonLinearModel.Section> allSections = shuntNonLinear.getAllSections();
if (section < 1 || section > allSections.size()) {
throw new PowsyblException(String.format("Section number must be between 1 and %d, inclusive", allSections.size()));
}
return Triple.of(shuntCompensator, allSections.get(section - 1), section);
}
}

Expand Down Expand Up @@ -1322,6 +1331,7 @@ public static NetworkDataframeMapper getExtensionDataframeMapper(String extensio
private static NetworkDataframeMapper aliases() {
return NetworkDataframeMapperBuilder.ofStream(NetworkDataframes::getAliasesData)
.stringsIndex("id", pair -> pair.getLeft().getId())
.strings("type", pair -> pair.getLeft().getType().toString())
.strings("alias", Pair::getRight)
.strings("alias_type", pair -> pair.getLeft().getAliasType(pair.getRight()).orElse(""))
.build();
Expand All @@ -1333,6 +1343,21 @@ private static Stream<Pair<Identifiable<?>, String>> getAliasesData(Network netw
.map(alias -> Pair.of(identifiable, alias)));
}

private static NetworkDataframeMapper properties() {
return NetworkDataframeMapperBuilder.ofStream(NetworkDataframes::getPropertiesData)
.stringsIndex("id", pair -> pair.getLeft().getId())
.strings("type", pair -> pair.getLeft().getType().toString())
.strings("key", Pair::getRight)
.strings("value", pair -> pair.getLeft().getProperty(pair.getRight()))
.build();
}

private static Stream<Pair<Identifiable<?>, String>> getPropertiesData(Network network) {
return network.getIdentifiables().stream()
.flatMap(identifiable -> identifiable.getPropertyNames().stream()
.map(prop -> Pair.of(identifiable, prop)));
}

private static NetworkDataframeMapper areaVoltageLevels() {
return NetworkDataframeMapperBuilder.ofStream(NetworkDataframes::areaVoltageLevelsData)
.stringsIndex("id", pair -> pair.getLeft().getId())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,8 @@ public enum ElementType {
AREA,
AREA_VOLTAGE_LEVELS,
AREA_BOUNDARIES,
INTERNAL_CONNECTION;
INTERNAL_CONNECTION,
PROPERTIES;

@CEnumValue
public native int getCValue();
Expand Down
2 changes: 2 additions & 0 deletions java/src/main/java/com/powsybl/python/commons/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ public static PyPowsyblApiHeader.ElementType convert(DataframeElementType type)
case AREA_VOLTAGE_LEVELS -> PyPowsyblApiHeader.ElementType.AREA_VOLTAGE_LEVELS;
case AREA_BOUNDARIES -> PyPowsyblApiHeader.ElementType.AREA_BOUNDARIES;
case INTERNAL_CONNECTION -> PyPowsyblApiHeader.ElementType.INTERNAL_CONNECTION;
case PROPERTIES -> PyPowsyblApiHeader.ElementType.PROPERTIES;
};
}

Expand Down Expand Up @@ -271,6 +272,7 @@ public static DataframeElementType convert(PyPowsyblApiHeader.ElementType type)
case AREA_VOLTAGE_LEVELS -> DataframeElementType.AREA_VOLTAGE_LEVELS;
case AREA_BOUNDARIES -> DataframeElementType.AREA_BOUNDARIES;
case INTERNAL_CONNECTION -> DataframeElementType.INTERNAL_CONNECTION;
case PROPERTIES -> DataframeElementType.PROPERTIES;
};
}

Expand Down
11 changes: 6 additions & 5 deletions java/src/main/java/com/powsybl/python/network/Dataframes.java
Original file line number Diff line number Diff line change
Expand Up @@ -310,18 +310,19 @@ private static List<NodeContext> getNodeBreakerViewNodes(VoltageLevel.NodeBreake
return nodes.stream().map(node -> {
Terminal terminal = nodeBreakerView.getTerminal(node);
if (terminal == null) {
return new NodeContext(node, null);
return new NodeContext(node, null, null);
} else {
return new NodeContext(node, terminal.getConnectable().getId());
return new NodeContext(node, terminal.getConnectable().getId(), terminal.getConnectable().getType());
}
}).collect(Collectors.toList());
}).toList();
}

private static DataframeMapper<VoltageLevel.NodeBreakerView, Void> createNodeBreakerViewNodes() {
return new DataframeMapperBuilder<VoltageLevel.NodeBreakerView, NodeContext, Void>()
.itemsProvider(Dataframes::getNodeBreakerViewNodes)
.intsIndex("node", NodeContext::getNode)
.strings("connectable_id", node -> Objects.toString(node.getConnectableId(), ""))
.intsIndex("node", NodeContext::node)
.strings("connectable_id", node -> Objects.toString(node.connectableId(), ""))
.strings("connectable_type", node -> Objects.toString(node.connectableType(), ""))
.build();
}

Expand Down
20 changes: 2 additions & 18 deletions java/src/main/java/com/powsybl/python/network/NodeContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,10 @@
*/
package com.powsybl.python.network;

import javax.annotation.Nullable;
import java.util.Objects;
import com.powsybl.iidm.network.IdentifiableType;

/**
* @author Etienne Lesot {@literal <etienne.lesot at rte-france.com>}
*/
public class NodeContext {
private final int node;
private final String connectableId;

public NodeContext(int node, @Nullable String connectableId) {
this.node = Objects.requireNonNull(node);
this.connectableId = connectableId;
}

public int getNode() {
return node;
}

public String getConnectableId() {
return connectableId;
}
public record NodeContext(int node, String connectableId, IdentifiableType connectableType) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@
{
"name":"com.fasterxml.jackson.databind.ext.Java7SupportImpl",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"[Lcom.fasterxml.jackson.databind.deser.Deserializers;"
}
]
Loading

0 comments on commit 984a78f

Please sign in to comment.