Skip to content

Commit c767fca

Browse files
authored
Merge branch 'main' into feature/1112-add-overload
2 parents b268b05 + 6f66d31 commit c767fca

49 files changed

Lines changed: 2431 additions & 592 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/build-test-release.yml

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,14 @@ jobs:
8585
sudo ln -s /usr/bin/gcc-14 /usr/local/bin/gcc
8686
sudo ln -s /usr/bin/g++-14 /usr/local/bin/g++
8787
88-
- name: Enable brew
89-
run: |
90-
echo "/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin" >> $GITHUB_PATH
91-
- name: Install C++ dependencies
88+
- name: Install uv
89+
uses: astral-sh/setup-uv@v7
90+
91+
- name: Install pgm-build-dependencies
9292
run: |
93-
brew update
94-
brew install boost eigen nlohmann-json msgpack-cxx doctest
93+
uv tool install https://github.com/PowerGridModel/pgm-build-dependencies/releases/latest/download/pgm_build_dependencies-0.1.0-py3-none-any.whl
94+
pgm-build-setup-ga-ci
95+
9596
- name: Build and test
9697
run: ./build.sh -p ${{ env.PRESET }} -e -i -t
9798

@@ -108,21 +109,13 @@ jobs:
108109
steps:
109110
- uses: actions/checkout@v6
110111

111-
- name: Activate conda
112-
uses: conda-incubator/setup-miniconda@v3 # install miniforge instead
113-
with:
114-
miniforge-version: latest
115-
channels: conda-forge
116-
conda-remove-defaults: "true"
112+
- name: Install uv
113+
uses: astral-sh/setup-uv@v7
117114

118-
- name: List conda
115+
- name: Install pgm-build-dependencies
119116
run: |
120-
conda info
121-
conda list
122-
123-
- name: Install conda environment
124-
run: |
125-
conda create --yes -p C:\conda_envs\cpp_pkgs -c conda-forge libboost-headers eigen nlohmann_json msgpack-cxx doctest
117+
uv tool install https://github.com/PowerGridModel/pgm-build-dependencies/releases/latest/download/pgm_build_dependencies-0.1.0-py3-none-any.whl
118+
pgm-build-setup-ga-ci
126119
127120
- uses: ./.github/actions/enable-msvc
128121
if: runner.os == 'Windows'
@@ -166,10 +159,13 @@ jobs:
166159
with:
167160
xcode-version: latest-stable
168161

169-
- name: Install cpp dependencies
162+
- name: Install uv
163+
uses: astral-sh/setup-uv@v7
164+
165+
- name: Install pgm-build-dependencies
170166
run: |
171-
brew update
172-
brew install ninja boost eigen nlohmann-json msgpack-cxx doctest
167+
uv tool install https://github.com/PowerGridModel/pgm-build-dependencies/releases/latest/download/pgm_build_dependencies-0.1.0-py3-none-any.whl
168+
pgm-build-setup-ga-ci
173169
174170
- name: Build and test
175171
run: ./build.sh -p ${{ env.PRESET }} -e -i -t

.github/workflows/clang-tidy.yml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,13 @@ jobs:
5858
sudo ln -s /usr/bin/clang++-18 /usr/local/bin/clang++
5959
sudo ln -s /usr/bin/clang-tidy-18 /usr/local/bin/clang-tidy
6060
61-
- name: Enable brew
61+
- name: Install uv
62+
uses: astral-sh/setup-uv@v7
63+
64+
- name: Install pgm-build-dependencies
6265
run: |
63-
echo "/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin" >> $GITHUB_PATH
64-
65-
- name: Install C++ dependencies
66-
run: |
67-
brew update
68-
brew install boost eigen nlohmann-json msgpack-cxx doctest
66+
uv tool install https://github.com/PowerGridModel/pgm-build-dependencies/releases/latest/download/pgm_build_dependencies-0.1.0-py3-none-any.whl
67+
pgm-build-setup-ga-ci
6968
7069
- name: Set build target in case of workflow dispatch
7170
if: inputs.target != null

.github/workflows/sonar.yml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,12 @@ jobs:
3737
sudo apt-get install -y ninja-build clang-18 lcov gcovr
3838
sudo ln -s /usr/bin/clang-18 /usr/local/bin/clang
3939
sudo ln -s /usr/bin/clang++-18 /usr/local/bin/clang++
40-
- name: Enable brew
41-
run: |
42-
echo "/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin" >> $GITHUB_PATH
43-
- name: Install C++ dependencies
44-
run: |
45-
brew update
46-
brew install boost eigen nlohmann-json msgpack-cxx doctest
4740
- name: Install uv
4841
uses: astral-sh/setup-uv@v7
42+
- name: Install pgm-build-dependencies
43+
run: |
44+
uv tool install https://github.com/PowerGridModel/pgm-build-dependencies/releases/latest/download/pgm_build_dependencies-0.1.0-py3-none-any.whl
45+
pgm-build-setup-ga-ci
4946
- name: Install build-wrapper
5047
uses: SonarSource/sonarqube-scan-action/install-build-wrapper@v7
5148

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ repos:
99
- id: reuse
1010
- repo: https://github.com/astral-sh/ruff-pre-commit
1111
# Ruff version.
12-
rev: v0.14.10
12+
rev: v0.14.11
1313
hooks:
1414
# Run the linter.
1515
- id: ruff-check

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ SPDX-License-Identifier: MPL-2.0
77
[![PyPI version](https://badge.fury.io/py/power-grid-model.svg?no-cache)](https://badge.fury.io/py/power-grid-model) <!-- markdownlint-disable-line first-line-h1 line-length -->
88
[![Anaconda-Server Badge](https://anaconda.org/conda-forge/power-grid-model/badges/version.svg?no-cache)](https://anaconda.org/conda-forge/power-grid-model)
99
[![License: MPL2.0](https://img.shields.io/badge/License-MPL2.0-informational.svg)](https://github.com/PowerGridModel/power-grid-model/blob/main/LICENSE)
10+
[![OpenSSF Best Practices](https://bestpractices.coreinfrastructure.org/projects/7298/badge)](https://bestpractices.coreinfrastructure.org/projects/7298)
1011
[![Downloads](https://static.pepy.tech/badge/power-grid-model)](https://pepy.tech/project/power-grid-model)
1112
[![Downloads](https://static.pepy.tech/badge/power-grid-model/month)](https://pepy.tech/project/power-grid-model)
1213

docs/advanced_documentation/build-guide.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,22 @@ uv sync
386386
uv run pytest
387387
```
388388
389+
#### Build Python Library from Source with Native Debug Symbols
390+
391+
For debugging purposes, it may be useful to build the Power Grid Model with debug symbols in the shared native library.
392+
To do so, the following command can be used to override the default build settings.
393+
394+
```shell
395+
uv sync --config-settings=cmake.build-type="RelWithDebInfo"
396+
```
397+
398+
It is also possible to install the Power Grid Model as a full debug build, including extra sanity checks and with a
399+
lower degree of optimizations. Note this may come with a significant impact on the performance.
400+
401+
```shell
402+
uv sync --config-settings=cmake.build-type="Debug"
403+
```
404+
389405
### Build CMake Project
390406
391407
If you have installed Visual Studio 2019/2022 (not the build tools), you can open the repo folder as a cmake project.

docs/api_reference/python-api-reference.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ SPDX-License-Identifier: MPL-2.0
88

99
This is the Python API reference for the `power-grid-model` library.
1010
Due to the nature of how Python module works, we cannnot hide the implementation detail completely from the user.
11-
As a general rule, any Python modules/functions/classes which are not documented in this API documentation,
12-
are internal implementations.
11+
As a general rule, any Python modules/functions/classes not documented in this API documentation are internal
12+
implementations.
1313
**The user should not use any of them.**
1414
**We do not guarantee the stability or even the existence of those modules.**
1515

@@ -114,6 +114,8 @@ This includes all miscellaneous type hints not under dataset or categories.
114114
.. autofunction:: power_grid_model.utils.json_serialize_to_file
115115
.. autofunction:: power_grid_model.utils.msgpack_deserialize_from_file
116116
.. autofunction:: power_grid_model.utils.msgpack_serialize_to_file
117+
.. autofunction:: power_grid_model.utils.msgpack_deserialize_from_stream
118+
.. autofunction:: power_grid_model.utils.msgpack_serialize_to_stream
117119
.. autofunction:: power_grid_model.utils.import_json_data
118120
.. autofunction:: power_grid_model.utils.export_json_data
119121
.. autofunction:: power_grid_model.utils.self_test

docs/examples/Power Flow Example.ipynb

Lines changed: 78 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,6 +1146,64 @@
11461146
"print(output_data[ComponentType.line][\"i_from\"])"
11471147
]
11481148
},
1149+
{
1150+
"cell_type": "markdown",
1151+
"id": "344efbe8",
1152+
"metadata": {},
1153+
"source": [
1154+
"#### Cartesian product of batch datasets\n",
1155+
"\n",
1156+
"It is possible to conduct a batch calculation of multiple datasets in form of a cartesian product of their scenarios.\n",
1157+
"Assume certain batch datasets with N1, N2, N3, ... scenarios. \n",
1158+
"This would give us $N1 * N2 * N3 * ...$ possible combinations via the cartesian product.\n",
1159+
"The resultant output data is in flat form and it has dimension of N1 * N2 * N3 with first dataset being the highest\n",
1160+
"dimension. \n",
1161+
"This can be beneficial in reducing complexity of implementation of such batch calculation \n",
1162+
"along with keeping the size of such resultant update_data to a minimum.\n",
1163+
"\n",
1164+
"```note\n",
1165+
"The data validation module mentioned in #validation-(optional) does not support cartesian product of datasets. \n",
1166+
"It is advised to combine the datasets them manually via numpy to use the validator.\n",
1167+
"```"
1168+
]
1169+
},
1170+
{
1171+
"cell_type": "markdown",
1172+
"id": "5de1a2f7",
1173+
"metadata": {},
1174+
"source": [
1175+
"We can combine the time series mutation for all n-1 contingencies together in following way.\n",
1176+
"Both the batch datasets are passed together in `update_data` in a list."
1177+
]
1178+
},
1179+
{
1180+
"cell_type": "code",
1181+
"execution_count": 29,
1182+
"id": "d690eeb7",
1183+
"metadata": {},
1184+
"outputs": [
1185+
{
1186+
"name": "stdout",
1187+
"output_type": "stream",
1188+
"text": [
1189+
"Output data has shape (30, 3)\n",
1190+
"[0 1 1]\n",
1191+
"[0 1 1]\n",
1192+
"[1 0 1]\n",
1193+
"[1 0 1]\n"
1194+
]
1195+
}
1196+
],
1197+
"source": [
1198+
"output_data = model.calculate_power_flow(update_data=[n_min_1_mutation_update_specific, time_series_mutation])\n",
1199+
"print(\"Output data has shape\", output_data[ComponentType.line].shape)\n",
1200+
"line_output = output_data[ComponentType.line][\"energized\"]\n",
1201+
"print(line_output[0, :])\n",
1202+
"print(line_output[1, :])\n",
1203+
"print(line_output[10, :])\n",
1204+
"print(line_output[11, :])"
1205+
]
1206+
},
11491207
{
11501208
"attachments": {},
11511209
"cell_type": "markdown",
@@ -1210,7 +1268,7 @@
12101268
},
12111269
{
12121270
"cell_type": "code",
1213-
"execution_count": 29,
1271+
"execution_count": 30,
12141272
"id": "b5f10bae",
12151273
"metadata": {},
12161274
"outputs": [
@@ -1270,7 +1328,7 @@
12701328
},
12711329
{
12721330
"cell_type": "code",
1273-
"execution_count": 30,
1331+
"execution_count": 31,
12741332
"id": "1a221507",
12751333
"metadata": {},
12761334
"outputs": [
@@ -1312,15 +1370,15 @@
13121370
},
13131371
{
13141372
"cell_type": "code",
1315-
"execution_count": 31,
1373+
"execution_count": 32,
13161374
"id": "541af620",
13171375
"metadata": {},
13181376
"outputs": [
13191377
{
13201378
"name": "stdout",
13211379
"output_type": "stream",
13221380
"text": [
1323-
"Iteration failed to converge after 20 iterations! Max deviation: 3.54512e-16, error tolerance: 1e-20.\n",
1381+
"Iteration failed to converge after 20 iterations! Max deviation: 3.54512293063893e-16, error tolerance: 1e-20.\n",
13241382
"\n",
13251383
"Try validate_input_data() or validate_batch_data() to validate your data.\n",
13261384
"\n"
@@ -1360,7 +1418,7 @@
13601418
},
13611419
{
13621420
"cell_type": "code",
1363-
"execution_count": 32,
1421+
"execution_count": 33,
13641422
"id": "20d8285c",
13651423
"metadata": {},
13661424
"outputs": [],
@@ -1371,7 +1429,7 @@
13711429
},
13721430
{
13731431
"cell_type": "code",
1374-
"execution_count": 33,
1432+
"execution_count": 34,
13751433
"id": "b702eb15",
13761434
"metadata": {},
13771435
"outputs": [
@@ -1384,7 +1442,7 @@
13841442
"\n",
13851443
"Failed scenarios: [3 7]\n",
13861444
"Succeeded scenarios: [0 1 2 4 5 6 8 9]\n",
1387-
"Error messages: ['The id cannot be found: 1000\\n', 'Sparse matrix error, possibly singular matrix!\\nIf you get this error from state estimation, it might mean the system is not fully observable, i.e. not enough measurements.\\nIt might also mean that you are running into a corner case where PGM cannot resolve yet.See https://github.com/PowerGridModel/power-grid-model/issues/864.']\n"
1445+
"Error messages: ['The id cannot be found: 1000\\n', 'Sparse matrix error, possibly singular matrix!\\nIf you get this error from state estimation, it might mean the system is not fully observable, i.e. not enough measurements.\\nIt might also mean that you are running into a corner case where PGM cannot resolve yet.\\nSee https://github.com/PowerGridModel/power-grid-model/issues/864.']\n"
13881446
]
13891447
}
13901448
],
@@ -1406,7 +1464,7 @@
14061464
},
14071465
{
14081466
"cell_type": "code",
1409-
"execution_count": 34,
1467+
"execution_count": 35,
14101468
"id": "1ba71901",
14111469
"metadata": {},
14121470
"outputs": [
@@ -1415,16 +1473,16 @@
14151473
"output_type": "stream",
14161474
"text": [
14171475
"Node data with invalid results\n",
1418-
"[[ 9.99401170e-001 9.92685785e-001 9.94521366e-001]\n",
1419-
" [ 9.99347687e-001 9.86226389e-001 9.89352855e-001]\n",
1420-
" [ 9.99288384e-001 9.79654011e-001 9.84095542e-001]\n",
1421-
" [-2.66881060e+116 2.33997016e-302 6.70346672e-198]\n",
1422-
" [ 9.99151380e-001 9.66149483e-001 9.73298790e-001]\n",
1423-
" [ 9.99073166e-001 9.59205860e-001 9.67750710e-001]\n",
1424-
" [ 9.98988099e-001 9.52126208e-001 9.62096474e-001]\n",
1425-
" [-2.44756775e+092 5.35663612e-256 1.91838796e-203]\n",
1426-
" [ 9.98796126e-001 9.37530046e-001 9.50447962e-001]\n",
1427-
" [ 9.98688504e-001 9.29997471e-001 9.44441670e-001]]\n",
1476+
"[[9.99401170e-001 9.92685785e-001 9.94521366e-001]\n",
1477+
" [9.99347687e-001 9.86226389e-001 9.89352855e-001]\n",
1478+
" [9.99288384e-001 9.79654011e-001 9.84095542e-001]\n",
1479+
" [2.18565566e-312 4.89761332e-310 2.97079411e-313]\n",
1480+
" [9.99151380e-001 9.66149483e-001 9.73298790e-001]\n",
1481+
" [9.99073166e-001 9.59205860e-001 9.67750710e-001]\n",
1482+
" [9.98988099e-001 9.52126208e-001 9.62096474e-001]\n",
1483+
" [4.89761332e-310 4.89761332e-310 4.89761332e-310]\n",
1484+
" [9.98796126e-001 9.37530046e-001 9.50447962e-001]\n",
1485+
" [9.98688504e-001 9.29997471e-001 9.44441670e-001]]\n",
14281486
"Node data with only valid results\n",
14291487
"[[0.99940117 0.99268579 0.99452137]\n",
14301488
" [0.99934769 0.98622639 0.98935286]\n",
@@ -1467,7 +1525,7 @@
14671525
],
14681526
"metadata": {
14691527
"kernelspec": {
1470-
"display_name": "venv",
1528+
"display_name": "power-grid-model",
14711529
"language": "python",
14721530
"name": "python3"
14731531
},
@@ -1481,7 +1539,7 @@
14811539
"name": "python",
14821540
"nbconvert_exporter": "python",
14831541
"pygments_lexer": "ipython3",
1484-
"version": "3.13.3"
1542+
"version": "3.14.2"
14851543
}
14861544
},
14871545
"nbformat": 4,

0 commit comments

Comments
 (0)