Skip to content

Commit 279d0a9

Browse files
Merge pull request #923 from PowerGridModel/feature/step-up-transformer-tap-changer-python-validation
Automatic tap changer step up transformer support: Python validation
2 parents 5c600d9 + 057e245 commit 279d0a9

File tree

6 files changed

+3
-118
lines changed

6 files changed

+3
-118
lines changed

src/power_grid_model/validation/_rules.py

-47
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,10 @@
6666
SameValueError,
6767
TransformerClockError,
6868
TwoValuesZeroError,
69-
UnsupportedTransformerRegulationError,
7069
ValidationError,
7170
)
7271
from power_grid_model.validation.utils import (
7372
_eval_expression,
74-
_get_indexer,
7573
_get_mask,
7674
_get_valid_ids,
7775
_nan_type,
@@ -910,48 +908,3 @@ def _fault_phase_supported(fault_type: FaultType, fault_phase: FaultPhase):
910908
)
911909
]
912910
return []
913-
914-
915-
def all_supported_tap_control_side( # pylint: disable=too-many-arguments
916-
data: SingleDataset,
917-
component: ComponentType,
918-
control_side_field: str,
919-
regulated_object_field: str,
920-
tap_side_fields: list[tuple[ComponentType, str]],
921-
**filters: Any,
922-
) -> list[UnsupportedTransformerRegulationError]:
923-
"""
924-
Args:
925-
data (SingleDataset): The input/update data set for all components
926-
component (ComponentType): The component of interest
927-
control_side_field (str): The field of interest
928-
regulated_object_field (str): The field that contains the regulated component ids
929-
tap_side_fields (list[tuple[ComponentType, str]]): The fields of interest per regulated component,
930-
formatted as [(component_1, field_1), (component_2, field_2)]
931-
**filters: One or more filters on the dataset. E.g. regulated_object="transformer".
932-
933-
Returns:
934-
A list containing zero or more InvalidAssociatedEnumValueErrors; listing all the ids
935-
of components where the field of interest was invalid, given the referenced object's field.
936-
"""
937-
mask = _get_mask(data=data, component=component, field=control_side_field, **filters)
938-
values = data[component][control_side_field][mask]
939-
940-
invalid = np.zeros_like(mask)
941-
942-
for ref_component, ref_field in tap_side_fields:
943-
if ref_component in data:
944-
indices = _get_indexer(data[ref_component]["id"], data[component][regulated_object_field], default_value=-1)
945-
found = indices != -1
946-
ref_comp_values = data[ref_component][ref_field][indices[found]]
947-
invalid[found] = np.logical_or(invalid[found], values[found] == ref_comp_values)
948-
949-
if invalid.any():
950-
return [
951-
UnsupportedTransformerRegulationError(
952-
component=component,
953-
fields=[control_side_field, regulated_object_field],
954-
ids=data[component]["id"][invalid].flatten().tolist(),
955-
)
956-
]
957-
return []

src/power_grid_model/validation/_validation.py

-8
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
all_less_than as _all_less_than,
4747
all_not_two_values_equal as _all_not_two_values_equal,
4848
all_not_two_values_zero as _all_not_two_values_zero,
49-
all_supported_tap_control_side as _all_supported_tap_control_side,
5049
all_unique as _all_unique,
5150
all_valid_associated_enum_values as _all_valid_associated_enum_values,
5251
all_valid_clocks as _all_valid_clocks,
@@ -978,11 +977,4 @@ def validate_transformer_tap_regulator(data: SingleDataset) -> list[ValidationEr
978977
errors += _all_greater_than_or_equal_to_zero(
979978
data, ComponentType.transformer_tap_regulator, "line_drop_compensation_x", 0.0
980979
)
981-
errors += _all_supported_tap_control_side(
982-
data,
983-
ComponentType.transformer_tap_regulator,
984-
"control_side",
985-
"regulated_object",
986-
[(ComponentType.transformer, "tap_side"), (ComponentType.three_winding_transformer, "tap_side")],
987-
)
988980
return errors

src/power_grid_model/validation/errors.py

-12
Original file line numberDiff line numberDiff line change
@@ -518,15 +518,3 @@ def enum_str(self) -> str:
518518

519519
def __eq__(self, other):
520520
return super().__eq__(other) and self.enum == other.enum
521-
522-
523-
class UnsupportedTransformerRegulationError(MultiFieldValidationError):
524-
"""
525-
The control side of a branch regulator is not supported for the regulated object
526-
"""
527-
528-
_message = (
529-
"Unsupported control side for {n} {objects}. "
530-
"The control side cannot be on the same side as the tap side. "
531-
"The node at the control side must have the same or lower u_rated as the node at the tap side."
532-
)

tests/unit/validation/test_input_validation.py

-5
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
NotLessThanError,
3535
NotUniqueError,
3636
TwoValuesZeroError,
37-
UnsupportedTransformerRegulationError,
3837
)
3938
from power_grid_model.validation.utils import _nan_type
4039

@@ -641,10 +640,6 @@ def test_validate_input_data_transformer_tap_regulator(input_data):
641640
assert (
642641
NotGreaterOrEqualError("transformer_tap_regulator", "line_drop_compensation_x", [1], 0.0) in validation_errors
643642
)
644-
assert (
645-
UnsupportedTransformerRegulationError("transformer_tap_regulator", ["control_side", "regulated_object"], [54])
646-
in validation_errors
647-
)
648643
assert NotUniqueError("transformer_tap_regulator", "regulated_object", [51, 54]) in validation_errors
649644

650645

tests/unit/validation/test_rules.py

-34
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
all_less_than,
2828
all_not_two_values_equal,
2929
all_not_two_values_zero,
30-
all_supported_tap_control_side,
3130
all_unique,
3231
all_valid_clocks,
3332
all_valid_enum_values,
@@ -55,7 +54,6 @@
5554
NotUniqueError,
5655
SameValueError,
5756
TwoValuesZeroError,
58-
UnsupportedTransformerRegulationError,
5957
)
6058

6159

@@ -640,35 +638,3 @@ def test_all_valid_fault_phases():
640638
errors = all_valid_fault_phases(invalid, "fault", "foo", "bar")
641639
assert len(errors) == 1
642640
assert FaultPhaseError("fault", fields=["foo", "bar"], ids=list(range(26))) in errors
643-
644-
645-
def test_supported_tap_control_side():
646-
valid = {
647-
"foo": np.array([(0, 4)], dtype=[("id", "i4"), ("foofoo", "i1")]),
648-
"bar": np.array([(1, 5)], dtype=[("id", "i4"), ("barbar", "i1")]),
649-
"baz": np.array([], dtype=[("id", "i4"), ("bazbaz", "i1")]),
650-
"regulator": np.array([(2, 0, 6), (3, 1, 7)], dtype=[("id", "i4"), ("regulated", "i4"), ("control", "i1")]),
651-
}
652-
errors = all_supported_tap_control_side(
653-
valid,
654-
"regulator",
655-
"control",
656-
"regulated",
657-
[("foo", "foofoo"), ("bar", "barbar"), ("baz", "bazbaz"), ("bla", "blabla")],
658-
)
659-
assert not errors
660-
661-
invalid = {
662-
"foo": np.array([(0, 4)], dtype=[("id", "i4"), ("foofoo", "i1")]),
663-
"bar": np.array([(1, 5)], dtype=[("id", "i4"), ("barbar", "i1")]),
664-
"regulator": np.array([(2, 0, 4), (3, 1, 5)], dtype=[("id", "i4"), ("regulated", "i4"), ("control", "i1")]),
665-
}
666-
errors = all_supported_tap_control_side(
667-
invalid,
668-
"regulator",
669-
"control",
670-
"regulated",
671-
[("foo", "foofoo"), ("bar", "barbar"), ("baz", "bazbaz")],
672-
)
673-
assert len(errors) == 1
674-
assert UnsupportedTransformerRegulationError(component="regulator", fields=["control", "regulated"], ids=[2, 3])

tests/unit/validation/test_validation_functions.py

+3-12
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
MultiComponentNotUniqueError,
3434
NotUniqueError,
3535
PQSigmaPairError,
36-
UnsupportedTransformerRegulationError,
3736
)
3837

3938
NaN = power_grid_meta_data[DatasetType.input][ComponentType.node].nans["id"]
@@ -971,11 +970,11 @@ def test_validate_values__tap_regulator_control_side():
971970
transformer_tap_regulator["regulated_object"] = np.arange(7)
972971
transformer_tap_regulator["control_side"] = [
973972
BranchSide.to_side, # OK
974-
BranchSide.from_side, # control side is same as tap side (unsupported)
973+
BranchSide.from_side, # OK
975974
Branch3Side.side_3, # branch3 provided but it is a 2-winding transformer (invalid)
976975
10, # control side entirely out of range (invalid)
977976
Branch3Side.side_3, # OK
978-
Branch3Side.side_1, # control side is same as tap side (unsupported)
977+
Branch3Side.side_1, # OK
979978
10, # control side entirely out of range (invalid)
980979
]
981980

@@ -991,7 +990,7 @@ def test_validate_values__tap_regulator_control_side():
991990
assert power_flow_errors == all_errors
992991
assert not state_estimation_errors
993992

994-
assert len(all_errors) == 4
993+
assert len(all_errors) == 3
995994
assert (
996995
InvalidEnumValueError("transformer_tap_regulator", "control_side", [10, 13], [BranchSide, Branch3Side])
997996
in all_errors
@@ -1014,11 +1013,3 @@ def test_validate_values__tap_regulator_control_side():
10141013
)
10151014
in all_errors
10161015
)
1017-
assert (
1018-
UnsupportedTransformerRegulationError(
1019-
"transformer_tap_regulator",
1020-
["control_side", "regulated_object"],
1021-
[8, 12],
1022-
)
1023-
in all_errors
1024-
)

0 commit comments

Comments
 (0)