-
Notifications
You must be signed in to change notification settings - Fork 56
Add private extensions validation (loadflow-validation) #3820
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
samirromdhani
wants to merge
3
commits into
main
Choose a base branch
from
feat/696_loadflow_validation_extension
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
...lidation/src/main/java/com/powsybl/loadflow/validation/extension/ExtensionValidation.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| /** | ||
| * Copyright (c) 2026, RTE (http://www.rte-france.com) | ||
| * This Source Code Form is subject to the terms of the Mozilla Public | ||
| * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| * file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
| * SPDX-License-Identifier: MPL-2.0 | ||
| */ | ||
| package com.powsybl.loadflow.validation.extension; | ||
| import com.powsybl.iidm.network.Network; | ||
| import com.powsybl.loadflow.validation.ValidationConfig; | ||
|
|
||
| /** | ||
| * | ||
| * @author Samir Romdhani {@literal <samir.romdhani at rte-france.com>} | ||
| */ | ||
| public interface ExtensionValidation { | ||
|
|
||
| String getName(); | ||
|
|
||
| boolean check(Network network, ValidationConfig config); | ||
|
|
||
| } |
49 changes: 49 additions & 0 deletions
49
...idation/src/main/java/com/powsybl/loadflow/validation/extension/ExtensionsValidation.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| /** | ||
| * Copyright (c) 2026, RTE (http://www.rte-france.com) | ||
| * This Source Code Form is subject to the terms of the Mozilla Public | ||
| * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| * file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
| * SPDX-License-Identifier: MPL-2.0 | ||
| */ | ||
| package com.powsybl.loadflow.validation.extension; | ||
|
|
||
| import com.google.common.base.Suppliers; | ||
| import com.google.common.collect.Lists; | ||
| import com.powsybl.iidm.network.Network; | ||
| import com.powsybl.loadflow.validation.ValidationConfig; | ||
| import com.powsybl.tools.ToolRunningContext; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Optional; | ||
| import java.util.ServiceLoader; | ||
| import java.util.function.Supplier; | ||
|
|
||
| /** | ||
| * @author Samir Romdhani {@literal <samir.romdhani at rte-france.com>} | ||
| */ | ||
| public class ExtensionsValidation { | ||
|
|
||
| private static final Supplier<List<ExtensionValidation>> EXTENSIONS = Suppliers.memoize(() -> Lists.newArrayList( | ||
| ServiceLoader.load(ExtensionValidation.class, ExtensionsValidation.class.getClassLoader()))); | ||
|
|
||
| public static List<ExtensionValidation> getExtensions() { | ||
| return EXTENSIONS.get(); | ||
| } | ||
|
|
||
| public static List<String> getExtensionsNames() { | ||
| return getExtensions().stream().map(ExtensionValidation::getName).toList(); | ||
| } | ||
|
|
||
| public static Optional<ExtensionValidation> getExtension(String name) { | ||
| return getExtensions().stream().filter(v -> v.getName().equals(name)).findFirst(); | ||
| } | ||
|
|
||
| public void runExtensionValidations(Network network, ValidationConfig config, ToolRunningContext context) { | ||
| getExtensions().forEach(extensionValidation -> { | ||
| boolean success = extensionValidation.check(network, config); | ||
| context.getOutputStream().println("Validate load-flow results of network " + network.getId() | ||
| + " - validation type: Extension/" + extensionValidation.getName() | ||
| + " - result: " + (success ? "success" : "fail")); | ||
| }); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
...loadflow-validation/src/test/java/com/powsybl/loadflow/validation/ValidationToolTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| /** | ||
| * Copyright (c) 2026, RTE (http://www.rte-france.com) | ||
| * This Source Code Form is subject to the terms of the Mozilla Public | ||
| * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| * file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
| * SPDX-License-Identifier: MPL-2.0 | ||
| */ | ||
| package com.powsybl.loadflow.validation; | ||
|
|
||
| import com.powsybl.tools.Tool; | ||
| import com.powsybl.tools.test.AbstractToolTest; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.nio.file.Files; | ||
| import java.util.Collections; | ||
| import java.util.Objects; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.*; | ||
|
|
||
| /** | ||
| * | ||
| * @author Samir Romdhani {@literal <samir.romdhani at rte-france.com>} | ||
| */ | ||
| class ValidationToolTest extends AbstractToolTest { | ||
|
|
||
| private static final String COMMAND_NAME = "loadflow-validation"; | ||
| private final ValidationTool tool = new ValidationTool(); | ||
|
|
||
| @Override | ||
| @BeforeEach | ||
| public void setUp() throws Exception { | ||
| super.setUp(); | ||
| Files.copy(Objects.requireNonNull(getClass().getResourceAsStream("/network.xiidm")), fileSystem.getPath("network.xiidm")); | ||
| } | ||
|
|
||
| @Override | ||
| protected Iterable<Tool> getTools() { | ||
| return Collections.singleton(tool); | ||
| } | ||
|
|
||
| @Override | ||
| public void assertCommand() { | ||
| assertEquals(COMMAND_NAME, tool.getCommand().getName()); | ||
| assertEquals("Computation", tool.getCommand().getTheme()); | ||
| assertEquals("Validate load-flow results of a network", tool.getCommand().getDescription()); | ||
|
|
||
| assertCommand(tool.getCommand(), COMMAND_NAME, 12, 2); | ||
| assertOption(tool.getCommand().getOptions(), "case-file", true, true); | ||
| assertOption(tool.getCommand().getOptions(), "output-folder", true, true); | ||
| assertOption(tool.getCommand().getOptions(), "load-flow", false, false); | ||
| assertOption(tool.getCommand().getOptions(), "types", false, true); | ||
| assertOption(tool.getCommand().getOptions(), "with-extensions-validation", false, false); | ||
| } | ||
|
|
||
| @Test | ||
| void testCommand() { | ||
| assertCommand(); | ||
| } | ||
|
|
||
| @Test | ||
| void loadFlowValidationShouldSucceedWithRequiredOption() { | ||
| String expectedOut = String.join(System.lineSeparator(), | ||
| "Loading case network.xiidm", | ||
| "Validate load-flow results of network network - validation type: FLOWS - result: success", | ||
| "Validate load-flow results of network network - validation type: GENERATORS - result: success", | ||
| "Validate load-flow results of network network - validation type: BUSES - result: success", | ||
| "Validate load-flow results of network network - validation type: SVCS - result: success", | ||
| "Validate load-flow results of network network - validation type: SHUNTS - result: success", | ||
| "Validate load-flow results of network network - validation type: TWTS - result: success", | ||
| "Validate load-flow results of network network - validation type: TWTS3W - result: success" + System.lineSeparator()); | ||
| assertCommandSuccessfulMatch(new String[]{"loadflow-validation", "--case-file", "network.xiidm", "--output-folder", "test"}, expectedOut); | ||
| } | ||
|
|
||
| @Test | ||
| void loadFlowValidationShouldComputePrivateValidation() { | ||
| String expectedOut = String.join(System.lineSeparator(), | ||
| "Loading case network.xiidm", | ||
| "Validate load-flow results of network network - validation type: FLOWS - result: success", | ||
| "Validate load-flow results of network network - validation type: GENERATORS - result: success", | ||
| "Validate load-flow results of network network - validation type: BUSES - result: success", | ||
| "Validate load-flow results of network network - validation type: SVCS - result: success", | ||
| "Validate load-flow results of network network - validation type: SHUNTS - result: success", | ||
| "Validate load-flow results of network network - validation type: TWTS - result: success", | ||
| "Validate load-flow results of network network - validation type: TWTS3W - result: success", | ||
| "Validate load-flow results of network network - validation type: Extension/extensionValidationMock1 - result: success" + System.lineSeparator()); | ||
| assertCommandSuccessfulMatch(new String[]{"loadflow-validation", "--case-file", "network.xiidm", "--output-folder", "test", "--with-extensions-validation"}, expectedOut); | ||
| } | ||
| } |
30 changes: 30 additions & 0 deletions
30
...tion/src/test/java/com/powsybl/loadflow/validation/extension/ExtensionValidationMock.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| /** | ||
| * Copyright (c) 2026, RTE (http://www.rte-france.com) | ||
| * This Source Code Form is subject to the terms of the Mozilla Public | ||
| * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| * file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
| * SPDX-License-Identifier: MPL-2.0 | ||
| */ | ||
| package com.powsybl.loadflow.validation.extension; | ||
| import com.google.auto.service.AutoService; | ||
| import com.powsybl.iidm.network.Network; | ||
| import com.powsybl.loadflow.validation.ValidationConfig; | ||
|
|
||
| /** | ||
| * | ||
| * @author Samir Romdhani {@literal <samir.romdhani at rte-france.com>} | ||
| */ | ||
| @AutoService(ExtensionValidation.class) | ||
| public class ExtensionValidationMock implements ExtensionValidation { | ||
|
|
||
| @Override | ||
| public String getName() { | ||
| return "extensionValidationMock1"; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean check(Network network, ValidationConfig config) { | ||
| return true; | ||
| } | ||
|
|
||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong place, you put it between an argument and the examples linked to that argument