power-grid-model 1.12.57__py3-none-win_amd64.whl → 1.12.59__py3-none-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of power-grid-model might be problematic. Click here for more details.

Files changed (59) hide show
  1. power_grid_model/__init__.py +54 -54
  2. power_grid_model/_core/__init__.py +3 -3
  3. power_grid_model/_core/buffer_handling.py +493 -493
  4. power_grid_model/_core/data_handling.py +141 -141
  5. power_grid_model/_core/data_types.py +132 -132
  6. power_grid_model/_core/dataset_definitions.py +109 -109
  7. power_grid_model/_core/enum.py +226 -226
  8. power_grid_model/_core/error_handling.py +206 -206
  9. power_grid_model/_core/errors.py +130 -130
  10. power_grid_model/_core/index_integer.py +17 -17
  11. power_grid_model/_core/options.py +71 -71
  12. power_grid_model/_core/power_grid_core.py +563 -563
  13. power_grid_model/_core/power_grid_dataset.py +535 -535
  14. power_grid_model/_core/power_grid_meta.py +243 -243
  15. power_grid_model/_core/power_grid_model.py +686 -686
  16. power_grid_model/_core/power_grid_model_c/__init__.py +3 -3
  17. power_grid_model/_core/power_grid_model_c/bin/power_grid_model_c.dll +0 -0
  18. power_grid_model/_core/power_grid_model_c/get_pgm_dll_path.py +63 -63
  19. power_grid_model/_core/power_grid_model_c/include/power_grid_model_c/basics.h +255 -255
  20. power_grid_model/_core/power_grid_model_c/include/power_grid_model_c/buffer.h +108 -108
  21. power_grid_model/_core/power_grid_model_c/include/power_grid_model_c/dataset.h +316 -316
  22. power_grid_model/_core/power_grid_model_c/include/power_grid_model_c/dataset_definitions.h +1052 -1052
  23. power_grid_model/_core/power_grid_model_c/include/power_grid_model_c/handle.h +99 -99
  24. power_grid_model/_core/power_grid_model_c/include/power_grid_model_c/meta_data.h +189 -189
  25. power_grid_model/_core/power_grid_model_c/include/power_grid_model_c/model.h +125 -125
  26. power_grid_model/_core/power_grid_model_c/include/power_grid_model_c/options.h +142 -142
  27. power_grid_model/_core/power_grid_model_c/include/power_grid_model_c/serialization.h +118 -118
  28. power_grid_model/_core/power_grid_model_c/include/power_grid_model_c.h +36 -36
  29. power_grid_model/_core/power_grid_model_c/include/power_grid_model_cpp/basics.hpp +65 -65
  30. power_grid_model/_core/power_grid_model_c/include/power_grid_model_cpp/buffer.hpp +61 -61
  31. power_grid_model/_core/power_grid_model_c/include/power_grid_model_cpp/dataset.hpp +220 -220
  32. power_grid_model/_core/power_grid_model_c/include/power_grid_model_cpp/handle.hpp +108 -108
  33. power_grid_model/_core/power_grid_model_c/include/power_grid_model_cpp/meta_data.hpp +84 -84
  34. power_grid_model/_core/power_grid_model_c/include/power_grid_model_cpp/model.hpp +63 -63
  35. power_grid_model/_core/power_grid_model_c/include/power_grid_model_cpp/options.hpp +52 -52
  36. power_grid_model/_core/power_grid_model_c/include/power_grid_model_cpp/serialization.hpp +124 -124
  37. power_grid_model/_core/power_grid_model_c/include/power_grid_model_cpp/utils.hpp +81 -81
  38. power_grid_model/_core/power_grid_model_c/include/power_grid_model_cpp.hpp +19 -19
  39. power_grid_model/_core/power_grid_model_c/lib/cmake/power_grid_model/power_grid_modelConfigVersion.cmake +3 -3
  40. power_grid_model/_core/serialization.py +317 -317
  41. power_grid_model/_core/typing.py +20 -20
  42. power_grid_model/_core/utils.py +798 -798
  43. power_grid_model/data_types.py +321 -321
  44. power_grid_model/enum.py +27 -27
  45. power_grid_model/errors.py +37 -37
  46. power_grid_model/typing.py +43 -43
  47. power_grid_model/utils.py +473 -473
  48. power_grid_model/validation/__init__.py +25 -25
  49. power_grid_model/validation/_rules.py +1171 -1171
  50. power_grid_model/validation/_validation.py +1172 -1172
  51. power_grid_model/validation/assertions.py +93 -93
  52. power_grid_model/validation/errors.py +602 -602
  53. power_grid_model/validation/utils.py +313 -313
  54. {power_grid_model-1.12.57.dist-info → power_grid_model-1.12.59.dist-info}/METADATA +1 -1
  55. power_grid_model-1.12.59.dist-info/RECORD +65 -0
  56. power_grid_model-1.12.57.dist-info/RECORD +0 -65
  57. {power_grid_model-1.12.57.dist-info → power_grid_model-1.12.59.dist-info}/WHEEL +0 -0
  58. {power_grid_model-1.12.57.dist-info → power_grid_model-1.12.59.dist-info}/entry_points.txt +0 -0
  59. {power_grid_model-1.12.57.dist-info → power_grid_model-1.12.59.dist-info}/licenses/LICENSE +0 -0
