Skip to content

feat: take N-1 element names from the grid during input N-1 validation - #889

Merged
spetznick-elia merged 4 commits into
mainfrom
feat/validate-monitored-element-name
Nov 6, 2026
Merged

spetznick-elia merged 4 commits into
mainfrom
feat/validate-monitored-element-name

Conversation

@spetznick-elia

Copy link
Copy Markdown
Collaborator

Checklist

Please check if the PR fulfills these requirements:

  • PR Title follows conventional commit messages
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • All commits in this PR are DCO signed-off (see CONTRIBUTING.md)

Does this PR already have an issue describing the problem?

No linked issue. Follow-up to #722, which added grid validation of the input N-1 definition.

What is the new behavior and why?

The importer validates an input N-1 definition against the grid file. Until now, that validation corrected the type and kind of each element from the grid, matched by id, but kept the element name from the input file. Monitored and contingency elements could then carry stale or missing names that do not match the grid they refer to.

Now the grid also decides the name. Each monitored element and contingency element takes the name of the grid element with the same id:

  • the UCTE elementName if it is set, because UCTE grids leave the Powsybl name empty;
  • otherwise the Powsybl name;
  • if the grid element has no name, the input name is kept, so names are never wiped.

Each overwritten name is logged as a warning (nminus1_element_name_corrected) with the input and the grid name, in the same way as type corrections. Element ids and every other part of the definition stay as they are.

Open point: in UCTE grids, tie lines fall back to the Powsybl name (both half-line ids joined with +). The new name is not built from their per-side elementName_1 and elementName_2 values.

Does this PR introduce a breaking change?

  • Yes, because
  • No

When validating the input N-1 definition against the grid, the name of
every monitored and contingency element is overwritten by the grid
element's name (UCTE elementName if set, else the Powsybl name). Elements
without a grid name keep their input name. Each change is logged as
nminus1_element_name_corrected.

Signed-off-by: Sascha Petznick <229719644+spetznick-elia@users.noreply.github.com>
Loop over the N-1 element types and read each with network.get_elements
instead of listing one getter per element type. The name check now runs
before the unchanged type/kind correction.

Signed-off-by: Sascha Petznick <229719644+spetznick-elia@users.noreply.github.com>
GridElementType now lives next to GridElement in nminus1_definition and
types the element-type keys of the input N-1 definition validation.
power_factory_data_class imports it from there, so existing imports keep
working.

Signed-off-by: Sascha Petznick <229719644+spetznick-elia@users.noreply.github.com>
Iterate over GridElementType instead of the keys of KIND_BY_ELEMENT_TYPE
when reading names, and parametrize the name test over a UCTE and a CGMES
grid.

Signed-off-by: Sascha Petznick <229719644+spetznick-elia@users.noreply.github.com>
@spetznick-elia
spetznick-elia marked this pull request as ready for review November 6, 2026 09:38
Copilot AI balanced review requested due to automatic review settings November 6, 2026 09:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

There are no active review issues for the standalone validator’s grid-name alignment changes.

No open issues 🎉

What changed in this PR

Updates the standalone input N-1 validator introduced in #722 to align monitored and contingency element names with the grid. This does not wire the validator into the production import pipeline.

Changes:

  • Prefer UCTE elementName, then Powsybl name; preserve input names when neither is available and log corrections.
  • Centralize GridElementType in the shared interfaces package.
  • Add name-alignment tests and document the fallback behavior.
File Description
packages/​interfaces_pkg/​src/​toop_engine_interfaces/​nminus1_definition.py Defines the shared GridElementType alias.
packages/​importer_pkg/​tests/​pypowsybl_import/​test_nminus1_definition_input.py Tests UCTE and CGMES names, correction logging, and unnamed-grid fallback.
packages/​importer_pkg/​src/​toop_engine_importer/​pypowsybl_import/​contingency_from_file/​nminus1_definition_input.py Retrieves grid names and applies them during N-1 validation.
packages/​importer_pkg/​src/​toop_engine_importer/​contingency_from_power_factory/​power_factory_data_class.py Reuses the shared element-type alias.
docs/​importer/​pypowsybl/​index.md Documents name precedence and preservation of input names.

Review effort: Balanced

@sonarqube-mccs

sonarqube-mccs Bot commented Nov 6, 2026

Copy link
Copy Markdown

@BenjPetr BenjPetr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@spetznick-elia
spetznick-elia merged commit 808291e into main Nov 6, 2026
30 of 36 checks passed
@spetznick-elia
spetznick-elia deleted the feat/validate-monitored-element-name branch November 6, 2026 09:55
spetznick-elia added a commit that referenced this pull request Nov 6, 2026
…#891)

## Checklist

Please check if the PR fulfills these requirements:

- [x] PR Title follows conventional commit messages
- [x] Tests for the changes have been added (for bug fixes / features)
- [x] Docs have been added / updated (for bug fixes / features)
- [x] All commits in this PR are DCO signed-off (see CONTRIBUTING.md)

## Does this PR already have an issue describing the problem?

No linked issue. Follow-up to #889.

## What is the new behavior and why?

The N-1 definition that the DC solver preprocessing builds and the input
N-1 definition that the importer validates named the same UCTE elements
differently:

- The DC solver names a UCTE line or transformer `<id>: <elementName>`,
and a single-outage contingency of it the same way.
- The importer used the bare `elementName` for the element and kept the
contingency name of the input file. That name follows a business naming
scheme, with underscores between shortened node names and a type suffix
such as `:line` or `:trf`.

The importer now uses the DC solver's naming:

- UCTE lines and two-winding transformers are named `<id>:
<elementName>`, and UCTE tie lines by their id. Other UCTE elements keep
their `elementName`, and CGMES elements their Powsybl `name`.
- A contingency that the DC solver outages as a single element takes
that element's grid name. That is a contingency with exactly one line,
two-winding transformer or tie line connected at both sides, or with no
such branch and exactly one injection; isolating switches do not count.
A contingency with a three-winding transformer is never a single outage,
because the transformer becomes three DC branches. Multi-outages, and
contingencies whose element has no name in the grid, keep their input
name.
- Each renamed contingency is logged as
`nminus1_contingency_name_corrected`.

Known difference: for pure UCTE grids, the DC solver's `get_lines` joins
id and `elementName` without the `": "` separator (`<id><elementName>`),
unlike its transformers and its UCTE/CGMES-merged ("hybrid") grids. The
importer always uses `": "`, which matches the DC solver's transformers
and hybrid grids.

## Does this PR introduce a breaking change?

- [ ] Yes, because
- [x] No

---------

Signed-off-by: Sascha Petznick <229719644+spetznick-elia@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants