You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/advanced_documentation/build-guide.md
+63-29Lines changed: 63 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,8 @@ SPDX-License-Identifier: MPL-2.0
6
6
7
7
# Build Guide
8
8
9
-
This document explains how you can build this library from source, including some examples of build environment. In this
9
+
This document explains how you can build this library from source, including some examples of build environment.
10
+
In this
10
11
repository there are three builds:
11
12
12
13
* A `power-grid-model`[pip](https://pypi.org/project/power-grid-model/) Python package with C++ extension as the calculation core.
@@ -22,22 +23,27 @@ repository there are three builds:
22
23
23
24
## Build Requirements
24
25
25
-
To build the library from source, you need to first prepare the compiler toolchains and the build dependencies. In this
26
-
section a list of general requirements are given. After this section there are examples of setup in Linux (Ubuntu 22.04),
26
+
To build the library from source, you need to first prepare the compiler toolchains and the build dependencies.
27
+
In this
28
+
section a list of general requirements are given.
29
+
After this section there are examples of setup in Linux (Ubuntu 22.04),
27
30
Windows 10, and macOS (Big Sur).
28
31
29
32
### Architecture Support
30
33
31
-
This library is written and tested on `x86_64` and `arm64` architecture. Building the library in `IA-32` might be working, but is
34
+
This library is written and tested on `x86_64` and `arm64` architecture.
35
+
Building the library in `IA-32` might be working, but is
32
36
not tested.
33
37
34
38
The source code is written with the mindset of ISO standard C++ only, i.e. avoid compiler-extension or platform-specific
35
-
features as much as possible. In this way the effort to port the library to other platform/architecture might be
39
+
features as much as possible.
40
+
In this way the effort to port the library to other platform/architecture might be
36
41
minimum.
37
42
38
43
### Compiler Support
39
44
40
-
You need a C++ compiler with C++20 support. Below is a list of tested compilers:
45
+
You need a C++ compiler with C++20 support.
46
+
Below is a list of tested compilers:
41
47
42
48
#### Linux
43
49
@@ -110,7 +116,8 @@ Then you can run the tests.
110
116
pytest
111
117
```
112
118
113
-
A basic `self_test` function is provided to check if the installation was successful and ensures there are no build errors, segmentation violations, undefined symbols, etc. It performs multiple C API calls, runs through the main data flow, and verifies the integrity of serialization and deserialization.
119
+
A basic `self_test` function is provided to check if the installation was successful and ensures there are no build errors, segmentation violations, undefined symbols, etc.
120
+
It performs multiple C API calls, runs through the main data flow, and verifies the integrity of serialization and deserialization.
If you opt for a developer build of Power Grid Model,
154
-
you can use the pre-defined CMake presets to enable developer build, including all the tests, warnings, examples, and benchmark. In the presets the [Ninja](https://ninja-build.org/) generator is used.
161
+
you can use the pre-defined CMake presets to enable developer build, including all the tests, warnings, examples, and benchmark.
162
+
In the presets the [Ninja](https://ninja-build.org/) generator is used.
155
163
In principle, you can use any C++ IDE with cmake and ninja support to develop the C++ project.
156
164
It is also possible to use the bare CMake CLI to set up the project.
157
165
Supported presets for your development platform can be listed using `cmake --list-presets`.
@@ -165,23 +173,32 @@ In the developer build the following build targets (directories) are enabled:
165
173
*`tests/benchmark_cpp`: the C++ benchmark target for performance measure.
166
174
*`power_grid_model_c_example`: an example C program to call the dynamic library
167
175
168
-
On Linux/macOS, the presets will use command `clang`/`clang++` or `gcc`/`g++` to find the relevant `clang` or `gcc` compiler. It is the developer's reponsiblity to properly define symbolic links (which should be discoverable through `PATH` environment variable) of `clang` or `gcc` compiler in your system. If you want to build with `clang-tidy`, you also need to define symbolic link of `clang-tidy` to point to the actual `clang-tidy` executable of your system.
176
+
On Linux/macOS, the presets will use command `clang`/`clang++` or `gcc`/`g++` to find the relevant `clang` or `gcc` compiler.
177
+
It is the developer's reponsiblity to properly define symbolic links (which should be discoverable through `PATH` environment variable) of `clang` or `gcc` compiler in your system.
178
+
If you want to build with `clang-tidy`, you also need to define symbolic link of `clang-tidy` to point to the actual `clang-tidy` executable of your system.
169
179
170
-
Similar also applies to Windows: the presets will use command `cl.exe` or `clang-cl.exe` to find the compiler. Developer needs to make sure the they are discoverable in `PATH`. For x64 Windows native development using MSVC or Clang CL, please use the `x64 Native Command Prompt`, which uses `vcvarsall.bat` to set up the appropriate build environment.
180
+
Similar also applies to Windows: the presets will use command `cl.exe` or `clang-cl.exe` to find the compiler.
181
+
Developer needs to make sure the they are discoverable in `PATH`.
182
+
For x64 Windows native development using MSVC or Clang CL, please use the `x64 Native Command Prompt`, which uses `vcvarsall.bat` to set up the appropriate build environment.
171
183
172
184
## Visual Studio Code Support
173
185
174
-
You can use any IDE to develop this project. As a popular cross-platform IDE, the settings for Visual Studio Code is preconfigured in the folder `.vscode`. You can open the repository folder with VSCode and the configuration will be loaded automatically.
186
+
You can use any IDE to develop this project.
187
+
As a popular cross-platform IDE, the settings for Visual Studio Code is preconfigured in the folder `.vscode`.
188
+
You can open the repository folder with VSCode and the configuration will be loaded automatically.
175
189
176
190
```{note}
177
-
VSCode (as well as some other IDEs) does not set its own build environment itself. For optimal usage, open the folder
178
-
using `code <project_dir>` from a terminal that has the environment set up. See above section for tips.
191
+
VSCode (as well as some other IDEs) does not set its own build environment itself.
192
+
For optimal usage, open the folder
193
+
using `code <project_dir>` from a terminal that has the environment set up.
194
+
See above section for tips.
179
195
```
180
196
181
197
## Build Script for Linux/macOS
182
198
183
199
There is a convenient shell script to build the cmake project in Linux or macOS:
184
-
{{ "[`build.sh`]({}/build.sh)".format(gh_link_head_blob) }}. You can study the file and write your own build script.
You can study the file and write your own build script.
185
202
The following options are supported in the build script.
186
203
187
204
```shell
@@ -196,8 +213,8 @@ To list the available presets, run `./build.sh -h`.
196
213
197
214
## Example Setup for Ubuntu 24.04 (in WSL or physical/virtual machine)
198
215
199
-
In this section an example is given forsetupin Ubuntu 24.04. You can use this example in Windows Subsystem for Linux (
200
-
WSL), or in a physical/virtual machine.
216
+
In this section an example is given forsetupin Ubuntu 24.04.
217
+
You can use this example in Windows Subsystem forLinux (WSL), orin a physical/virtual machine.
201
218
202
219
### Environment variables
203
220
@@ -258,7 +275,8 @@ pytest
258
275
259
276
There is a convenient shell script to build the cmake project: {{ "[`build.sh`]({}/build.sh)".format(gh_link_head_blob) }}.
260
277
261
-
As an example, go to the root folder of repo. Use the following command to build the project in release mode:
278
+
As an example, go to the root folder of repo.
279
+
Use the following command to build the project in release mode:
262
280
263
281
```shell
264
282
./build.sh -p <preset>
@@ -296,11 +314,13 @@ Define the following environment variable user-wide:
296
314
297
315
### Software Toolchains
298
316
299
-
You need to install the MSVC compiler. You can either install the whole Visual Studio IDE or just the build tools.
317
+
You need to install the MSVC compiler.
318
+
You can either install the whole Visual Studio IDE or just the build tools.
300
319
301
320
* [Visual Studio Build Tools](https://aka.ms/vs/17/release/vs_BuildTools.exe) (free)
302
321
* Select C++ build tools
303
-
* Full [Visual Studio](https://visualstudio.microsoft.com/vs/) (All three versions are suitable. Check the license!)
322
+
* Full [Visual Studio](https://visualstudio.microsoft.com/vs/) (All three versions are suitable.
323
+
Check the license!)
304
324
* Select Desktop Development with C++
305
325
* [Optional] Select `C++ Clang tools for Windows`
306
326
@@ -310,7 +330,8 @@ Other toolchains:
310
330
* [Git](https://git-scm.com/downloads)
311
331
312
332
```{note}
313
-
It is also possible to use any other `conda` provider like [Miniconda](https://docs.conda.io/en/latest/miniconda.html). However, we recommend using [Miniforge](https://github.com/conda-forge/miniforge), because it is published under BSD License and by default does not have any references to commercially licensed software.
333
+
It is also possible to use any other `conda` provider like [Miniconda](https://docs.conda.io/en/latest/miniconda.html).
334
+
However, we recommend using [Miniforge](https://github.com/conda-forge/miniforge), because it is published under BSD License and by default does not have any references to commercially licensed software.
314
335
```
315
336
316
337
```{note}
@@ -320,7 +341,8 @@ It is possible to enable long paths in Windows by following the steps in the [Mi
320
341
321
342
### C++ packages
322
343
323
-
The recommended way to get C++ package is via `conda`. Open a miniconda console.
344
+
The recommended way to get C++ package is via `conda`.
@@ -421,7 +447,8 @@ There is a convenient shell script to build the cmake project: {{ "[`build.sh`](
421
447
422
448
**Note: the test coverage option is not supported in macOS.**
423
449
424
-
As an example, go to the root folder of repo. Use the following command to build the project in release mode:
450
+
As an example, go to the root folder of repo.
451
+
Use the following command to build the project in release mode:
425
452
426
453
```shell
427
454
./build.sh -p <preset>
@@ -455,17 +482,23 @@ The {{ "[package tests]({}/tests/package_tests)".format(gh_link_head_blob) }} pr
455
482
project contained in {{ "[`tests/package_tests`]({}/tests/package_tests)".format(gh_link_head_blob) }}.
456
483
457
484
This project is designed to test and illustrate finding and linking to the installed package from the Power Grid Model
458
-
project. Setup of this project is done the same way as the setup of the main project mentioned in the above, but with
485
+
project.
486
+
Setup of this project is done the same way as the setup of the main project mentioned in the above, but with
459
487
the {{ "[`tests/package_tests`]({}/tests/package_tests)".format(gh_link_head_blob) }} directory as its root folder.
460
488
461
489
```{note}
462
-
This project has the main project as a required dependency. Configuration will fail if the main project has not been
490
+
This project has the main project as a required dependency.
491
+
Configuration will fail if the main project has not been
463
492
built and installed, e.g. using `cmake --build --preset <preset> --target install`for the current preset.
464
493
```
465
494
466
495
## Documentation
467
496
468
-
The documentation is built in [Sphinx](https://github.com/sphinx-doc/sphinx). It can be built locally in a Python environment. The packages required for building it can be found under the `[doc]` optional dependencies. In addition, the `power-grid-model` Python package needs to be built by following the steps mentioned [above](#build-python-package). After that, the documentation specific packages can be installed via:
497
+
The documentation is built in [Sphinx](https://github.com/sphinx-doc/sphinx).
498
+
It can be built locally in a Python environment.
499
+
The packages required for building it can be found under the `[doc]` optional dependencies.
500
+
In addition, the `power-grid-model` Python package needs to be built by following the steps mentioned [above](#build-python-package).
501
+
After that, the documentation specific packages can be installed via:
469
502
470
503
```shell
471
504
pip install -e .[doc]
@@ -475,7 +508,8 @@ pip install -e .[doc]
475
508
The `pip install .` part of the command installs the complete package from scratch.
476
509
```
477
510
478
-
The C API documentation is generated using [Doxygen](https://www.doxygen.nl). If you do not have Doxygen installed, it can also be temporarily bypassed by commenting out the `breathe` settings in`docs/conf.py`.
511
+
The C API documentation is generated using [Doxygen](https://www.doxygen.nl).
512
+
If you do not have Doxygen installed, it can also be temporarily bypassed by commenting out the `breathe` settings in`docs/conf.py`.
479
513
480
514
The documentation can be built with the following commands, resulting in HTML files of the webpages which can be found in`docs/_build/html` directory.
Copy file name to clipboardExpand all lines: docs/advanced_documentation/c-api.md
+15-7Lines changed: 15 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -26,7 +26,8 @@ In this documentation, the main design choices and concepts of the C API are pre
26
26
27
27
## Finding and linking the package
28
28
29
-
The package can be loaded using the Config mode of the `find_package` CMake command. An
29
+
The package can be loaded using the Config mode of the `find_package` CMake command.
30
+
An
30
31
{{ "[example project]({}/tests/package_tests/CMakeLists.txt)".format(gh_link_head_blob) }} is provided by the
31
32
{{ "[Git project]({})".format(gh_link_head_tree) }}, which is also used for testing the package.
32
33
@@ -64,7 +65,9 @@ However, due to the lack of default argument in C,
64
65
this would mean that the C API has a breaking change everytime we add a new option,
65
66
which happends very often.
66
67
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_*`.
68
+
To solve this issue, we use another opaque object `PGM_Options`.
69
+
The user creates an object with default options by `PGM_create_options`.
70
+
You can then specify individual options by `PGM_set_*`.
68
71
In the `PGM_calculate` function you need to pass a pointer to `PGM_Options`.
69
72
In this way, we can ensure the API backwards compatibility.
70
73
If we add a new option, it will get a default value in the `PGM_create_options` function.
@@ -80,7 +83,8 @@ We define the following concepts in the data hierarchy:
80
83
* Dataset: a collection of data buffers for a given purpose.
81
84
At this moment, we have four dataset types: `input`, `update`, `sym_output`, `asym_output`.
82
85
* 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`.
83
-
* Attribute: a property of given component. For example, `u_rated` attribute of `node` is the rated voltage of the node.
86
+
* Attribute: a property of given component.
87
+
For example, `u_rated` attribute of `node` is the rated voltage of the node.
84
88
85
89
Additionally, at this time, we distinguish two buffer types: [component buffers](#component-buffers) and [attribute buffers](#attribute-buffers).
86
90
@@ -122,7 +126,8 @@ iiiift iiiift iiiift <-- data: 6 bytes per line: 4 bytes for the ID, 1 for
122
126
123
127
#### Create and destroy buffer
124
128
125
-
Data buffers are almost always allocated and freed in the heap. We provide two ways of doing so.
129
+
Data buffers are almost always allocated and freed in the heap.
130
+
We provide two ways of doing so.
126
131
127
132
* You can use the function `PGM_create_buffer` and `PGM_destroy_buffer` to create and destroy buffer.
128
133
In this way, the library is handling the memory (de-)allocation.
@@ -137,15 +142,17 @@ You cannot use `PGM_destroy_buffer` to release a buffer created in your own code
137
142
138
143
#### Set and get attribute
139
144
140
-
Once you have the data buffer, you need to set or get attributes. We provide two ways of doing so.
145
+
Once you have the data buffer, you need to set or get attributes.
146
+
We provide two ways of doing so.
141
147
142
148
* You can use the function `PGM_buffer_set_value` and `PGM_buffer_get_value` to get and set values.
143
149
* You can do pointer cast directly on the buffer pointer, by shifting the pointer to proper offset
144
150
and cast it to a certain value type.
145
151
You need to first call `PGM_meta_*` functions to retrieve the correct offset.
146
152
147
153
Pointer cast is generally more efficient and flexible because you are not calling into the
148
-
dynamic library everytime. But it requires the user to retrieve the offset information first.
154
+
dynamic library everytime.
155
+
But it requires the user to retrieve the offset information first.
149
156
Using the buffer helper function is more convenient but with some overhead.
150
157
151
158
#### Set NaN function
@@ -183,7 +190,8 @@ A combination of attribute buffers with the same amount of elements has the powe
183
190
The type (implying the size) of each attribute can be found using the `PGM_meta_attribute_ctype`.
184
191
185
192
Since all attributes consist of primitive types, operations are straightforward.
186
-
We therefore do not provide explicit interface functionality to create an attribute buffer. Instead, you should use `PGM_dataset_const_add_buffer` or `PGM_dataset_mutable_add_buffer` with empty data (`NULL`) to set a component buffer for data in columnar-format, and use the functions `PGM_dataset_const_add_attribute_buffer` and `PGM_dataset_mutable_add_attribute_buffer` to add the attribute buffers directly to a dataset.
193
+
We therefore do not provide explicit interface functionality to create an attribute buffer.
194
+
Instead, you should use `PGM_dataset_const_add_buffer` or `PGM_dataset_mutable_add_buffer` with empty data (`NULL`) to set a component buffer for data in columnar-format, and use the functions `PGM_dataset_const_add_attribute_buffer` and `PGM_dataset_mutable_add_attribute_buffer` to add the attribute buffers directly to a dataset.
0 commit comments