Skip to content

Faster ModificationsContext - #1469

Open
PoulpoGaz wants to merge 4 commits into
mainfrom
faster-modifications-context
Open

Faster ModificationsContext#1469
PoulpoGaz wants to merge 4 commits into
mainfrom
faster-modifications-context

Conversation

@PoulpoGaz

@PoulpoGaz PoulpoGaz commented Jul 22, 2026

Copy link
Copy Markdown

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?

What kind of change does this PR introduce?

Feature

What is the current behavior?

This PR reduces the work performed by ModificationsContext in two ways.

First, it changes how vertices removed from or added to the main component are computed to avoid an unnecessary copy and uses THashSet instead of HashSet.

Second, AbstractGraphConnectivity#startTemporaryChanges currently copies all vertices outside the main component so that callers can later invoke get(Vertices|Edges)(AddedTo|RemovedFrom)MainComponent. But, sometimes users don't call these methods, making this coy unnecessary.

For example: in LfActionUtils#updateConnectivity, the impact of a set of actions on the network connectivity after a contingency is simulated. Because the connectivity is in its initial state, that is before the contingency, it is necessary to

  1. call startTemporaryChanges and apply the contingency
  2. call startTemporaryChanges again (otherwise, topological comparisons would be performed against the pre-contingency state instead of the post-contingency state) and apply the actions
  3. Use get(Vertices|Edges)(AddedTo|removedFrom)MainComponent.
  4. undo the actions
  5. undo the contingency

Notice that the first startTemporaryChanges isn't associated with any topological comparisons. So in this case, copying the vertices outside the main component is unnecessary.

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

This PR introduces a new method in GraphConnectivity: startTemporaryChanges(boolean computeComparisons). Users can now explicitly disable the computation of topological comparisons by passing false. If they use one of the following methods: get(Vertices|Edges)(AddedTo|removedFrom)MainComponent, an exception is thrown.

startTemporaryChanges is kept and his behavior isn't changed.

When running a security analysis with ~5000 contingencies, ~5000 operator strategies with one action and NaiveGraphConnectivity, the total time spent on connectivity is reduced from 72 s to 60 s. When using DTree, the total time is reduced from 8.7 s to 5.6 s.

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:

Signed-off-by: Valentin Carrez <valentin.carrez@rte-france.com>
Signed-off-by: Valentin Carrez <valentin.carrez@rte-france.com>
Signed-off-by: Valentin Carrez <valentin.carrez@rte-france.com>
Signed-off-by: Valentin Carrez <valentin.carrez@rte-france.com>
@sonarqubecloud

Copy link
Copy Markdown

@PoulpoGaz
PoulpoGaz marked this pull request as ready for review July 22, 2026 14:02
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.

1 participant