Skip to content

Commit 2db3fad

Browse files
authored
Merge branch 'main' into fix-current-sensor-output-residuals
2 parents 040ba60 + edc1018 commit 2db3fad

File tree

50 files changed

+486
-430
lines changed

Some content is hidden

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

50 files changed

+486
-430
lines changed

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

+9-22
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@ on:
1313
type: boolean
1414
description: Create a (pre-)release when CI passes
1515
required: true
16-
secrets:
17-
PYPI_USER:
18-
required: true
19-
PYPI_PASS:
20-
required: true
2116
# run this workflow manually from the Actions tab
2217
workflow_dispatch:
2318
inputs:
@@ -44,12 +39,13 @@ jobs:
4439
python-version: "3.12"
4540

4641
- name: Set PyPI Version
47-
run: |
48-
pip install requests build
49-
python set_pypi_version.py
42+
uses: PowerGridModel/pgm-version-bump@main
5043

5144
- name: Build SDist
52-
run: python -m build --sdist --outdir wheelhouse .
45+
run: |
46+
cat PYPI_VERSION
47+
pip install build
48+
python -m build --sdist --outdir wheelhouse .
5349
5450
- name: Keep version file
5551
uses: actions/upload-artifact@v4
@@ -283,16 +279,14 @@ jobs:
283279
- name: Test
284280
run: pytest
285281

286-
publish-wheels:
282+
github-release:
283+
name: Create and release assets to GitHub
287284
needs: [build-cpp-test-linux, build-cpp-test-windows, build-cpp-test-macos, build-and-test-python, build-and-test-conda]
288285
# always run publish job but fail at the first step if previous jobs have been failed
289286
if: always()
290-
runs-on: ubuntu-24.04
287+
runs-on: ubuntu-latest
291288
permissions:
292289
contents: write
293-
env:
294-
TWINE_USERNAME: ${{ secrets.PYPI_USER }}
295-
TWINE_PASSWORD: ${{ secrets.PYPI_PASS }}
296290

297291
steps:
298292
- name: Fail fast
@@ -329,14 +323,7 @@ jobs:
329323
- name: Display tag
330324
run: echo "${{ steps.tag.outputs.tag }}"
331325

