-
Notifications
You must be signed in to change notification settings - Fork 43
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
Supress Exceptions in some cases when working with variants [ allowVariantMultiThreadAccess(true) ] #867
Conversation
It was proposed to entirely remove the possibility to have an unset variant for the allowMultithreadAccess(false) mode to make things more coherent. @geofjamg what do you think ? (the only possibility to get in this state is to remove the working variant). With the following diff: diff --git a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/MultiVariantContext.java b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/MultiVariantContext.java
index a667398aa..2423c2825 100644
--- a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/MultiVariantContext.java
+++ b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/MultiVariantContext.java
@@ -36,7 +36,7 @@ class MultiVariantContext implements VariantContext {
@Override
public void resetIfVariantIndexIs(int index) {
if (this.index == index) {
- this.index = -1;
+ this.index = VariantManagerImpl.INITIAL_VARIANT_INDEX;
}
}
}
diff --git a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/VariantManagerImpl.java b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/VariantManagerImpl.java
index 8c91e94ca..77a592bff 100644
--- a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/VariantManagerImpl.java
+++ b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/VariantManagerImpl.java
@@ -26,7 +26,7 @@ public class VariantManagerImpl implements VariantManager {
private static final Logger LOGGER = LoggerFactory.getLogger(VariantManagerImpl.class);
- private static final int INITIAL_VARIANT_INDEX = 0;
+ static final int INITIAL_VARIANT_INDEX = 0;
private VariantContext variantContext;
|
…ess and workingvariant is not set Signed-off-by: Jon Harper <[email protected]>
…de is already what we want Signed-off-by: Jon Harper <[email protected]>
…ad to multithread Signed-off-by: Jon Harper <[email protected]>
Let's merge this and then we can think about the API of unset variants ?
|
Please check if the PR fulfills these requirements (please use
'[x]'
to check the checkboxes, or submit the PR and then click the checkboxes)Does this PR already have an issue describing the problem ? If so, link to this issue using
'#XXX'
and skip the restNo
What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
Bug Fix: This PR supresses Exceptions in some cases when working with variants
What is the current behavior? (You can also link to an open issue here)
What is the new behavior (if this is a feature change)?
allowVariantMultiThreadAccess doesn't do anything if we are already in the good mode. allowVariantMultiThreadAccess doesn't throw when the currentvariant is not set (for multithread mode, it keeps it unset; for singlethread mode, it resets the variant to the default variant.
Does this PR introduce a breaking change or deprecate an API? If yes, check the following:
No
Other information:
This is not a perfect solution... This API is very dangerous and we should think about changing it completely. In the meantime, this PR makes it less error prone.
Problems with the current API:
If a network is shared between multiple tasks that are not aware of each other, on task can set allowVariantMultiThreadAccess(false) while the other task is relying on the fact that it had set allowVariantMultiThreadAccess(true) for its computation.
In this case, it is unclear what we want to do: