Skip to content

Conversation

@obrix
Copy link
Member

@obrix obrix commented Oct 23, 2025

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?

A proposal for a detailed result handler interface in the security analysis API

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:

obrix added 2 commits October 23, 2025 10:10
Signed-off-by: Bertrand Rix <[email protected]>
Signed-off-by: Bertrand Rix <[email protected]>
@obrix obrix marked this pull request as draft October 23, 2025 08:17
obrix added 3 commits October 23, 2025 10:21
Signed-off-by: Bertrand Rix <[email protected]>
Signed-off-by: Bertrand Rix <[email protected]>
Signed-off-by: Bertrand Rix <[email protected]>
@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
3.8% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@obrix
Copy link
Member Author

obrix commented Oct 24, 2025

@geofjamg @vidaldid-rte

In the proposed approach a new parameter for the security analysis is available : a list of SecurityAnalysisResultHandlers. Theses handlers will be notified in the security analysis implementation when data is available.

A basic example implementation is provided, InMemoryResultHandler, that just store the data in memory as they come.

The user can provide its own implementation. The contingency and operator strategy is provided in the API to let the user deduce the context of the data provided (see in memory implementation).

What is missing here to a least cover our use case : a GeneratorResult, providing target and real flow for each state. But to add this the StateMonitor API should probably be updated to be able to monitor generators.

Maybe we could add some more notification API in the handler interface such as "base case done", "contingency done", "operator strategy done". It could be handy when doing large security analysis and some progression notification system is available in the user architecture.


void writeBusResult(Contingency contingency, OperatorStrategy operatorStrategy, BusResult busResult);

}
Copy link
Contributor

Choose a reason for hiding this comment

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

To align with the suggestion in #3626 (that extends the sensitivity writer for multi-component, better failure diagnosis and interrupt) you could add

// numCC and numCs are used for contingencies that have equipments in multiple components
void writeContingencyStatus contingency(int contingencyIndex, LoadFlowResult.ComponentResult.Status, String statusText, int numCC, int numCs);

void writeSynchronousComponentStatus(int numCC, int numCS, LoadFlowResult.ComponentResult.Status, String statusText,);

// Called at the end of the computation if the computation has not been interrupted
void computationComplete();

Copy link
Contributor

Choose a reason for hiding this comment

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

To turn this in to a way to get result in streaming, you could also add methods for listening to violations.

Copy link
Member

Choose a reason for hiding this comment

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

@obrix yes, here you only streamed only a part of the SecurityAnalysisResult API. We should fully convert it even for violations.

/**
* Sets the list of handlers referenced in {@link SecurityAnalysisResultHandler}
*/
public T setResultHandlers(List<SecurityAnalysisResultHandler> handlers) {
Copy link
Contributor

@vidaldid-rte vidaldid-rte Oct 24, 2025

Choose a reason for hiding this comment

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

Why a list and not only one ?
If there was only one, we coud mimic the sensi API: no result handler provided means you return an in memory result.
Handler provided means you return void and send the data to the writer.
This view implies that the writer supports also the violation results, not only the monitored objects.

Then if it is useful to have serveral handlers, we would provided the implementation of a SecurityAnalysisResultMultiplexer that would dispatch the calls to a list of handlers.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes I agree, if some kind of multiplexing is needed the user has everything available to do it himself anyway. So ok for a single handler API.

Copy link
Member Author

@obrix obrix Oct 28, 2025

Choose a reason for hiding this comment

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

An handler provided would mean we do not fill the result objects then ? NetworkResult in PreContingencyResult / PostContingencyResult would remain empty ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Here is the Sensitivity API. We could use the same idea for security + writer

No writer -> returns a Result. Internally it creates a writer that creates the result object. The provider only knows the writer.
public SensitivityAnalysisResult run(Network network,
String workingVariantId,
List factors,
SensitivityAnalysisRunParameters runParameters)

A writer -> returns void. The user code handles that data as needed, without memory overhead, for example if the result is directly streamed into a database or a python dataframe.
public void run(Network network,
String workingVariantId,
SensitivityFactorReader factorReader,
SensitivityResultWriter resultWriter,
SensitivityAnalysisRunParameters runParameters) {
runAsync(network, workingVariantId, factorReader, resultWriter, runParameters).join();
}

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants