Skip to content

Commit

Permalink
Add support for multithread with OpenLoadFlow in security analysis
Browse files Browse the repository at this point in the history
* Copy network to iidm-impl while multithread variant access is not supported in the network-store
* SecurityAnalysisParameters.load() in any case to retrieve specific parameters set in the PlatformConfig (like threadCount)
  • Loading branch information
antoinebhs committed Sep 5, 2024
1 parent b0e6939 commit 5bb7141
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
11 changes: 11 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@
<dependencyManagement>
<dependencies>
<!-- overrides of imports -->
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-open-loadflow</artifactId>
<version>1.13.0-SNAPSHOT</version>
</dependency>

<!-- imports -->
<dependency>
Expand Down Expand Up @@ -195,6 +200,12 @@
<artifactId>micrometer-registry-prometheus</artifactId>
<scope>runtime</scope>
</dependency>
<!-- FIXME: Remove this runtime dependency when variant multithread access is implemented in the network-store -->
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-iidm-impl</artifactId>
<scope>runtime</scope>
</dependency>

<!-- Test dependencies -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,13 @@ public SecurityAnalysisRunContext createRunContext(UUID networkUuid, String vari
}

public SecurityAnalysisParametersDTO toSecurityAnalysisParameters(SecurityAnalysisParametersEntity entity) {
SecurityAnalysisParameters securityAnalysisParameters;
SecurityAnalysisParameters securityAnalysisParameters = SecurityAnalysisParameters.load();
List<List<Double>> limitReductions = new ArrayList<>();
if (entity == null) {
securityAnalysisParameters = SecurityAnalysisParameters.load()
// the default values are overloaded
.setIncreasedViolationsParameters(getIncreasedViolationsParameters(DEFAULT_FLOW_PROPORTIONAL_THRESHOLD, DEFAULT_LOW_VOLTAGE_PROPORTIONAL_THRESHOLD, DEFAULT_LOW_VOLTAGE_ABSOLUTE_THRESHOLD, DEFAULT_HIGH_VOLTAGE_PROPORTIONAL_THRESHOLD, DEFAULT_HIGH_VOLTAGE_ABSOLUTE_THRESHOLD));
// the default values are overloaded
securityAnalysisParameters.setIncreasedViolationsParameters(getIncreasedViolationsParameters(DEFAULT_FLOW_PROPORTIONAL_THRESHOLD, DEFAULT_LOW_VOLTAGE_PROPORTIONAL_THRESHOLD, DEFAULT_LOW_VOLTAGE_ABSOLUTE_THRESHOLD, DEFAULT_HIGH_VOLTAGE_PROPORTIONAL_THRESHOLD, DEFAULT_HIGH_VOLTAGE_ABSOLUTE_THRESHOLD));
} else {
securityAnalysisParameters = new SecurityAnalysisParameters().setIncreasedViolationsParameters(getIncreasedViolationsParameters(entity.getFlowProportionalThreshold(), entity.getLowVoltageProportionalThreshold(), entity.getLowVoltageAbsoluteThreshold(), entity.getHighVoltageProportionalThreshold(), entity.getHighVoltageAbsoluteThreshold()));
securityAnalysisParameters.setIncreasedViolationsParameters(getIncreasedViolationsParameters(entity.getFlowProportionalThreshold(), entity.getLowVoltageProportionalThreshold(), entity.getLowVoltageAbsoluteThreshold(), entity.getHighVoltageProportionalThreshold(), entity.getHighVoltageAbsoluteThreshold()));
limitReductions = entity.toLimitReductionsValues();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
import com.powsybl.iidm.criteria.duration.IntervalTemporaryDurationCriterion;
import com.powsybl.iidm.criteria.duration.LimitDurationCriterion;
import com.powsybl.iidm.criteria.duration.PermanentDurationCriterion;
import com.powsybl.iidm.network.LimitType;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.VariantManagerConstants;
import com.powsybl.iidm.network.*;
import com.powsybl.iidm.serde.NetworkSerDe;
import com.powsybl.loadflow.LoadFlowResult;
import com.powsybl.network.store.client.NetworkStoreService;
import com.powsybl.network.store.client.PreloadingStrategy;
import com.powsybl.security.*;
import com.powsybl.security.limitreduction.LimitReduction;
import com.powsybl.ws.commons.LogUtils;
Expand All @@ -42,6 +42,7 @@
import java.util.Objects;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
import java.util.function.Function;
Expand Down Expand Up @@ -92,6 +93,11 @@ public SecurityAnalysisResult run(SecurityAnalysisRunContext runContext) {
}
}

@Override
protected PreloadingStrategy getNetworkPreloadingStrategy() {
return PreloadingStrategy.ALL_COLLECTIONS_NEEDED_FOR_BUS_VIEW;
}

@Override
protected String getComputationType() {
return COMPUTATION_TYPE;
Expand All @@ -108,6 +114,20 @@ protected CompletableFuture<SecurityAnalysisResult> getCompletableFuture(Securit
.toList();
List<LimitReduction> limitReductions = createLimitReductions(runContext);

Network network = runContext.getNetwork();
// FIXME: Remove this part when multithread variant access is implemented in the network-store
if (runContext.getProvider().equals("OpenLoadFlow")) {
long startTime = System.nanoTime();
Network originalNetwork = runContext.getNetwork();
String originalVariant = originalNetwork.getVariantManager().getWorkingVariantId();
originalNetwork.getVariantManager().setWorkingVariant(variantId);

network = NetworkSerDe.copy(originalNetwork, NetworkFactory.find("Default"));
network.getVariantManager().cloneVariant(VariantManagerConstants.INITIAL_VARIANT_ID, variantId);
LOGGER.info("Network copied to iidm-impl in {} ms", TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime));
originalNetwork.getVariantManager().setWorkingVariant(originalVariant);
}

SecurityAnalysisRunParameters runParameters = new SecurityAnalysisRunParameters()
.setSecurityAnalysisParameters(runContext.getParameters().securityAnalysisParameters())
.setComputationManager(executionService.getComputationManager())
Expand All @@ -116,7 +136,7 @@ protected CompletableFuture<SecurityAnalysisResult> getCompletableFuture(Securit
.setReportNode(runContext.getReportNode());

return securityAnalysisRunner.runAsync(
runContext.getNetwork(),
network,
variantId,
n -> contingencies,
runParameters)
Expand Down

0 comments on commit 5bb7141

Please sign in to comment.