@@ -1,220 +1,220 @@
1
- // SPDX-FileCopyrightText: Contributors to the Power Grid Model project <powergridmodel@lfenergy.org>
2
- //
3
- // SPDX-License-Identifier: MPL-2.0
4
-
5
- #pragma once
6
- #ifndef POWER_GRID_MODEL_CPP_DATASET_HPP
7
- #define POWER_GRID_MODEL_CPP_DATASET_HPP
8
-
9
- #include "basics.hpp"
10
- #include "buffer.hpp"
11
- #include "handle.hpp"
12
-
13
- #include "power_grid_model_c/dataset.h"
14
-
15
- namespace power_grid_model_cpp {
16
- class ComponentTypeNotFound : public PowerGridError {
17
- public:
18
- ComponentTypeNotFound(std::string const& component)
19
- : PowerGridError{[&]() {
20
- using namespace std::string_literals;
21
- return "ComponentType"s + component + " not found"s;
22
- }()} {}
23
- ComponentTypeNotFound(std::string_view component) : ComponentTypeNotFound{std::string{component}} {}
24
- };
25
-
26
- class DatasetInfo {
27
-
28
- public:
29
- DatasetInfo(RawDatasetInfo const* info) noexcept : info_{info} {}
30
- DatasetInfo(DatasetInfo&&) = default;
31
- DatasetInfo& operator=(DatasetInfo&&) = default;
32
- DatasetInfo(DatasetInfo const&) = delete; // No copy constructor
33
- DatasetInfo& operator=(DatasetInfo const&) = delete; // No copy assignment
34
- ~DatasetInfo() = default;
35
-
36
- std::string name() const { return std::string{handle_.call_with(PGM_dataset_info_name, info_)}; }
37
-
38
- bool is_batch() const { return handle_.call_with(PGM_dataset_info_is_batch, info_) != 0; }
39
-
40
- Idx batch_size() const { return handle_.call_with(PGM_dataset_info_batch_size, info_); }
41
-
42
- Idx n_components() const { return handle_.call_with(PGM_dataset_info_n_components, info_); }
43
-
44
- std::string component_name(Idx component_idx) const {
45
- return std::string{handle_.call_with(PGM_dataset_info_component_name, info_, component_idx)};
46
- }
47
-
48
- Idx component_elements_per_scenario(Idx component_idx) const {
49
- return handle_.call_with(PGM_dataset_info_elements_per_scenario, info_, component_idx);
50
- }
51
-
52
- Idx component_total_elements(Idx component_idx) const {
53
- return handle_.call_with(PGM_dataset_info_total_elements, info_, component_idx);
54
- }
55
-
56
- Idx component_idx(std::string_view component) const {
57
- Idx const n_comp = n_components();
58
- for (Idx idx = 0; idx < n_comp; ++idx) {
59
- if (component_name(idx) == component) {
60
- return idx;
61
- }
62
- }
63
- throw ComponentTypeNotFound{component};
64
- }
65
-
66
- bool has_attribute_indications(Idx component_idx) const {
67
- return handle_.call_with(PGM_dataset_info_has_attribute_indications, info_, component_idx) != 0;
68
- }
69
-
70
- std::vector<std::string> attribute_indications(Idx component_idx) const {
71
- Idx const n_attributes = handle_.call_with(PGM_dataset_info_n_attribute_indications, info_, component_idx);
72
- std::vector<std::string> attributes;
73
- attributes.reserve(n_attributes);
74
- for (Idx idx = 0; idx < n_attributes; ++idx) {
75
- attributes.emplace_back(handle_.call_with(PGM_dataset_info_attribute_name, info_, component_idx, idx));
76
- }
77
- return attributes;
78
- }
79
-
80
- private:
81
- Handle handle_{};
82
- RawDatasetInfo const* info_;
83
- };
84
-
85
- class DatasetWritable {
86
- public:
87
- DatasetWritable(RawWritableDataset* dataset)
88
- : dataset_{dataset}, info_{handle_.call_with(PGM_dataset_writable_get_info, dataset_)} {}
89
- DatasetWritable(DatasetWritable&&) = default;
90
- DatasetWritable& operator=(DatasetWritable&&) = default;
91
- DatasetWritable(DatasetWritable const&) = delete; // No copy constructor
92
- DatasetWritable& operator=(DatasetWritable const&) = delete; // No copy assignment
93
- ~DatasetWritable() = default;
94
-
95
- RawWritableDataset const* get() const { return dataset_; }
96
- RawWritableDataset* get() { return dataset_; }
97
-
98
- DatasetInfo const& get_info() const { return info_; }
99
-
100
- void set_buffer(std::string const& component, Idx* indptr, RawDataPtr data) {
101
- handle_.call_with(PGM_dataset_writable_set_buffer, get(), component.c_str(), indptr, data);
102
- }
103
-
104
- void set_buffer(std::string const& component, Idx* indptr, Buffer& data) {
105
- handle_.call_with(PGM_dataset_writable_set_buffer, get(), component.c_str(), indptr, data.get());
106
- }
107
-
108
- void set_attribute_buffer(std::string const& component, std::string const& attribute, RawDataPtr data) {
109
- handle_.call_with(PGM_dataset_writable_set_attribute_buffer, get(), component.c_str(), attribute.c_str(), data);
110
- }
111
-
112
- void set_attribute_buffer(std::string const& component, std::string const& attribute, Buffer& data) {
113
- handle_.call_with(PGM_dataset_writable_set_attribute_buffer, get(), component.c_str(), attribute.c_str(),
114
- data.get());
115
- }
116
-
117
- private:
118
- Handle handle_{};
119
- RawWritableDataset* dataset_;
120
- DatasetInfo info_;
121
- };
122
-
123
- class DatasetMutable {
124
- public:
125
- explicit DatasetMutable(std::string const& dataset, bool is_batch, Idx batch_size)
126
- : dataset_{handle_.call_with(PGM_create_dataset_mutable, dataset.c_str(), (is_batch ? Idx{1} : Idx{0}),
127
- batch_size)},
128
- info_{handle_.call_with(PGM_dataset_mutable_get_info, get())} {}
129
-
130
- RawMutableDataset const* get() const { return dataset_.get(); }
131
- RawMutableDataset* get() { return dataset_.get(); }
132
-
133
- void add_buffer(std::string const& component, Idx elements_per_scenario, Idx total_elements, Idx const* indptr,
134
- RawDataPtr data) {
135
- handle_.call_with(PGM_dataset_mutable_add_buffer, get(), component.c_str(), elements_per_scenario,
136
- total_elements, indptr, data);
137
- }
138
-
139
- void add_buffer(std::string const& component, Idx elements_per_scenario, Idx total_elements, Idx const* indptr,
140
- Buffer& data) {
141
- handle_.call_with(PGM_dataset_mutable_add_buffer, get(), component.c_str(), elements_per_scenario,
142
- total_elements, indptr, data.get());
143
- }
144
-
145
- void add_attribute_buffer(std::string const& component, std::string const& attribute, RawDataPtr data) {
146
- handle_.call_with(PGM_dataset_mutable_add_attribute_buffer, get(), component.c_str(), attribute.c_str(), data);
147
- }
148
-
149
- void add_attribute_buffer(std::string const& component, std::string const& attribute, Buffer& data) {
150
- handle_.call_with(PGM_dataset_mutable_add_attribute_buffer, get(), component.c_str(), attribute.c_str(),
151
- data.get());
152
- }
153
-
154
- DatasetInfo const& get_info() const { return info_; }
155
-
156
- private:
157
- Handle handle_{};
158
- detail::UniquePtr<RawMutableDataset, &PGM_destroy_dataset_mutable> dataset_;
159
- DatasetInfo info_;
160
- };
161
-
162
- class DatasetConst {
163
- public:
164
- explicit DatasetConst(std::string const& dataset, bool is_batch, Idx batch_size)
165
- : dataset_{handle_.call_with(PGM_create_dataset_const, dataset.c_str(), (is_batch ? Idx{1} : Idx{0}),
166
- batch_size)},
167
- info_{handle_.call_with(PGM_dataset_const_get_info, get())} {}
168
-
169
- DatasetConst(DatasetWritable const& writable_dataset)
170
- : dataset_{handle_.call_with(PGM_create_dataset_const_from_writable, writable_dataset.get())},
171
- info_{handle_.call_with(PGM_dataset_const_get_info, get())} {}
172
-
173
- DatasetConst(DatasetMutable const& mutable_dataset)
174
- : dataset_{handle_.call_with(PGM_create_dataset_const_from_mutable, mutable_dataset.get())},
175
- info_{handle_.call_with(PGM_dataset_const_get_info, get())} {}
176
-
177
- RawConstDataset const* get() const { return dataset_.get(); }
178
- RawConstDataset* get() { return dataset_.get(); }
179
-
180
- void add_buffer(std::string const& component, Idx elements_per_scenario, Idx total_elements, Idx const* indptr,
181
- RawDataConstPtr data) {
182
- handle_.call_with(PGM_dataset_const_add_buffer, get(), component.c_str(), elements_per_scenario, total_elements,
183
- indptr, data);
184
- }
185
-
186
- void add_buffer(std::string const& component, Idx elements_per_scenario, Idx total_elements, Idx const* indptr,
187
- Buffer const& data) {
188
- handle_.call_with(PGM_dataset_const_add_buffer, get(), component.c_str(), elements_per_scenario, total_elements,
189
- indptr, data.get());
190
- }
191
-
192
- void add_attribute_buffer(std::string const& component, std::string const& attribute, RawDataConstPtr data) {
193
- handle_.call_with(PGM_dataset_const_add_attribute_buffer, get(), component.c_str(), attribute.c_str(), data);
194
- }
195
-
196
- void add_attribute_buffer(std::string const& component, std::string const& attribute, Buffer const& data) {
197
- handle_.call_with(PGM_dataset_const_add_attribute_buffer, get(), component.c_str(), attribute.c_str(),
198
- data.get());
199
- }
200
-
201
- DatasetInfo const& get_info() const { return info_; }
202
-
203
- private:
204
- Handle handle_{};
205
- detail::UniquePtr<RawConstDataset, &PGM_destroy_dataset_const> dataset_;
206
- DatasetInfo info_;
207
- };
208
-
209
- struct OwningMemory {
210
- std::vector<Buffer> buffers;
211
- std::vector<std::vector<Idx>> indptrs;
212
- };
213
-
214
- struct OwningDataset {
215
- DatasetMutable dataset;
216
- OwningMemory storage{};
217
- };
218
- } // namespace power_grid_model_cpp
219
-
220
- #endif // POWER_GRID_MODEL_CPP_DATASET_HPP
1
+ // SPDX-FileCopyrightText: Contributors to the Power Grid Model project <powergridmodel@lfenergy.org>
2
+ //
3
+ // SPDX-License-Identifier: MPL-2.0
4
+
5
+ #pragma once
6
+ #ifndef POWER_GRID_MODEL_CPP_DATASET_HPP
7
+ #define POWER_GRID_MODEL_CPP_DATASET_HPP
8
+
9
+ #include "basics.hpp"
10
+ #include "buffer.hpp"
11
+ #include "handle.hpp"
12
+
13
+ #include "power_grid_model_c/dataset.h"
14
+
15
+ namespace power_grid_model_cpp {
16
+ class ComponentTypeNotFound : public PowerGridError {
17
+ public:
18
+ ComponentTypeNotFound(std::string const& component)
19
+ : PowerGridError{[&]() {
20
+ using namespace std::string_literals;
21
+ return "ComponentType"s + component + " not found"s;
22
+ }()} {}
23
+ ComponentTypeNotFound(std::string_view component) : ComponentTypeNotFound{std::string{component}} {}
24
+ };
25
+
26
+ class DatasetInfo {
27
+
28
+ public:
29
+ DatasetInfo(RawDatasetInfo const* info) noexcept : info_{info} {}
30
+ DatasetInfo(DatasetInfo&&) = default;
31
+ DatasetInfo& operator=(DatasetInfo&&) = default;
32
+ DatasetInfo(DatasetInfo const&) = delete; // No copy constructor
33
+ DatasetInfo& operator=(DatasetInfo const&) = delete; // No copy assignment
34
+ ~DatasetInfo() = default;
35
+
36
+ std::string name() const { return std::string{handle_.call_with(PGM_dataset_info_name, info_)}; }
37
+
38
+ bool is_batch() const { return handle_.call_with(PGM_dataset_info_is_batch, info_) != 0; }
39
+
40
+ Idx batch_size() const { return handle_.call_with(PGM_dataset_info_batch_size, info_); }
41
+
42
+ Idx n_components() const { return handle_.call_with(PGM_dataset_info_n_components, info_); }
43
+
44
+ std::string component_name(Idx component_idx) const {
45
+ return std::string{handle_.call_with(PGM_dataset_info_component_name, info_, component_idx)};
46
+ }
47
+
48
+ Idx component_elements_per_scenario(Idx component_idx) const {
49
+ return handle_.call_with(PGM_dataset_info_elements_per_scenario, info_, component_idx);
50
+ }
51
+
52
+ Idx component_total_elements(Idx component_idx) const {
53
+ return handle_.call_with(PGM_dataset_info_total_elements, info_, component_idx);
54
+ }
55
+
56
+ Idx component_idx(std::string_view component) const {
57
+ Idx const n_comp = n_components();
58
+ for (Idx idx = 0; idx < n_comp; ++idx) {
59
+ if (component_name(idx) == component) {
60
+ return idx;
61
+ }
62
+ }
63
+ throw ComponentTypeNotFound{component};
64
+ }
65
+
66
+ bool has_attribute_indications(Idx component_idx) const {
67
+ return handle_.call_with(PGM_dataset_info_has_attribute_indications, info_, component_idx) != 0;
68
+ }
69
+
70
+ std::vector<std::string> attribute_indications(Idx component_idx) const {
71
+ Idx const n_attributes = handle_.call_with(PGM_dataset_info_n_attribute_indications, info_, component_idx);
72
+ std::vector<std::string> attributes;
73
+ attributes.reserve(n_attributes);
74
+ for (Idx idx = 0; idx < n_attributes; ++idx) {
75
+ attributes.emplace_back(handle_.call_with(PGM_dataset_info_attribute_name, info_, component_idx, idx));
76
+ }
77
+ return attributes;
78
+ }
79
+
80
+ private:
81
+ Handle handle_{};
82
+ RawDatasetInfo const* info_;
83
+ };
84
+
85
+ class DatasetWritable {
86
+ public:
87
+ DatasetWritable(RawWritableDataset* dataset)
88
+ : dataset_{dataset}, info_{handle_.call_with(PGM_dataset_writable_get_info, dataset_)} {}
89
+ DatasetWritable(DatasetWritable&&) = default;
90
+ DatasetWritable& operator=(DatasetWritable&&) = default;
91
+ DatasetWritable(DatasetWritable const&) = delete; // No copy constructor
92
+ DatasetWritable& operator=(DatasetWritable const&) = delete; // No copy assignment
93
+ ~DatasetWritable() = default;
94
+
95
+ RawWritableDataset const* get() const { return dataset_; }
96
+ RawWritableDataset* get() { return dataset_; }
97
+
98
+ DatasetInfo const& get_info() const { return info_; }
99
+
100
+ void set_buffer(std::string const& component, Idx* indptr, RawDataPtr data) {
101
+ handle_.call_with(PGM_dataset_writable_set_buffer, get(), component.c_str(), indptr, data);
102
+ }
103
+
104
+ void set_buffer(std::string const& component, Idx* indptr, Buffer& data) {
105
+ handle_.call_with(PGM_dataset_writable_set_buffer, get(), component.c_str(), indptr, data.get());
106
+ }
107
+
108
+ void set_attribute_buffer(std::string const& component, std::string const& attribute, RawDataPtr data) {
109
+ handle_.call_with(PGM_dataset_writable_set_attribute_buffer, get(), component.c_str(), attribute.c_str(), data);
110
+ }
111
+
112
+ void set_attribute_buffer(std::string const& component, std::string const& attribute, Buffer& data) {
113
+ handle_.call_with(PGM_dataset_writable_set_attribute_buffer, get(), component.c_str(), attribute.c_str(),
114
+ data.get());
115
+ }
116
+
117
+ private:
118
+ Handle handle_{};
119
+ RawWritableDataset* dataset_;
120
+ DatasetInfo info_;
121
+ };
122
+
123
+ class DatasetMutable {
124
+ public:
125
+ explicit DatasetMutable(std::string const& dataset, bool is_batch, Idx batch_size)
126
+ : dataset_{handle_.call_with(PGM_create_dataset_mutable, dataset.c_str(), (is_batch ? Idx{1} : Idx{0}),
127
+ batch_size)},
128
+ info_{handle_.call_with(PGM_dataset_mutable_get_info, get())} {}
129
+
130
+ RawMutableDataset const* get() const { return dataset_.get(); }
131
+ RawMutableDataset* get() { return dataset_.get(); }
132
+
133
+ void add_buffer(std::string const& component, Idx elements_per_scenario, Idx total_elements, Idx const* indptr,
134
+ RawDataPtr data) {
135
+ handle_.call_with(PGM_dataset_mutable_add_buffer, get(), component.c_str(), elements_per_scenario,
136
+ total_elements, indptr, data);
137
+ }
138
+
139
+ void add_buffer(std::string const& component, Idx elements_per_scenario, Idx total_elements, Idx const* indptr,
140
+ Buffer& data) {
141
+ handle_.call_with(PGM_dataset_mutable_add_buffer, get(), component.c_str(), elements_per_scenario,
142
+ total_elements, indptr, data.get());
143
+ }
144
+
145
+ void add_attribute_buffer(std::string const& component, std::string const& attribute, RawDataPtr data) {
146
+ handle_.call_with(PGM_dataset_mutable_add_attribute_buffer, get(), component.c_str(), attribute.c_str(), data);
147
+ }
148
+
149
+ void add_attribute_buffer(std::string const& component, std::string const& attribute, Buffer& data) {
150
+ handle_.call_with(PGM_dataset_mutable_add_attribute_buffer, get(), component.c_str(), attribute.c_str(),
151
+ data.get());
152
+ }
153
+
154
+ DatasetInfo const& get_info() const { return info_; }
155
+
156
+ private:
157
+ Handle handle_{};
158
+ detail::UniquePtr<RawMutableDataset, &PGM_destroy_dataset_mutable> dataset_;
159
+ DatasetInfo info_;
160
+ };
161
+
162
+ class DatasetConst {
163
+ public:
164
+ explicit DatasetConst(std::string const& dataset, bool is_batch, Idx batch_size)
165
+ : dataset_{handle_.call_with(PGM_create_dataset_const, dataset.c_str(), (is_batch ? Idx{1} : Idx{0}),
166
+ batch_size)},
167
+ info_{handle_.call_with(PGM_dataset_const_get_info, get())} {}
168
+
169
+ DatasetConst(DatasetWritable const& writable_dataset)
170
+ : dataset_{handle_.call_with(PGM_create_dataset_const_from_writable, writable_dataset.get())},
171
+ info_{handle_.call_with(PGM_dataset_const_get_info, get())} {}
172
+
173
+ DatasetConst(DatasetMutable const& mutable_dataset)
174
+ : dataset_{handle_.call_with(PGM_create_dataset_const_from_mutable, mutable_dataset.get())},
175
+ info_{handle_.call_with(PGM_dataset_const_get_info, get())} {}
176
+
177
+ RawConstDataset const* get() const { return dataset_.get(); }
178
+ RawConstDataset* get() { return dataset_.get(); }
179
+
180
+ void add_buffer(std::string const& component, Idx elements_per_scenario, Idx total_elements, Idx const* indptr,
181
+ RawDataConstPtr data) {
182
+ handle_.call_with(PGM_dataset_const_add_buffer, get(), component.c_str(), elements_per_scenario, total_elements,
183
+ indptr, data);
184
+ }
185
+
186
+ void add_buffer(std::string const& component, Idx elements_per_scenario, Idx total_elements, Idx const* indptr,
187
+ Buffer const& data) {
188
+ handle_.call_with(PGM_dataset_const_add_buffer, get(), component.c_str(), elements_per_scenario, total_elements,
189
+ indptr, data.get());
190
+ }
191
+
192
+ void add_attribute_buffer(std::string const& component, std::string const& attribute, RawDataConstPtr data) {
193
+ handle_.call_with(PGM_dataset_const_add_attribute_buffer, get(), component.c_str(), attribute.c_str(), data);
194
+ }
195
+
196
+ void add_attribute_buffer(std::string const& component, std::string const& attribute, Buffer const& data) {
197
+ handle_.call_with(PGM_dataset_const_add_attribute_buffer, get(), component.c_str(), attribute.c_str(),
198
+ data.get());
199
+ }
200
+
201
+ DatasetInfo const& get_info() const { return info_; }
202
+
203
+ private:
204
+ Handle handle_{};
205
+ detail::UniquePtr<RawConstDataset, &PGM_destroy_dataset_const> dataset_;
206
+ DatasetInfo info_;
207
+ };
208
+
209
+ struct OwningMemory {
210
+ std::vector<Buffer> buffers;
211
+ std::vector<std::vector<Idx>> indptrs;
212
+ };
213
+
214
+ struct OwningDataset {
215
+ DatasetMutable dataset;
216
+ OwningMemory storage{};
217
+ };
218
+ } // namespace power_grid_model_cpp
219
+
220
+ #endif // POWER_GRID_MODEL_CPP_DATASET_HPP
@@ -1,108 +1,108 @@
1
- // SPDX-FileCopyrightText: Contributors to the Power Grid Model project <powergridmodel@lfenergy.org>
2
- //
3
- // SPDX-License-Identifier: MPL-2.0
4
-
5
- #pragma once
6
- #ifndef POWER_GRID_MODEL_CPP_HANDLE_HPP
7
- #define POWER_GRID_MODEL_CPP_HANDLE_HPP
8
-
9
- #include "basics.hpp"
10
-
11
- #include "power_grid_model_c/handle.h"
12
-
13
- namespace power_grid_model_cpp {
14
- class PowerGridError : public std::exception {
15
- public:
16
- PowerGridError(std::string message) : message_(std::move(message)) {}
17
- const char* what() const noexcept override { return message_.c_str(); }
18
- virtual Idx error_code() const noexcept { return PGM_regular_error; };
19
-
20
- private:
21
- std::string message_;
22
- };
23
-
24
- class PowerGridRegularError : public PowerGridError {
25
- public:
26
- using PowerGridError::PowerGridError;
27
- Idx error_code() const noexcept override { return PGM_regular_error; }
28
- };
29
-
30
- class PowerGridSerializationError : public PowerGridError {
31
- public:
32
- using PowerGridError::PowerGridError;
33
- Idx error_code() const noexcept override { return PGM_serialization_error; }
34
- };
35
-
36
- class PowerGridBatchError : public PowerGridError {
37
- public:
38
- struct FailedScenario {
39
- Idx scenario{};
40
- std::string error_message;
41
- };
42
-
43
- PowerGridBatchError(std::string message, std::vector<FailedScenario> failed_scenarios_c)
44
- : PowerGridError{std::move(message)}, failed_scenarios_{std::move(failed_scenarios_c)} {}
45
- Idx error_code() const noexcept override { return PGM_batch_error; }
46
- std::vector<FailedScenario> const& failed_scenarios() const { return failed_scenarios_; }
47
-
48
- private:
49
- std::vector<FailedScenario> failed_scenarios_;
50
- };
51
-
52
- class Handle {
53
- public:
54
- RawHandle* get() const { return handle_.get(); }
55
-
56
- void clear_error() const { PGM_clear_error(get()); }
57
-
58
- void check_error() const {
59
- RawHandle const* handle_ptr = get();
60
- Idx const error_code = PGM_error_code(handle_ptr);
61
- std::string const error_message = error_code == PGM_no_error ? "" : PGM_error_message(handle_ptr);
62
- switch (error_code) {
63
- case PGM_no_error:
64
- return;
65
- case PGM_regular_error:
66
- clear_error();
67
- throw PowerGridRegularError{error_message};
68
- case PGM_batch_error: {
69
- Idx const n_failed_scenarios = PGM_n_failed_scenarios(handle_ptr);
70
- std::vector<PowerGridBatchError::FailedScenario> failed_scenarios(n_failed_scenarios);
71
- auto const* const failed_scenario_seqs = PGM_failed_scenarios(handle_ptr);
72
- auto const* const failed_scenario_messages = PGM_batch_errors(handle_ptr);
73
- for (Idx i = 0; i < n_failed_scenarios; ++i) {
74
- failed_scenarios[i] =
75
- PowerGridBatchError::FailedScenario{// NOLINT(modernize-use-designated-initializers)
76
- failed_scenario_seqs[i], failed_scenario_messages[i]};
77
- }
78
- clear_error();
79
- throw PowerGridBatchError{error_message, std::move(failed_scenarios)};
80
- }
81
- case PGM_serialization_error:
82
- clear_error();
83
- throw PowerGridSerializationError{error_message};
84
- default:
85
- clear_error();
86
- throw PowerGridError{error_message};
87
- }
88
- }
89
-
90
- template <typename Func, typename... Args> auto call_with(Func&& func, Args&&... args) const {
91
- if constexpr (std::is_void_v<decltype(std::forward<Func>(func)(get(), std::forward<Args>(args)...))>) {
92
- std::forward<Func>(func)(get(), std::forward<Args>(args)...);
93
- check_error();
94
- } else {
95
- auto result = std::forward<Func>(func)(get(), std::forward<Args>(args)...);
96
- check_error();
97
- return result;
98
- }
99
- }
100
-
101
- private:
102
- // For handle the const semantics are not needed.
103
- // It is meant to be mutated even in const situations.
104
- std::unique_ptr<RawHandle, detail::DeleterFunctor<&PGM_destroy_handle>> handle_{PGM_create_handle()};
105
- };
106
- } // namespace power_grid_model_cpp
107
-
108
- #endif // POWER_GRID_MODEL_CPP_HANDLE_HPP
1
+ // SPDX-FileCopyrightText: Contributors to the Power Grid Model project <powergridmodel@lfenergy.org>
2
+ //
3
+ // SPDX-License-Identifier: MPL-2.0
4
+
5
+ #pragma once
6
+ #ifndef POWER_GRID_MODEL_CPP_HANDLE_HPP
7
+ #define POWER_GRID_MODEL_CPP_HANDLE_HPP
8
+
9
+ #include "basics.hpp"
10
+
11
+ #include "power_grid_model_c/handle.h"
12
+
13
+ namespace power_grid_model_cpp {
14
+ class PowerGridError : public std::exception {
15
+ public:
16
+ PowerGridError(std::string message) : message_(std::move(message)) {}
17
+ const char* what() const noexcept override { return message_.c_str(); }
18
+ virtual Idx error_code() const noexcept { return PGM_regular_error; };
19
+
20
+ private:
21
+ std::string message_;
22
+ };
23
+
24
+ class PowerGridRegularError : public PowerGridError {
25
+ public:
26
+ using PowerGridError::PowerGridError;
27
+ Idx error_code() const noexcept override { return PGM_regular_error; }
28
+ };
29
+
30
+ class PowerGridSerializationError : public PowerGridError {
31
+ public:
32
+ using PowerGridError::PowerGridError;
33
+ Idx error_code() const noexcept override { return PGM_serialization_error; }
34
+ };
35
+
36
+ class PowerGridBatchError : public PowerGridError {
37
+ public:
38
+ struct FailedScenario {
39
+ Idx scenario{};
40
+ std::string error_message;
41
+ };
42
+
43
+ PowerGridBatchError(std::string message, std::vector<FailedScenario> failed_scenarios_c)
44
+ : PowerGridError{std::move(message)}, failed_scenarios_{std::move(failed_scenarios_c)} {}
45
+ Idx error_code() const noexcept override { return PGM_batch_error; }
46
+ std::vector<FailedScenario> const& failed_scenarios() const { return failed_scenarios_; }
47
+
48
+ private:
49
+ std::vector<FailedScenario> failed_scenarios_;
50
+ };
51
+
52
+ class Handle {
53
+ public:
54
+ RawHandle* get() const { return handle_.get(); }
55
+
56
+ void clear_error() const { PGM_clear_error(get()); }
57
+
58
+ void check_error() const {
59
+ RawHandle const* handle_ptr = get();
60
+ Idx const error_code = PGM_error_code(handle_ptr);
61
+ std::string const error_message = error_code == PGM_no_error ? "" : PGM_error_message(handle_ptr);
62
+ switch (error_code) {
63
+ case PGM_no_error:
64
+ return;
65
+ case PGM_regular_error:
66
+ clear_error();
67
+ throw PowerGridRegularError{error_message};
68
+ case PGM_batch_error: {
69
+ Idx const n_failed_scenarios = PGM_n_failed_scenarios(handle_ptr);
70
+ std::vector<PowerGridBatchError::FailedScenario> failed_scenarios(n_failed_scenarios);
71
+ auto const* const failed_scenario_seqs = PGM_failed_scenarios(handle_ptr);
72
+ auto const* const failed_scenario_messages = PGM_batch_errors(handle_ptr);
73
+ for (Idx i = 0; i < n_failed_scenarios; ++i) {
74
+ failed_scenarios[i] =
75
+ PowerGridBatchError::FailedScenario{// NOLINT(modernize-use-designated-initializers)
76
+ failed_scenario_seqs[i], failed_scenario_messages[i]};
77
+ }
78
+ clear_error();
79
+ throw PowerGridBatchError{error_message, std::move(failed_scenarios)};
80
+ }
81
+ case PGM_serialization_error:
82
+ clear_error();
83
+ throw PowerGridSerializationError{error_message};
84
+ default:
85
+ clear_error();
86
+ throw PowerGridError{error_message};
87
+ }
88
+ }
89
+
90
+ template <typename Func, typename... Args> auto call_with(Func&& func, Args&&... args) const {
91
+ if constexpr (std::is_void_v<decltype(std::forward<Func>(func)(get(), std::forward<Args>(args)...))>) {
92
+ std::forward<Func>(func)(get(), std::forward<Args>(args)...);
93
+ check_error();
94
+ } else {
95
+ auto result = std::forward<Func>(func)(get(), std::forward<Args>(args)...);
96
+ check_error();
97
+ return result;
98
+ }
99
+ }
100
+
101
+ private:
102
+ // For handle the const semantics are not needed.
103
+ // It is meant to be mutated even in const situations.
104
+ std::unique_ptr<RawHandle, detail::DeleterFunctor<&PGM_destroy_handle>> handle_{PGM_create_handle()};
105
+ };
106
+ } // namespace power_grid_model_cpp
107
+
108
+ #endif // POWER_GRID_MODEL_CPP_HANDLE_HPP