Skip to content

Fix non-idempotent voltage level layout run - #830

Open
samirromdhani wants to merge 8 commits into
mainfrom
test/289-running-the-layout-is-not-idempotent
Open

Fix non-idempotent voltage level layout run#830
samirromdhani wants to merge 8 commits into
mainfrom
test/289-running-the-layout-is-not-idempotent

Conversation

@samirromdhani

@samirromdhani samirromdhani commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Please check if the PR fulfills these requirements

  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • A PR or issue has been opened in all impacted repositories (if any)

Does this PR already have an issue describing the problem?

Fixes #289
What kind of change does this PR introduce?

What is the current behavior?

What is the new behavior (if this is a feature change)?

Does this PR introduce a breaking change or deprecate an API?

  • Yes
  • No

If yes, please check if the following requirements are fulfilled

  • The Breaking Change or Deprecated label has been added
  • The migration steps are described in the following section

What changes might users need to make in their application due to this PR? (migration steps)

Other information:

Root cause
  • cellDetector.detectCells(getGraph()); always creates new cells via graph.addCell()
  • addPaddingToCoord() add vl padding to graph.coord on every run (coord is not reset)

Signed-off-by: Samir Romdhani <samir.romdhani_externe@rte-france.com>
@samirromdhani
samirromdhani force-pushed the test/289-running-the-layout-is-not-idempotent branch from 4d6286d to d215f13 Compare August 4, 2026 15:38
Signed-off-by: Samir Romdhani <samir.romdhani_externe@rte-france.com>
@samirromdhani
samirromdhani force-pushed the test/289-running-the-layout-is-not-idempotent branch from 2b4a5ba to 3bc6770 Compare August 5, 2026 14:20
Signed-off-by: Samir Romdhani <samir.romdhani_externe@rte-france.com>
@samirromdhani samirromdhani changed the title Fix no idempotent layout run (WIP) Fix non-idempotent voltage level layout run Aug 5, 2026
@samirromdhani
samirromdhani marked this pull request as ready for review August 5, 2026 14:57

@NathanDissoubray NathanDissoubray 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.

Have you checked that there isn't the same kind of bug for ZoneGraph and for SubstationGraph ?

Signed-off-by: Samir Romdhani <samir.romdhani_externe@rte-france.com>
@samirromdhani

Copy link
Copy Markdown
Contributor Author

Have you checked that there isn't the same kind of bug for ZoneGraph and for SubstationGraph ?

Yes, both use VoltageLevelLayoutFactory, so the fix applies there too.
Added equivalent tests for substation and zone graph.

Signed-off-by: Samir Romdhani <samir.romdhani_externe@rte-france.com>
Signed-off-by: Samir Romdhani <samir.romdhani_externe@rte-france.com>
@samirromdhani samirromdhani self-assigned this Aug 12, 2026

@So-Fras So-Fras left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the work! I left first comments to discuss.

LayoutParameters.Padding dPadding = layoutParam.getDiagramPadding();
setCoord(coord.getX() + dPadding.left() + vlPadding.left(),
coord.getY() + dPadding.top() + vlPadding.top());
setCoord(getCoord().getX() + dPadding.left() + vlPadding.left(),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't see the link with the 2nd root cause mentioned in the PR description.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Here, I just preferred using the getter, the two root causes are added in the same method clearCells

    public void clearCells() {
        cells.clear();        // first root cause
        cellCounter = 0;      // first root cause
        setCoord(0, 0);       // second root cause
    }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The root causes:

for (Set<Node> nodes : internCellsNodes) {
graph.addCell(new InternCell(graph.getNextCellNumber(), nodes));

cells was not initialized when the layout was run twice => fixed by cells.clear()
graph.getNextCellNumber() was not initialized when the layout was run twice => fixed by cellCounter = 0

Coord was not initialized when the layout was run twice => fixed by setCoord(0, 0)

substation = Networks.createSubstation(network, "s", "s", Country.FR);
vl = Networks.createVoltageLevel(substation, "vl", "vl", TopologyKind.NODE_BREAKER, 380);
Networks.createBusBarSection(vl, "bbs", "bbs", 0, 1, 1);
Networks.createLoad(vl, "l", "l", "l", 0, ConnectablePosition.Direction.TOP, 2, 10, 10);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
Networks.createLoad(vl, "l", "l", "l", 0, ConnectablePosition.Direction.TOP, 2, 10, 10);
Networks.createLoad(vl, "l", 0, ConnectablePosition.Direction.TOP, 2, 10, 10);

graphBuilder = new NetworkGraphBuilder(network);
substation = Networks.createSubstation(network, "s", "s", Country.FR);
vl = Networks.createVoltageLevel(substation, "vl", "vl", TopologyKind.NODE_BREAKER, 380);
Networks.createBusBarSection(vl, "bbs", "bbs", 0, 1, 1);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
Networks.createBusBarSection(vl, "bbs", "bbs", 0, 1, 1);
Networks.createBusBarSection(vl, "bbs", 0, 1, 1);

Signed-off-by: Samir Romdhani <samir.romdhani_externe@rte-france.com>
@sonarqubecloud

sonarqubecloud Bot commented Sep 3, 2026

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Running the layout is not idempotent

3 participants