power-grid-model 1.10.99__py3-none-macosx_13_0_x86_64.whl → 1.12.104__py3-none-macosx_13_0_x86_64.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.
- power_grid_model/__init__.py +25 -0
- power_grid_model/_core/buffer_handling.py +32 -17
- power_grid_model/_core/data_handling.py +69 -15
- power_grid_model/_core/data_types.py +143 -0
- power_grid_model/_core/dataset_definitions.py +4 -6
- power_grid_model/_core/enum.py +226 -0
- power_grid_model/_core/error_handling.py +12 -11
- power_grid_model/_core/errors.py +130 -0
- power_grid_model/_core/options.py +15 -13
- power_grid_model/_core/power_grid_core.py +30 -50
- power_grid_model/_core/power_grid_dataset.py +56 -39
- power_grid_model/_core/power_grid_meta.py +38 -20
- power_grid_model/_core/power_grid_model.py +394 -61
- power_grid_model/_core/power_grid_model_c/__init__.py +3 -0
- power_grid_model/_core/power_grid_model_c/get_pgm_dll_path.py +63 -0
- power_grid_model/_core/power_grid_model_c/include/power_grid_model_c/basics.h +255 -0
- power_grid_model/_core/power_grid_model_c/include/power_grid_model_c/buffer.h +108 -0
- power_grid_model/_core/power_grid_model_c/include/power_grid_model_c/dataset.h +332 -0
- power_grid_model/_core/power_grid_model_c/include/power_grid_model_c/dataset_definitions.h +1060 -0
- power_grid_model/_core/power_grid_model_c/include/power_grid_model_c/handle.h +99 -0
- power_grid_model/_core/power_grid_model_c/include/power_grid_model_c/meta_data.h +189 -0
- power_grid_model/_core/power_grid_model_c/include/power_grid_model_c/model.h +130 -0
- power_grid_model/_core/power_grid_model_c/include/power_grid_model_c/options.h +142 -0
- power_grid_model/_core/power_grid_model_c/include/power_grid_model_c/serialization.h +118 -0
- power_grid_model/_core/power_grid_model_c/include/power_grid_model_c.h +36 -0
- power_grid_model/_core/power_grid_model_c/include/power_grid_model_cpp/basics.hpp +65 -0
- power_grid_model/_core/power_grid_model_c/include/power_grid_model_cpp/buffer.hpp +61 -0
- power_grid_model/_core/power_grid_model_c/include/power_grid_model_cpp/dataset.hpp +224 -0
- power_grid_model/_core/power_grid_model_c/include/power_grid_model_cpp/handle.hpp +108 -0
- power_grid_model/_core/power_grid_model_c/include/power_grid_model_cpp/meta_data.hpp +84 -0
- power_grid_model/_core/power_grid_model_c/include/power_grid_model_cpp/model.hpp +63 -0
- power_grid_model/_core/power_grid_model_c/include/power_grid_model_cpp/options.hpp +52 -0
- power_grid_model/_core/power_grid_model_c/include/power_grid_model_cpp/serialization.hpp +124 -0
- power_grid_model/_core/power_grid_model_c/include/power_grid_model_cpp/utils.hpp +81 -0
- power_grid_model/_core/power_grid_model_c/include/power_grid_model_cpp.hpp +19 -0
- power_grid_model/_core/power_grid_model_c/lib/cmake/power_grid_model/power_grid_modelConfig.cmake +37 -0
- power_grid_model/_core/power_grid_model_c/lib/cmake/power_grid_model/power_grid_modelConfigVersion.cmake +65 -0
- power_grid_model/_core/power_grid_model_c/lib/cmake/power_grid_model/power_grid_modelTargets-release.cmake +19 -0
- power_grid_model/_core/power_grid_model_c/lib/cmake/power_grid_model/power_grid_modelTargets.cmake +144 -0
- power_grid_model/_core/power_grid_model_c/lib/libpower_grid_model_c.1.12.104.dylib +0 -0
- power_grid_model/_core/power_grid_model_c/lib/libpower_grid_model_c.dylib +0 -0
- power_grid_model/_core/power_grid_model_c/share/LICENSE +292 -0
- power_grid_model/_core/power_grid_model_c/share/README.md +15 -0
- power_grid_model/_core/serialization.py +20 -18
- power_grid_model/_core/typing.py +20 -0
- power_grid_model/{_utils.py → _core/utils.py} +44 -29
- power_grid_model/data_types.py +185 -183
- power_grid_model/enum.py +16 -216
- power_grid_model/errors.py +29 -119
- power_grid_model/typing.py +7 -12
- power_grid_model/utils.py +150 -21
- power_grid_model/validation/__init__.py +11 -0
- power_grid_model/validation/_rules.py +304 -37
- power_grid_model/validation/_validation.py +292 -100
- power_grid_model/validation/assertions.py +2 -1
- power_grid_model/validation/errors.py +98 -16
- power_grid_model/validation/utils.py +26 -31
- {power_grid_model-1.10.99.dist-info → power_grid_model-1.12.104.dist-info}/METADATA +36 -43
- power_grid_model-1.12.104.dist-info/RECORD +65 -0
- {power_grid_model-1.10.99.dist-info → power_grid_model-1.12.104.dist-info}/WHEEL +1 -1
- power_grid_model-1.12.104.dist-info/entry_points.txt +3 -0
- power_grid_model/_core/_power_grid_core.so +0 -0
- power_grid_model-1.10.99.dist-info/RECORD +0 -32
- power_grid_model-1.10.99.dist-info/top_level.txt +0 -1
- {power_grid_model-1.10.99.dist-info → power_grid_model-1.12.104.dist-info}/licenses/LICENSE +0 -0
power_grid_model/__init__.py
CHANGED
|
@@ -13,6 +13,7 @@ from power_grid_model._core.power_grid_meta import (
|
|
|
13
13
|
)
|
|
14
14
|
from power_grid_model._core.power_grid_model import PowerGridModel
|
|
15
15
|
from power_grid_model.enum import (
|
|
16
|
+
AngleMeasurementType,
|
|
16
17
|
Branch3Side,
|
|
17
18
|
BranchSide,
|
|
18
19
|
CalculationMethod,
|
|
@@ -27,3 +28,27 @@ from power_grid_model.enum import (
|
|
|
27
28
|
WindingType,
|
|
28
29
|
)
|
|
29
30
|
from power_grid_model.typing import ComponentAttributeMapping
|
|
31
|
+
|
|
32
|
+
__all__ = [
|
|
33
|
+
"AngleMeasurementType",
|
|
34
|
+
"Branch3Side",
|
|
35
|
+
"BranchSide",
|
|
36
|
+
"CalculationMethod",
|
|
37
|
+
"CalculationType",
|
|
38
|
+
"ComponentAttributeFilterOptions",
|
|
39
|
+
"ComponentAttributeMapping",
|
|
40
|
+
"ComponentType",
|
|
41
|
+
"DatasetType",
|
|
42
|
+
"FaultPhase",
|
|
43
|
+
"FaultType",
|
|
44
|
+
"LoadGenType",
|
|
45
|
+
"MeasuredTerminalType",
|
|
46
|
+
"PowerGridModel",
|
|
47
|
+
"ShortCircuitVoltageScaling",
|
|
48
|
+
"TapChangingStrategy",
|
|
49
|
+
"WindingType",
|
|
50
|
+
"attribute_dtype",
|
|
51
|
+
"attribute_empty_value",
|
|
52
|
+
"initialize_array",
|
|
53
|
+
"power_grid_meta_data",
|
|
54
|
+
]
|
|
@@ -11,26 +11,26 @@ from typing import cast
|
|
|
11
11
|
|
|
12
12
|
import numpy as np
|
|
13
13
|
|
|
14
|
+
from power_grid_model._core.data_types import (
|
|
15
|
+
AttributeType,
|
|
16
|
+
ComponentData,
|
|
17
|
+
DenseBatchData,
|
|
18
|
+
IndexPointer,
|
|
19
|
+
SingleComponentData,
|
|
20
|
+
SparseBatchArray,
|
|
21
|
+
SparseBatchData,
|
|
22
|
+
)
|
|
14
23
|
from power_grid_model._core.error_handling import VALIDATOR_MSG
|
|
15
24
|
from power_grid_model._core.index_integer import IdxC, IdxNp
|
|
16
25
|
from power_grid_model._core.power_grid_core import IdxPtr, VoidPtr
|
|
17
26
|
from power_grid_model._core.power_grid_meta import ComponentMetaData
|
|
18
|
-
from power_grid_model.
|
|
27
|
+
from power_grid_model._core.utils import (
|
|
19
28
|
_extract_data_from_component_data,
|
|
20
29
|
_extract_indptr,
|
|
21
30
|
check_indptr_consistency,
|
|
22
31
|
is_columnar,
|
|
23
32
|
is_sparse,
|
|
24
33
|
)
|
|
25
|
-
from power_grid_model.data_types import (
|
|
26
|
-
AttributeType,
|
|
27
|
-
ComponentData,
|
|
28
|
-
DenseBatchData,
|
|
29
|
-
IndexPointer,
|
|
30
|
-
SingleComponentData,
|
|
31
|
-
SparseBatchArray,
|
|
32
|
-
SparseBatchData,
|
|
33
|
-
)
|
|
34
34
|
|
|
35
35
|
|
|
36
36
|
@dataclass
|
|
@@ -117,9 +117,15 @@ def _get_raw_attribute_data_view(data: np.ndarray, schema: ComponentMetaData, at
|
|
|
117
117
|
Returns:
|
|
118
118
|
a raw view on the data set.
|
|
119
119
|
"""
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
120
|
+
dense_batch_ndim = 2
|
|
121
|
+
|
|
122
|
+
attr_schema = schema.dtype[attribute]
|
|
123
|
+
attr_shape_start = data.ndim - attr_schema.ndim
|
|
124
|
+
dataset_shape = data.shape[:attr_shape_start]
|
|
125
|
+
attr_shape = data.shape[attr_shape_start:]
|
|
126
|
+
if len(dataset_shape) <= dense_batch_ndim and attr_shape == attr_schema.shape:
|
|
127
|
+
return _get_raw_data_view(data, dtype=schema.dtype[attribute].base)
|
|
128
|
+
raise ValueError("Given data has a different schema than supported.")
|
|
123
129
|
|
|
124
130
|
|
|
125
131
|
def _get_indptr_view(indptr: np.ndarray) -> IdxPtr: # type: ignore[valid-type]
|
|
@@ -185,15 +191,24 @@ def _get_dense_buffer_properties(
|
|
|
185
191
|
if actual_ndim not in (1, 2):
|
|
186
192
|
raise ValueError(f"Array can only be 1D or 2D. {VALIDATOR_MSG}")
|
|
187
193
|
|
|
188
|
-
|
|
189
|
-
|
|
194
|
+
single_dataset_ndim = 1
|
|
195
|
+
batch_dataset_ndim = 2
|
|
196
|
+
|
|
197
|
+
actual_is_batch = actual_ndim == batch_dataset_ndim
|
|
198
|
+
actual_batch_size = shape[0] if actual_is_batch else single_dataset_ndim
|
|
190
199
|
n_elements_per_scenario = shape[-1]
|
|
191
200
|
n_total_elements = actual_batch_size * n_elements_per_scenario
|
|
192
201
|
|
|
193
202
|
if is_batch is not None and is_batch != actual_is_batch:
|
|
194
|
-
raise ValueError(
|
|
203
|
+
raise ValueError(
|
|
204
|
+
f"Incorrect/inconsistent data provided: {'batch' if actual_is_batch else 'single'} "
|
|
205
|
+
f"data provided but {'batch' if is_batch else 'single'} data expected. {VALIDATOR_MSG}"
|
|
206
|
+
)
|
|
195
207
|
if batch_size is not None and batch_size != actual_batch_size:
|
|
196
|
-
raise ValueError(
|
|
208
|
+
raise ValueError(
|
|
209
|
+
f"Incorrect/inconsistent batch size provided: {actual_batch_size} scenarios provided "
|
|
210
|
+
f"but {batch_size} scenarios expected. {VALIDATOR_MSG}"
|
|
211
|
+
)
|
|
197
212
|
|
|
198
213
|
return BufferProperties(
|
|
199
214
|
is_sparse=is_sparse_property,
|
|
@@ -6,16 +6,26 @@
|
|
|
6
6
|
Data handling
|
|
7
7
|
"""
|
|
8
8
|
|
|
9
|
+
from typing import Literal, overload
|
|
10
|
+
|
|
9
11
|
import numpy as np
|
|
10
12
|
|
|
11
|
-
from power_grid_model._core.
|
|
13
|
+
from power_grid_model._core.data_types import (
|
|
14
|
+
BatchDataset,
|
|
15
|
+
Dataset,
|
|
16
|
+
DenseBatchArray,
|
|
17
|
+
SingleArray,
|
|
18
|
+
SingleColumnarData,
|
|
19
|
+
SingleDataset,
|
|
20
|
+
)
|
|
21
|
+
from power_grid_model._core.dataset_definitions import ComponentType, ComponentTypeVar, DatasetType
|
|
22
|
+
from power_grid_model._core.enum import CalculationType, ComponentAttributeFilterOptions
|
|
23
|
+
from power_grid_model._core.errors import PowerGridUnreachableHitError
|
|
12
24
|
from power_grid_model._core.power_grid_dataset import CConstDataset, CMutableDataset
|
|
13
25
|
from power_grid_model._core.power_grid_meta import initialize_array, power_grid_meta_data
|
|
14
|
-
from power_grid_model.
|
|
15
|
-
from power_grid_model.
|
|
16
|
-
from power_grid_model.
|
|
17
|
-
from power_grid_model.errors import PowerGridUnreachableHitError
|
|
18
|
-
from power_grid_model.typing import ComponentAttributeMapping
|
|
26
|
+
from power_grid_model._core.typing import ComponentAttributeMapping, ComponentAttributeMappingDict
|
|
27
|
+
from power_grid_model._core.utils import process_data_filter
|
|
28
|
+
from power_grid_model.data_types import DenseBatchColumnarData
|
|
19
29
|
|
|
20
30
|
|
|
21
31
|
def get_output_type(*, calculation_type: CalculationType, symmetric: bool) -> DatasetType:
|
|
@@ -38,7 +48,7 @@ def get_output_type(*, calculation_type: CalculationType, symmetric: bool) -> Da
|
|
|
38
48
|
if calculation_type == CalculationType.short_circuit:
|
|
39
49
|
return DatasetType.sc_output
|
|
40
50
|
|
|
41
|
-
raise NotImplementedError
|
|
51
|
+
raise NotImplementedError
|
|
42
52
|
|
|
43
53
|
|
|
44
54
|
def prepare_input_view(input_data: SingleDataset) -> CConstDataset:
|
|
@@ -85,6 +95,54 @@ def prepare_output_view(output_data: Dataset, output_type: DatasetType) -> CMuta
|
|
|
85
95
|
return CMutableDataset(output_data, dataset_type=output_type)
|
|
86
96
|
|
|
87
97
|
|
|
98
|
+
@overload
|
|
99
|
+
def create_output_data(
|
|
100
|
+
output_component_types: None | set[ComponentTypeVar] | list[ComponentTypeVar],
|
|
101
|
+
output_type: DatasetType,
|
|
102
|
+
all_component_count: dict[ComponentType, int],
|
|
103
|
+
is_batch: Literal[False],
|
|
104
|
+
batch_size: int,
|
|
105
|
+
) -> dict[ComponentType, SingleArray]: ...
|
|
106
|
+
@overload
|
|
107
|
+
def create_output_data(
|
|
108
|
+
output_component_types: None | set[ComponentTypeVar] | list[ComponentTypeVar],
|
|
109
|
+
output_type: DatasetType,
|
|
110
|
+
all_component_count: dict[ComponentType, int],
|
|
111
|
+
is_batch: Literal[True],
|
|
112
|
+
batch_size: int,
|
|
113
|
+
) -> dict[ComponentType, DenseBatchArray]: ...
|
|
114
|
+
@overload
|
|
115
|
+
def create_output_data(
|
|
116
|
+
output_component_types: ComponentAttributeFilterOptions,
|
|
117
|
+
output_type: DatasetType,
|
|
118
|
+
all_component_count: dict[ComponentType, int],
|
|
119
|
+
is_batch: Literal[False],
|
|
120
|
+
batch_size: int,
|
|
121
|
+
) -> dict[ComponentType, SingleColumnarData]: ...
|
|
122
|
+
@overload
|
|
123
|
+
def create_output_data(
|
|
124
|
+
output_component_types: ComponentAttributeFilterOptions,
|
|
125
|
+
output_type: DatasetType,
|
|
126
|
+
all_component_count: dict[ComponentType, int],
|
|
127
|
+
is_batch: Literal[True],
|
|
128
|
+
batch_size: int,
|
|
129
|
+
) -> dict[ComponentType, DenseBatchColumnarData]: ...
|
|
130
|
+
@overload
|
|
131
|
+
def create_output_data(
|
|
132
|
+
output_component_types: ComponentAttributeMappingDict,
|
|
133
|
+
output_type: DatasetType,
|
|
134
|
+
all_component_count: dict[ComponentType, int],
|
|
135
|
+
is_batch: Literal[False],
|
|
136
|
+
batch_size: int,
|
|
137
|
+
) -> SingleDataset: ...
|
|
138
|
+
@overload
|
|
139
|
+
def create_output_data(
|
|
140
|
+
output_component_types: ComponentAttributeMappingDict,
|
|
141
|
+
output_type: DatasetType,
|
|
142
|
+
all_component_count: dict[ComponentType, int],
|
|
143
|
+
is_batch: Literal[True],
|
|
144
|
+
batch_size: int,
|
|
145
|
+
) -> BatchDataset: ...
|
|
88
146
|
def create_output_data(
|
|
89
147
|
output_component_types: ComponentAttributeMapping,
|
|
90
148
|
output_type: DatasetType,
|
|
@@ -96,7 +154,7 @@ def create_output_data(
|
|
|
96
154
|
Create the output dataset based on component and batch size from the model; and output attributes requested by user.
|
|
97
155
|
|
|
98
156
|
Args:
|
|
99
|
-
output_component_types:
|
|
157
|
+
output_component_types (ComponentAttributeMapping):
|
|
100
158
|
the output components the user seeks to extract
|
|
101
159
|
output_type:
|
|
102
160
|
the type of output that the user will see (as per the calculation options)
|
|
@@ -118,11 +176,7 @@ def create_output_data(
|
|
|
118
176
|
result_dict: Dataset = {}
|
|
119
177
|
|
|
120
178
|
for name, count in all_component_count.items():
|
|
121
|
-
|
|
122
|
-
if is_batch:
|
|
123
|
-
shape: tuple[int] | tuple[int, int] = (batch_size, count)
|
|
124
|
-
else:
|
|
125
|
-
shape = (count,)
|
|
179
|
+
shape: tuple[int, int] | int = (batch_size, count) if is_batch else count
|
|
126
180
|
|
|
127
181
|
requested_component = processed_output_types[name]
|
|
128
182
|
dtype = power_grid_meta_data[output_type][name].dtype
|
|
@@ -134,8 +188,8 @@ def create_output_data(
|
|
|
134
188
|
ComponentAttributeFilterOptions.everything,
|
|
135
189
|
ComponentAttributeFilterOptions.relevant,
|
|
136
190
|
]:
|
|
137
|
-
result_dict[name] = {attr: np.empty(shape, dtype=dtype[attr]) for attr in dtype.names}
|
|
191
|
+
result_dict[name] = {attr: np.empty(shape=shape, dtype=dtype[attr]) for attr in dtype.names}
|
|
138
192
|
elif isinstance(requested_component, list | set):
|
|
139
|
-
result_dict[name] = {attr: np.empty(shape, dtype=dtype[attr]) for attr in requested_component}
|
|
193
|
+
result_dict[name] = {attr: np.empty(shape=shape, dtype=dtype[attr]) for attr in requested_component}
|
|
140
194
|
|
|
141
195
|
return result_dict
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: Contributors to the Power Grid Model project <powergridmodel@lfenergy.org>
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
|
|
5
|
+
"""
|
|
6
|
+
Data types involving PGM datasets.
|
|
7
|
+
|
|
8
|
+
Data types for library-internal use. In an attempt to clarify type hints, some types
|
|
9
|
+
have been defined and explained in this file.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from typing import TypeAlias, TypedDict, TypeVar
|
|
13
|
+
|
|
14
|
+
import numpy as np
|
|
15
|
+
|
|
16
|
+
from power_grid_model._core.dataset_definitions import ComponentType, ComponentTypeVar
|
|
17
|
+
|
|
18
|
+
SingleArray: TypeAlias = np.ndarray
|
|
19
|
+
|
|
20
|
+
AttributeType: TypeAlias = str
|
|
21
|
+
|
|
22
|
+
SingleColumn: TypeAlias = np.ndarray
|
|
23
|
+
|
|
24
|
+
DenseBatchArray: TypeAlias = np.ndarray
|
|
25
|
+
|
|
26
|
+
SingleColumnarData = dict[AttributeType, SingleColumn]
|
|
27
|
+
|
|
28
|
+
_SingleComponentData = TypeVar("_SingleComponentData", SingleArray, SingleColumnarData) # deduction helper
|
|
29
|
+
SingleComponentData = SingleArray | SingleColumnarData
|
|
30
|
+
|
|
31
|
+
SingleRowBasedDataset = dict[ComponentTypeVar, SingleArray]
|
|
32
|
+
SingleColumnarDataset = dict[ComponentTypeVar, SingleColumnarData]
|
|
33
|
+
SingleDataset = dict[ComponentTypeVar, _SingleComponentData]
|
|
34
|
+
|
|
35
|
+
BatchList = list[SingleDataset]
|
|
36
|
+
|
|
37
|
+
BatchColumn: TypeAlias = np.ndarray
|
|
38
|
+
|
|
39
|
+
DenseBatchColumnarData = dict[AttributeType, BatchColumn]
|
|
40
|
+
|
|
41
|
+
IndexPointer: TypeAlias = np.ndarray
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class SparseBatchColumnarData(TypedDict):
|
|
45
|
+
"""
|
|
46
|
+
Sparse batch columnar data is a dictionary containing the keys `indptr` and `data`.
|
|
47
|
+
|
|
48
|
+
- data: a :class:`SingleColumnarData`. The exact supported attribute columns depend on the component type.
|
|
49
|
+
- indptr: an :class:`IndexPointer` representing the start and end indices for each batch scenario.
|
|
50
|
+
|
|
51
|
+
- Examples:
|
|
52
|
+
|
|
53
|
+
- structure: {"indptr": :class:`IndexPointer`, "data": :class:`SingleColumnarData`}
|
|
54
|
+
- concrete example: {"indptr": [0, 2, 2, 3], "data": {"id": [0, 1, 0], "status": [1, 1, 0]}}
|
|
55
|
+
|
|
56
|
+
- the scenario 0 sets the status of components with ids 0 and 1 to 1
|
|
57
|
+
(and keeps defaults for other components)
|
|
58
|
+
- scenario 1 keeps the default values for all components
|
|
59
|
+
- scenario 2 sets the status of component with id 0 to 0 (and keeps defaults for other components)
|
|
60
|
+
"""
|
|
61
|
+
|
|
62
|
+
indptr: IndexPointer
|
|
63
|
+
data: SingleColumnarData
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
class SparseBatchArray(TypedDict):
|
|
67
|
+
"""
|
|
68
|
+
A sparse batch array is a dictionary containing the keys `indptr` and `data`.
|
|
69
|
+
|
|
70
|
+
- data: a :class:`SingleArray`. The exact dtype depends on the type of component.
|
|
71
|
+
- indptr: an :class:`IndexPointer` representing the start and end indices for each batch scenario.
|
|
72
|
+
|
|
73
|
+
- Examples:
|
|
74
|
+
|
|
75
|
+
- structure: {"indptr": :class:`IndexPointer`, "data": :class:`SingleArray`}
|
|
76
|
+
- concrete example: {"indptr": [0, 2, 2, 3], "data": [(0, 1, 1), (1, 1, 1), (0, 0, 0)]}
|
|
77
|
+
|
|
78
|
+
- the scenario 0 sets the statuses of components with ids 0 and 1 to 1
|
|
79
|
+
(and keeps defaults for other components)
|
|
80
|
+
- scenario 1 keeps the default values for all components
|
|
81
|
+
- scenario 2 sets the statuses of component with id 0 to 0 (and keeps defaults for other components)
|
|
82
|
+
"""
|
|
83
|
+
|
|
84
|
+
indptr: IndexPointer
|
|
85
|
+
data: SingleArray
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
SparseBatchData = SparseBatchArray | SparseBatchColumnarData
|
|
89
|
+
|
|
90
|
+
SparseDataComponentType: TypeAlias = str
|
|
91
|
+
|
|
92
|
+
BatchColumnarData = DenseBatchColumnarData | SparseBatchColumnarData
|
|
93
|
+
|
|
94
|
+
ColumnarData = SingleColumnarData | BatchColumnarData
|
|
95
|
+
BatchArray = DenseBatchArray | SparseBatchArray
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
BatchComponentData = BatchArray | BatchColumnarData
|
|
99
|
+
|
|
100
|
+
_BatchComponentData = TypeVar("_BatchComponentData", BatchArray, BatchColumnarData) # deduction helper
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
BatchDataset = dict[ComponentTypeVar, _BatchComponentData]
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
DataArray = SingleArray | BatchArray
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
_ComponentData = TypeVar("_ComponentData", SingleComponentData, BatchComponentData) # deduction helper
|
|
110
|
+
ComponentData = DataArray | ColumnarData
|
|
111
|
+
|
|
112
|
+
Dataset = dict[ComponentTypeVar, _ComponentData]
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
DenseBatchData = DenseBatchArray | DenseBatchColumnarData
|
|
116
|
+
|
|
117
|
+
# overloads that only match on latest PGM type
|
|
118
|
+
SingleRowBasedOutputDataset = dict[ComponentType, SingleArray]
|
|
119
|
+
SingleColumnarOutputDataset = dict[ComponentType, SingleColumnarData]
|
|
120
|
+
SingleOutputDataset = dict[ComponentType, SingleComponentData]
|
|
121
|
+
DenseBatchRowBasedOutputDataset = dict[ComponentType, DenseBatchArray]
|
|
122
|
+
DenseBatchColumnarOutputDataset = dict[ComponentType, DenseBatchColumnarData]
|
|
123
|
+
DenseBatchOutputDataset = dict[ComponentType, DenseBatchData]
|
|
124
|
+
OutputDataset = dict[ComponentType, ComponentData]
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
NominalValue = int
|
|
128
|
+
|
|
129
|
+
RealValue = float
|
|
130
|
+
|
|
131
|
+
AsymValue = tuple[RealValue, RealValue, RealValue]
|
|
132
|
+
|
|
133
|
+
AttributeValue = RealValue | NominalValue | AsymValue
|
|
134
|
+
|
|
135
|
+
Component = dict[AttributeType, AttributeValue | str]
|
|
136
|
+
|
|
137
|
+
ComponentList = list[Component]
|
|
138
|
+
|
|
139
|
+
SinglePythonDataset = dict[ComponentTypeVar, ComponentList]
|
|
140
|
+
|
|
141
|
+
BatchPythonDataset = list[SinglePythonDataset]
|
|
142
|
+
|
|
143
|
+
PythonDataset = SinglePythonDataset | BatchPythonDataset
|
|
@@ -6,13 +6,12 @@
|
|
|
6
6
|
|
|
7
7
|
# This file is automatically generated. DO NOT modify it manually!
|
|
8
8
|
|
|
9
|
+
from collections.abc import Mapping
|
|
9
10
|
from enum import Enum, EnumMeta
|
|
10
|
-
from typing import Any,
|
|
11
|
+
from typing import Any, TypeAlias, TypeVar
|
|
11
12
|
|
|
12
13
|
# fmt: off
|
|
13
14
|
|
|
14
|
-
# pylint: disable=invalid-name
|
|
15
|
-
|
|
16
15
|
class _MetaEnum(EnumMeta):
|
|
17
16
|
def __contains__(cls, member):
|
|
18
17
|
"""
|
|
@@ -24,7 +23,7 @@ class _MetaEnum(EnumMeta):
|
|
|
24
23
|
Returns:
|
|
25
24
|
bool: True if the member is part of the Enum, False otherwise.
|
|
26
25
|
"""
|
|
27
|
-
return member in cls.__members__
|
|
26
|
+
return member in cls.__members__
|
|
28
27
|
|
|
29
28
|
|
|
30
29
|
class DatasetType(str, Enum, metaclass=_MetaEnum):
|
|
@@ -56,6 +55,7 @@ class ComponentType(str, Enum, metaclass=_MetaEnum):
|
|
|
56
55
|
|
|
57
56
|
node = "node"
|
|
58
57
|
line = "line"
|
|
58
|
+
asym_line = "asym_line"
|
|
59
59
|
link = "link"
|
|
60
60
|
generic_branch = "generic_branch"
|
|
61
61
|
transformer = "transformer"
|
|
@@ -76,8 +76,6 @@ class ComponentType(str, Enum, metaclass=_MetaEnum):
|
|
|
76
76
|
fault = "fault"
|
|
77
77
|
|
|
78
78
|
|
|
79
|
-
# pylint: enable=invalid-name
|
|
80
|
-
|
|
81
79
|
DatasetTypeLike: TypeAlias = DatasetType | str
|
|
82
80
|
DatasetTypeVar = TypeVar("DatasetTypeVar", bound=DatasetTypeLike) # helper used for type deduction
|
|
83
81
|
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: Contributors to the Power Grid Model project <powergridmodel@lfenergy.org>
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
|
|
5
|
+
"""
|
|
6
|
+
Common enumerations for library-internal use.
|
|
7
|
+
|
|
8
|
+
Note: these enumeration match the C++ arithmetic core, so don't change the values unless you change them in C++ as well
|
|
9
|
+
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from enum import IntEnum
|
|
13
|
+
|
|
14
|
+
# Value names are defined in lower case instead of upper case
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class CalculationType(IntEnum):
|
|
18
|
+
"""Calculation Types"""
|
|
19
|
+
|
|
20
|
+
power_flow = 0
|
|
21
|
+
state_estimation = 1
|
|
22
|
+
short_circuit = 2
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class CalculationMethod(IntEnum):
|
|
26
|
+
"""Calculation Methods"""
|
|
27
|
+
|
|
28
|
+
linear = 0
|
|
29
|
+
newton_raphson = 1
|
|
30
|
+
iterative_linear = 2
|
|
31
|
+
iterative_current = 3
|
|
32
|
+
linear_current = 4
|
|
33
|
+
iec60909 = 5
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class TapChangingStrategy(IntEnum):
|
|
37
|
+
"""Tap Changing Strategies"""
|
|
38
|
+
|
|
39
|
+
disabled = 0
|
|
40
|
+
"""
|
|
41
|
+
Disable automatic tap adjustment
|
|
42
|
+
"""
|
|
43
|
+
any_valid_tap = 1
|
|
44
|
+
"""
|
|
45
|
+
Adjust tap position automatically; optimize for any value in the voltage band
|
|
46
|
+
"""
|
|
47
|
+
min_voltage_tap = 2
|
|
48
|
+
"""
|
|
49
|
+
Adjust tap position automatically; optimize for the lower end of the voltage band
|
|
50
|
+
"""
|
|
51
|
+
max_voltage_tap = 3
|
|
52
|
+
"""
|
|
53
|
+
Adjust tap position automatically; optimize for the higher end of the voltage band
|
|
54
|
+
"""
|
|
55
|
+
fast_any_tap = 4
|
|
56
|
+
"""
|
|
57
|
+
Adjust tap position automatically; optimize for any value in the voltage band; binary search
|
|
58
|
+
"""
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
class AngleMeasurementType(IntEnum):
|
|
62
|
+
"""The type of the angle measurement for current sensors."""
|
|
63
|
+
|
|
64
|
+
local_angle = 0
|
|
65
|
+
"""
|
|
66
|
+
The angle is relative to the local voltage angle
|
|
67
|
+
"""
|
|
68
|
+
global_angle = 1
|
|
69
|
+
"""
|
|
70
|
+
The angle is relative to the global voltage angle.
|
|
71
|
+
"""
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
class ShortCircuitVoltageScaling(IntEnum):
|
|
75
|
+
"""Voltage scaling for short circuit calculations"""
|
|
76
|
+
|
|
77
|
+
minimum = 0
|
|
78
|
+
maximum = 1
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
class _ExperimentalFeatures(IntEnum):
|
|
82
|
+
"""Experimental features"""
|
|
83
|
+
|
|
84
|
+
disabled = 0
|
|
85
|
+
enabled = 1
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
class ComponentAttributeFilterOptions(IntEnum):
|
|
89
|
+
"""Filter option component or attribute"""
|
|
90
|
+
|
|
91
|
+
everything = 0
|
|
92
|
+
"""Filter all components/attributes"""
|
|
93
|
+
relevant = 1
|
|
94
|
+
"""Filter only non-empty components/attributes that contain non-NaN values"""
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
class LoadGenType(IntEnum):
|
|
98
|
+
"""Load and Generator Types"""
|
|
99
|
+
|
|
100
|
+
const_power = 0
|
|
101
|
+
const_impedance = 1
|
|
102
|
+
const_current = 2
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
class WindingType(IntEnum):
|
|
106
|
+
"""Transformer Winding Types"""
|
|
107
|
+
|
|
108
|
+
wye = 0
|
|
109
|
+
wye_n = 1
|
|
110
|
+
delta = 2
|
|
111
|
+
zigzag = 3
|
|
112
|
+
zigzag_n = 4
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
class BranchSide(IntEnum):
|
|
116
|
+
"""Branch Sides"""
|
|
117
|
+
|
|
118
|
+
from_side = 0
|
|
119
|
+
to_side = 1
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
class Branch3Side(IntEnum):
|
|
123
|
+
"""Branch3 Sides"""
|
|
124
|
+
|
|
125
|
+
side_1 = 0
|
|
126
|
+
side_2 = 1
|
|
127
|
+
side_3 = 2
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
class MeasuredTerminalType(IntEnum):
|
|
131
|
+
"""The type of asset measured by a (power) sensor"""
|
|
132
|
+
|
|
133
|
+
branch_from = 0
|
|
134
|
+
"""
|
|
135
|
+
Measuring the from-terminal between a branch (except link) and a node
|
|
136
|
+
"""
|
|
137
|
+
branch_to = 1
|
|
138
|
+
"""
|
|
139
|
+
Measuring the to-terminal between a branch (except link) and a node
|
|
140
|
+
"""
|
|
141
|
+
source = 2
|
|
142
|
+
"""
|
|
143
|
+
Measuring the terminal between a source and a node
|
|
144
|
+
"""
|
|
145
|
+
shunt = 3
|
|
146
|
+
"""
|
|
147
|
+
Measuring the terminal between a shunt and a node
|
|
148
|
+
"""
|
|
149
|
+
load = 4
|
|
150
|
+
"""
|
|
151
|
+
Measuring the terminal between a load and a node
|
|
152
|
+
"""
|
|
153
|
+
generator = 5
|
|
154
|
+
"""
|
|
155
|
+
Measuring the terminal between a generator and a node
|
|
156
|
+
"""
|
|
157
|
+
branch3_1 = 6
|
|
158
|
+
"""
|
|
159
|
+
Measuring the terminal-1 between a branch3 and a node
|
|
160
|
+
"""
|
|
161
|
+
branch3_2 = 7
|
|
162
|
+
"""
|
|
163
|
+
Measuring the terminal-2 between a branch3 and a node
|
|
164
|
+
"""
|
|
165
|
+
branch3_3 = 8
|
|
166
|
+
"""
|
|
167
|
+
Measuring the terminal-3 between a branch3 and a node
|
|
168
|
+
"""
|
|
169
|
+
node = 9
|
|
170
|
+
"""
|
|
171
|
+
Measuring the total power injection into a node
|
|
172
|
+
"""
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
class FaultType(IntEnum):
|
|
176
|
+
"""The type of fault represented by a fault component"""
|
|
177
|
+
|
|
178
|
+
three_phase = 0
|
|
179
|
+
single_phase_to_ground = 1
|
|
180
|
+
two_phase = 2
|
|
181
|
+
two_phase_to_ground = 3
|
|
182
|
+
nan = -128
|
|
183
|
+
"""
|
|
184
|
+
Unspecified fault type. Needs to be overloaded at the latest in the update_data
|
|
185
|
+
"""
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
class FaultPhase(IntEnum):
|
|
189
|
+
"""The faulty phase(s) affected by the provided fault type"""
|
|
190
|
+
|
|
191
|
+
abc = 0
|
|
192
|
+
"""
|
|
193
|
+
All phases are faulty in a three-phase fault
|
|
194
|
+
"""
|
|
195
|
+
a = 1
|
|
196
|
+
"""
|
|
197
|
+
The first phase is faulty in a single-phase-to-ground fault
|
|
198
|
+
"""
|
|
199
|
+
b = 2
|
|
200
|
+
"""
|
|
201
|
+
The second phase is faulty in a single-phase-to-ground fault
|
|
202
|
+
"""
|
|
203
|
+
c = 3
|
|
204
|
+
"""
|
|
205
|
+
The third phase is faulty in a single-phase-to-ground fault
|
|
206
|
+
"""
|
|
207
|
+
ab = 4
|
|
208
|
+
"""
|
|
209
|
+
The first and second phase are faulty in a two-phase or two-phase-to-ground fault
|
|
210
|
+
"""
|
|
211
|
+
ac = 5
|
|
212
|
+
"""
|
|
213
|
+
The first and third phase are faulty in a two-phase or two-phase-to-ground fault
|
|
214
|
+
"""
|
|
215
|
+
bc = 6
|
|
216
|
+
"""
|
|
217
|
+
The second and third phase are faulty in a two-phase or two-phase-to-ground fault
|
|
218
|
+
"""
|
|
219
|
+
default_value = -1
|
|
220
|
+
"""
|
|
221
|
+
Use the default fault phase. Depends on the fault_type.
|
|
222
|
+
"""
|
|
223
|
+
nan = -128
|
|
224
|
+
"""
|
|
225
|
+
Unspecified fault phase. Needs to be overloaded at the latest in the update_data
|
|
226
|
+
"""
|