Skip to content

Commit 53e79c7

Browse files
fix merge conflicts
Signed-off-by: Laurynas Jagutis <[email protected]>
2 parents c2ebbbf + d9ec3fe commit 53e79c7

File tree

2 files changed

+16
-104
lines changed

2 files changed

+16
-104
lines changed

src/power_grid_model_io_native/_core/error_handling.py

Lines changed: 14 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -6,110 +6,25 @@
66
Error handling
77
"""
88

9-
import re
10-
11-
from power_grid_model.errors import (
12-
AutomaticTapCalculationError,
13-
ConflictID,
14-
ConflictVoltage,
15-
IDNotFound,
16-
IDWrongType,
17-
InvalidArguments,
18-
InvalidBranch,
19-
InvalidBranch3,
20-
InvalidCalculationMethod,
21-
InvalidMeasuredObject,
22-
InvalidRegulatedObject,
23-
InvalidShortCircuitPhaseOrType,
24-
InvalidTransformerClock,
25-
IterationDiverge,
26-
MaxIterationReached,
27-
MissingCaseForEnumError,
28-
NotObservableError,
9+
from power_grid_model._core.error_handling import (
10+
PGM_NO_ERROR,
11+
PGM_REGULAR_ERROR,
12+
PGM_SERIALIZATION_ERROR,
13+
VALIDATOR_MSG,
2914
PowerGridBatchError,
30-
PowerGridDatasetError,
31-
PowerGridError,
32-
PowerGridNotImplementedError,
3315
PowerGridSerializationError,
34-
PowerGridUnreachableHitError,
35-
SparseMatrixError,
16+
_interpret_error,
3617
)
3718

3819
from power_grid_model_io_native._core.power_grid_model_io_core import pgm_io_core as pgmic
3920

40-
VALIDATOR_MSG = "\nTry validate_input_data() or validate_batch_data() to validate your data.\n"
41-
# error codes
42-
PGM_NO_ERROR = 0
43-
PGM_REGULAR_ERROR = 1
44-
PGM_BATCH_ERROR = 2
45-
PGM_SERIALIZATION_ERROR = 3
46-
47-
_MISSING_CASE_FOR_ENUM_RE = re.compile(r" is not implemented for (.+) #(-?\d+)!\n")
48-
_INVALID_ARGUMENTS_RE = re.compile(r" is not implemented for ") # multiple different flavors
49-
_CONFLICT_VOLTAGE_RE = re.compile(
50-
r"Conflicting voltage for line (-?\d+)\n voltage at from node (-?\d+) is (.*)\n"
51-
r" voltage at to node (-?\d+) is (.*)\n"
52-
)
53-
_INVALID_BRANCH_RE = re.compile(r"Branch (-?\d+) has the same from- and to-node (-?\d+),\n This is not allowed!\n")
54-
_INVALID_BRANCH3_RE = re.compile(
55-
r"Branch3 (-?\d+) is connected to the same node at least twice. Node 1\/2\/3: (-?\d+)\/(-?\d+)\/(-?\d+),\n"
56-
r" This is not allowed!\n"
57-
)
58-
_INVALID_TRANSFORMER_CLOCK_RE = re.compile(r"Invalid clock for transformer (-?\d+), clock (-?\d+)\n")
59-
_SPARSE_MATRIX_ERROR_RE = re.compile(r"Sparse matrix error") # multiple different flavors
60-
_NOT_OBSERVABLE_ERROR_RE = re.compile(r"Not enough measurements available for state estimation.\n")
61-
_ITERATION_DIVERGE_RE = re.compile(r"Iteration failed to converge") # potentially multiple different flavors
62-
_MAX_ITERATION_REACHED_RE = re.compile(r"Maximum number of iterations reached")
63-
_CONFLICT_ID_RE = re.compile(r"Conflicting id detected: (-?\d+)\n")
64-
_ID_NOT_FOUND_RE = re.compile(r"The id cannot be found: (-?\d+)\n")
65-
_INVALID_MEASURED_OBJECT_RE = re.compile(r"(\w+) measurement is not supported for object of type (\w+)")
66-
_INVALID_REGULATED_OBJECT_RE = re.compile(
67-
r"(\w+) regulator is not supported for object "
68-
) # potentially multiple different flavors
69-
_AUTOMATIC_TAP_CALCULATION_ERROR_RE = re.compile(
70-
r"Automatic tap changing regulator with tap_side at LV side is not supported. Found at id (-?\d+)\n"
71-
)
72-
_ID_WRONG_TYPE_RE = re.compile(r"Wrong type for object with id (-?\d+)\n")
73-
_INVALID_CALCULATION_METHOD_RE = re.compile(r"The calculation method is invalid for this calculation!")
74-
_INVALID_SHORT_CIRCUIT_PHASE_OR_TYPE_RE = re.compile(r"short circuit type") # multiple different flavors
75-
_POWER_GRID_DATASET_ERROR_RE = re.compile(r"Dataset error: ") # multiple different flavors
76-
_POWER_GRID_UNREACHABLE_HIT_RE = re.compile(r"Unreachable code hit when executing ") # multiple different flavors
77-
_POWER_GRID_SEARCH_OPT_INCMPT_RE = re.compile(r"Search method is incompatible with optimization strategy: ")
78-
_POWER_GRID_NOT_IMPLEMENTED_ERROR_RE = re.compile(r"The functionality is either not supported or not yet implemented!")
79-
80-
_ERROR_MESSAGE_PATTERNS = {
81-
_MISSING_CASE_FOR_ENUM_RE: MissingCaseForEnumError,
82-
_INVALID_ARGUMENTS_RE: InvalidArguments,
83-
_CONFLICT_VOLTAGE_RE: ConflictVoltage,
84-
_INVALID_BRANCH_RE: InvalidBranch,
85-
_INVALID_BRANCH3_RE: InvalidBranch3,
86-
_INVALID_TRANSFORMER_CLOCK_RE: InvalidTransformerClock,
87-
_SPARSE_MATRIX_ERROR_RE: SparseMatrixError,
88-
_NOT_OBSERVABLE_ERROR_RE: NotObservableError,
89-
_ITERATION_DIVERGE_RE: IterationDiverge,
90-
_MAX_ITERATION_REACHED_RE: MaxIterationReached,
91-
_CONFLICT_ID_RE: ConflictID,
92-
_ID_NOT_FOUND_RE: IDNotFound,
93-
_INVALID_MEASURED_OBJECT_RE: InvalidMeasuredObject,
94-
_INVALID_REGULATED_OBJECT_RE: InvalidRegulatedObject,
95-
_AUTOMATIC_TAP_CALCULATION_ERROR_RE: AutomaticTapCalculationError,
96-
_ID_WRONG_TYPE_RE: IDWrongType,
97-
_INVALID_CALCULATION_METHOD_RE: InvalidCalculationMethod,
98-
_INVALID_SHORT_CIRCUIT_PHASE_OR_TYPE_RE: InvalidShortCircuitPhaseOrType,
99-
_POWER_GRID_DATASET_ERROR_RE: PowerGridDatasetError,
100-
_POWER_GRID_UNREACHABLE_HIT_RE: PowerGridUnreachableHitError,
101-
_POWER_GRID_SEARCH_OPT_INCMPT_RE: PowerGridUnreachableHitError,
102-
_POWER_GRID_NOT_IMPLEMENTED_ERROR_RE: PowerGridNotImplementedError,
103-
}
104-
105-
106-
def _interpret_error(message: str, decode_error: bool = True) -> PowerGridError:
107-
if decode_error:
108-
for pattern, type_ in _ERROR_MESSAGE_PATTERNS.items():
109-
if pattern.search(message) is not None:
110-
return type_(message)
111-
112-
return PowerGridError(message)
21+
# def _interpret_error_pgm_io(message: str, decode_error: bool = True) -> PowerGridError:
22+
# if decode_error:
23+
# for pattern, type_ in _ERROR_MESSAGE_PATTERNS.items():
24+
# if pattern.search(message) is not None:
25+
# return type_(message)
26+
27+
# return PowerGridError(message)
11328

11429

11530
def find_error(batch_size: int = 1, decode_error: bool = True) -> RuntimeError | None:
@@ -123,18 +38,14 @@ def find_error(batch_size: int = 1, decode_error: bool = True) -> RuntimeError |
12338
Returns: error object, can be none
12439
12540
"""
41+
_ = batch_size
12642
error_code: int = pgmic.error_code()
12743
if error_code == PGM_NO_ERROR:
12844
return None
12945
if error_code == PGM_REGULAR_ERROR:
13046
error_message = pgmic.error_message()
13147
error_message += VALIDATOR_MSG
13248
return _interpret_error(error_message, decode_error=decode_error)
133-
if error_code == PGM_BATCH_ERROR:
134-
_ = batch_size
135-
error_message = "There are errors in the batch calculation." + VALIDATOR_MSG
136-
error = PowerGridBatchError(error_message)
137-
return error
13849
if error_code == PGM_SERIALIZATION_ERROR:
13950
return PowerGridSerializationError(pgmic.error_message())
14051
return RuntimeError("Unknown error!")

tests/unit/test_vnf_converter.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
# SPDX-License-Identifier: MPL-2.0
44

55
import pytest
6+
from power_grid_model._core.error_handling import InvalidArguments
67

7-
from power_grid_model_io_native._core.error_handling import InvalidArguments, assert_no_error
8+
from power_grid_model_io_native._core.error_handling import assert_no_error
89
from power_grid_model_io_native._core.pgm_vnf_converter import PgmVnfConverter
910

1011

0 commit comments

Comments
 (0)