332-
- name: Upload wheels
333-
if: (inputs.create_release)
334-
run: |
335-
pip install twine
336-
echo "Publish to PyPI..."
337-
twine upload --verbose wheelhouse/*
338-
339-
- name: Release
326+
- name: Create GitHub release
340327
uses: softprops/action-gh-release@v2
341328
if: (inputs.create_release)
342329
with:

.github/workflows/check-code-quality.yml

+6
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ jobs:
6161
sudo apt-get update && sudo apt-get install -y clang-format-18
6262
find . -regex '.*\.\(h\|c\|cpp\|hpp\|cc\|cxx\)' -exec clang-format-18 -style=file -i {} \;
6363
64+
- name: Install and run markdownlint
65+
run: |
66+
npm install -g markdownlint-cli
67+
echo "Running markdownlint"
68+
markdownlint --fix .
69+
6470
- name: If needed raise error
6571
run: |
6672

.github/workflows/ci.yml

-3
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ jobs:
4343
# create_release becomes true if the event that triggered this workflow is "push" on main
4444
# otherwise create_release becomes false
4545
create_release: ${{ (github.event_name == 'workflow_dispatch' && inputs.create_release) || github.event_name == 'push'}}
46-
secrets:
47-
PYPI_USER: ${{ secrets.PYPI_USER }}
48-
PYPI_PASS: ${{ secrets.PYPI_PASS }}
4946

5047
check-code-quality:
5148
uses: "./.github/workflows/check-code-quality.yml"

.github/workflows/nightly.yml

-3
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ jobs:
2121
contents: write
2222
with:
2323
create_release: false
24-
secrets:
25-
PYPI_USER: user
26-
PYPI_PASS: pass
2724

2825
check-code-quality:
2926
uses: "./.github/workflows/check-code-quality.yml"

.github/workflows/publish-pypi.yml

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# SPDX-FileCopyrightText: Contributors to the Power Grid Model project <powergridmodel@lfenergy.org>
2+
#
3+
# SPDX-License-Identifier: MPL-2.0
4+
5+
name: Publish to PyPI
6+
7+
on:
8+
release:
9+
types: [published]
10+
workflow_dispatch:
11+
12+
permissions:
13+
contents: write
14+
id-token: write # Required for Trusted Publishing
15+
16+
jobs:
17+
publish:
18+
name: Publish to PyPI
19+
runs-on: ubuntu-latest
20+
21+
steps:
22+
- name: Download assets from GitHub release
23+
uses: robinraju/release-downloader@v1
24+
with:
25+
repository: ${{ github.repository }}
26+
# download the latest release
27+
latest: true
28+
# don't donwload pre-releases
29+
preRelease: false
30+
fileName: "*"
31+
# don't download GitHub-generated source tar and zip files
32+
tarBall: false
33+
zipBall: false
34+
# create a directory to store the downloaded assets
35+
out-file-path: assets-to-publish
36+
# don't extract downloaded files
37+
extract: false
38+
39+
- name: List downloaded assets
40+
run: ls -la assets-to-publish
41+
42+
- name: Upload assets to PyPI
43+
uses: pypa/gh-action-pypi-publish@release/v1
44+
with:
45+
# To test, use the TestPyPI:
46+
# repository-url: https://test.pypi.org/legacy/
47+
# You must also create an account and project on TestPyPI,
48+
# as well as set the trusted-publisher in the project settings:
49+
# https://docs.pypi.org/trusted-publishers/adding-a-publisher/
50+
# To publish to the official PyPI repository, just keep
51+
# repository-url commented out.
52+
packages-dir: assets-to-publish
53+
skip-existing: true
54+
print-hash: true
55+
verbose: true

.markdownlint.yaml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# SPDX-FileCopyrightText: Contributors to the Power Grid Model project <powergridmodel@lfenergy.org>
2+
#
3+
# SPDX-License-Identifier: MPL-2.0
4+
5+
# MD001/heading-increment : Heading levels should only increment by one level at a time : https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md001.md
6+
MD001: false
7+
8+
# MD013/line-length : Line length : https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md013.md
9+
MD013: false
10+
# # Number of characters
11+
# line_length: 80
12+
# # Number of characters for headings
13+
# heading_line_length: 80
14+
# # Number of characters for code blocks
15+
# code_block_line_length: 80
16+
# # Include code blocks
17+
# code_blocks: true
18+
# # Include tables
19+
# tables: true
20+
# # Include headings
21+
# headings: true
22+
# # Strict length checking
23+
# strict: false
24+
# # Stern length checking
25+
# stern: false
26+
27+
# MD024/no-duplicate-heading : Multiple headings with the same content : https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md024.md
28+
MD024: false

.pre-commit-config.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,8 @@ repos:
4141
hooks:
4242
- id: clang-format
4343
types_or: [ c++, c ]
44+
- repo: https://github.com/igorshubovych/markdownlint-cli
45+
rev: v0.44.0
46+
hooks:
47+
- id: markdownlint
48+
args: ["--fix"]

.vscode/extensions.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"matepek.vscode-catch2-test-adapter",
2525
"cschlosser.doxdocgen",
2626
"fredericbonnet.cmake-test-adapter",
27-
"sonarsource.sonarlint-vscode"
27+
"sonarsource.sonarlint-vscode",
28+
"davidanson.vscode-markdownlint"
2829
]
2930
}

README.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ SPDX-FileCopyrightText: Contributors to the Power Grid Model project <powergridm
44
SPDX-License-Identifier: MPL-2.0
55
-->
66

7-
[![PyPI version](https://badge.fury.io/py/power-grid-model.svg?no-cache)](https://badge.fury.io/py/power-grid-model)
7+
[![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 -->
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)
1010
[![Downloads](https://static.pepy.tech/badge/power-grid-model)](https://pepy.tech/project/power-grid-model)
@@ -24,7 +24,7 @@ SPDX-License-Identifier: MPL-2.0
2424

2525
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.8054429.svg)](https://zenodo.org/record/8054429)
2626

27-
[![](https://github.com/PowerGridModel/.github/blob/main/artwork/svg/color.svg)](#)
27+
[![Power Grid Model logo](https://github.com/PowerGridModel/.github/blob/main/artwork/svg/color.svg)](#) <!-- markdownlint-disable-line no-empty-links -->
2828

2929
# Power Grid Model
3030

@@ -50,15 +50,15 @@ Want to be updated on the latest news and releases? Subscribe to the Power Grid
5050

5151
You can directly install the package from PyPI.
5252

53-
```
53+
```sh
5454
pip install power-grid-model
5555
```
5656

5757
### Install from Conda
5858

5959
If you are using `conda`, you can directly install the package from `conda-forge` channel.
6060

61-
```
61+
```sh
6262
conda install -c conda-forge power-grid-model
6363
```
6464

@@ -68,7 +68,7 @@ To install the library from source, refer to the [Build Guide](https://power-gri
6868

6969
## Examples
7070

71-
Please refer to [Examples](https://github.com/PowerGridModel/power-grid-model-workshop/tree/main/examples) for more detailed examples for power flow and state estimation.
71+
Please refer to [Examples](https://github.com/PowerGridModel/power-grid-model-workshop/tree/main/examples) for more detailed examples for power flow and state estimation.
7272
Notebooks for validating the input data and exporting input/output data are also included.
7373

7474
## License
@@ -77,14 +77,14 @@ This project is licensed under the Mozilla Public License, version 2.0 - see [LI
7777

7878
## Licenses third-party libraries
7979

80-
This project includes third-party libraries,
80+
This project includes third-party libraries,
8181
which are licensed under their own respective Open-Source licenses.
82-
SPDX-License-Identifier headers are used to show which license is applicable.
82+
SPDX-License-Identifier headers are used to show which license is applicable.
8383
The concerning license files can be found in the [LICENSES](https://github.com/PowerGridModel/power-grid-model/tree/main/LICENSES) directory.
8484

8585
## Contributing
8686

87-
Please read [CODE_OF_CONDUCT](https://github.com/PowerGridModel/.github/blob/main/CODE_OF_CONDUCT.md), [CONTRIBUTING](https://github.com/PowerGridModel/.github/blob/main/CONTRIBUTING.md), [PROJECT GOVERNANCE](https://github.com/PowerGridModel/.github/blob/main/GOVERNANCE.md) and [RELEASE](https://github.com/PowerGridModel/.github/blob/main/RELEASE.md) for details on the process
87+
Please read [CODE_OF_CONDUCT](https://github.com/PowerGridModel/.github/blob/main/CODE_OF_CONDUCT.md), [CONTRIBUTING](https://github.com/PowerGridModel/.github/blob/main/CONTRIBUTING.md), [PROJECT GOVERNANCE](https://github.com/PowerGridModel/.github/blob/main/GOVERNANCE.md) and [RELEASE](https://github.com/PowerGridModel/.github/blob/main/RELEASE.md) for details on the process
8888
for submitting pull requests to us.
8989

9090
Visit [Contribute](https://github.com/PowerGridModel/power-grid-model/contribute) for a list of good first issues in this repo.

docs/advanced_documentation/c-api.md

+16-16
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@ SPDX-License-Identifier: MPL-2.0
77
# Use Power Grid Model through C API
88

99
While many users use Python API for Power Grid Model.
10-
This library also provides a C API.
11-
The main use case of C API is to integrate Power Grid Model into a non-Python application/library, namely, C, C++, JAVA, C#, etc.
10+
This library also provides a C API.
11+
The main use case of C API is to integrate Power Grid Model into a non-Python application/library, namely, C, C++, JAVA, C#, etc.
1212

13-
The C API consists of some
13+
The C API consists of some
1414
{{ "[header files]({}/power_grid_model_c/power_grid_model_c/include)".format(gh_link_head_blob) }}
15-
and a dynamic library (`.so` or `.dll`) built by a
15+
and a dynamic library (`.so` or `.dll`) built by a
1616
{{ "[cmake project]({}/power_grid_model_c/power_grid_model_c/CMakeLists.txt)".format(gh_link_head_blob) }}.
1717
Please refer to the [Build Guide](./build-guide.md) about how to build the library.
1818

1919
You can refer to the [C API Reference](../api_reference/power-grid-model-c-api-reference.rst)
20-
for a detailed documentation of the API.
21-
Please also have a look at an
20+
for a detailed documentation of the API.
21+
Please also have a look at an
2222
{{ "[example]({}/power_grid_model_c_example/main.c)".format(gh_link_head_blob) }}
2323
of C program to use this C API.
2424

@@ -37,7 +37,7 @@ and making it available to their binaries, e.g. by adding its location to `PATH`
3737

3838
## Opaque struct/pointer
3939

40-
As a common C API practice, we use [opaque struct/pointer](https://en.wikipedia.org/wiki/Opaque_pointer) in the API.
40+
As a common C API practice, we use [opaque struct/pointer](https://en.wikipedia.org/wiki/Opaque_pointer) in the API.
4141
The user creates the object by `PGM_create_*` function and release the object by `PGM_destroy_*` function.
4242
In other function calls, the user provide the relevant opaque pointer as the argument.
4343
The real memory layout of the object is unknown to the user.
@@ -50,21 +50,21 @@ Moreover, we might want to also retrieve some meta information from the calculat
5050
The C API uses a handle opaque object `PGM_Handle` to store all these kinds of error messages and information.
5151
You need to pass a handle pointer to most of the functions in the C API.
5252

53-
For example, after calling `PGM_create_model`, you can use `PGM_error_code` and `PGM_error_message`
53+
For example, after calling `PGM_create_model`, you can use `PGM_error_code` and `PGM_error_message`
5454
to check if there is error during the creation and the error message.
5555

5656
If you are calling the C API in multiple threads, each thread should have its own handle object created by `PGM_create_handle`.
5757

5858
## Calculation options
5959

60-
To execute a power grid calculation you need to specify many options,
60+
To execute a power grid calculation you need to specify many options,
6161
e.g., maximum number of iterations, error tolerance, etc.
6262
We could have declared all the calculation options as individual arguments in the `PGM_calculate` function.
63-
However, due to the lack of default argument in C,
63+
However, due to the lack of default argument in C,
6464
this would mean that the C API has a breaking change everytime we add a new option,
6565
which happends very often.
6666

67-
To solve this issue, we use another opaque object `PGM_Options`. The user creates an object with default options by `PGM_create_options`. You can then specify individual options by `PGM_set_*`.
67+
To solve this issue, we use another opaque object `PGM_Options`. The user creates an object with default options by `PGM_create_options`. You can then specify individual options by `PGM_set_*`.
6868
In the `PGM_calculate` function you need to pass a pointer to `PGM_Options`.
6969
In this way, we can ensure the API backwards compatibility.
7070
If we add a new option, it will get a default value in the `PGM_create_options` function.
@@ -77,7 +77,7 @@ For compatibility reasons, that format is dictated by the C API using the `PGM_m
7777

7878
We define the following concepts in the data hierarchy:
7979

80-
* Dataset: a collection of data buffers for a given purpose.
80+
* Dataset: a collection of data buffers for a given purpose.
8181
At this moment, we have four dataset types: `input`, `update`, `sym_output`, `asym_output`.
8282
* Component: a data buffer with the representation of all attributes of a physical grid component in our [data model](../user_manual/components.md), e.g., `node`.
8383
* Attribute: a property of given component. For example, `u_rated` attribute of `node` is the rated voltage of the node.
@@ -126,7 +126,7 @@ Data buffers are almost always allocated and freed in the heap. We provide two w
126126

127127
* You can use the function `PGM_create_buffer` and `PGM_destroy_buffer` to create and destroy buffer.
128128
In this way, the library is handling the memory (de-)allocation.
129-
* You can call some memory (de-)allocation function in your own code according to your platform,
129+
* You can call some memory (de-)allocation function in your own code according to your platform,
130130
e.g., `aligned_alloc` and `free`.
131131
You need to first call `PGM_meta_*` functions to retrieve the size and alignment of a component.
132132

@@ -141,10 +141,10 @@ Once you have the data buffer, you need to set or get attributes. We provide two
141141

142142
* You can use the function `PGM_buffer_set_value` and `PGM_buffer_get_value` to get and set values.
143143
* You can do pointer cast directly on the buffer pointer, by shifting the pointer to proper offset
144-
and cast it to a certain value type.
144+
and cast it to a certain value type.
145145
You need to first call `PGM_meta_*` functions to retrieve the correct offset.
146146

147-
Pointer cast is generally more efficient and flexible because you are not calling into the
147+
Pointer cast is generally more efficient and flexible because you are not calling into the
148148
dynamic library everytime. But it requires the user to retrieve the offset information first.
149149
Using the buffer helper function is more convenient but with some overhead.
150150

@@ -153,7 +153,7 @@ Using the buffer helper function is more convenient but with some overhead.
153153
In the C API we have a function `PGM_buffer_set_nan` which sets all the attributes in a buffer to `NaN`.
154154
In the calculation core, if an optional attribute is `NaN`, it will use the default value.
155155

156-
If you just want to set some attributes and keep everything else as `NaN`,
156+
If you just want to set some attributes and keep everything else as `NaN`,
157157
calling `PGM_buffer_set_nan` before you set attribute is convenient.
158158
This is useful especially in `update` dataset because you do not always update all the mutable attributes.
159159

docs/advanced_documentation/native-data-interface.md

+6-7
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,12 @@ The pointers are passed into C++ code so that the C++ program can write results
115115

116116
The basic data types used in the interface between C++ and Python are shown in the table below.
117117

118-
| C++ type | `numpy.dtype` | null value | usage |
119-
| --- | --- | --- | --- |
120-
| `int32_t` | `'i4'` | - 2^31 | ids of physical components |
121-
| `int8_t` | `'i1'` | - 2^7 | enumeration types, boolean types, and small integers (e.g. tap position of transformer) |
122-
| `double` | `'f8'` | NaN ([IEEE 754](https://en.wikipedia.org/wiki/NaN)) | physical quantities (e.g. voltage) |
123-
| `double[3]` | `'(3, )f8'` | NaN ([IEEE 754](https://en.wikipedia.org/wiki/NaN)) | three-phase asymmetric physical quantities (e.g. voltage) |
118+
| C++ type | `numpy.dtype` | null value | usage |
119+
| ----------- | ------------- | --------------------------------------------------- | --------------------------------------------------------------------------------------- |
120+
| `int32_t` | `'i4'` | - 2^31 | ids of physical components |
121+
| `int8_t` | `'i1'` | - 2^7 | enumeration types, boolean types, and small integers (e.g. tap position of transformer) |
122+
| `double` | `'f8'` | NaN ([IEEE 754](https://en.wikipedia.org/wiki/NaN)) | physical quantities (e.g. voltage) |
123+
| `double[3]` | `'(3, )f8'` | NaN ([IEEE 754](https://en.wikipedia.org/wiki/NaN)) | three-phase asymmetric physical quantities (e.g. voltage) |
124124

125125
*The [endianness](https://en.wikipedia.org/wiki/Endianness)
126126
of C++ and Python side is also matched. For `x86-64` platform the little endian is used, so that
@@ -170,7 +170,6 @@ and predefines all the corresponding `numpy.dtype`.
170170
The detailed explanation of all attributes of each component is given in
171171
[Graph Data model](../user_manual/data-model.md#attributes-of-components).
172172

173-
174173
One can import the `power_grid_meta_data` to get all the predefined `numpy.dtype` and create relevant arrays.
175174
The code below creates an array which is compatible with transformer input dataset.
176175

0 commit comments

Comments
 (0)