Skip to content
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

Replace "Usage Rules" by "Trigger Conditions" #1050

Closed
wants to merge 23 commits into from

Conversation

bqth29
Copy link
Collaborator

@bqth29 bqth29 commented Jun 20, 2024

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)

Does this PR already have an issue describing the problem?
Fixes #992

What kind of change does this PR introduce?
Usage Rules have been discarded and replaced by Trigger Conditions that carry a sort of logical gates on four conditions: instant, contingency, cnec and country.

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)

TODO

Other information:

bqth29 added 10 commits June 18, 2024 09:56
Signed-off-by: Thomas Bouquet <[email protected]>
Signed-off-by: Thomas Bouquet <[email protected]>
Signed-off-by: Thomas Bouquet <[email protected]>
Signed-off-by: Thomas Bouquet <[email protected]>
Signed-off-by: Thomas Bouquet <[email protected]>
Signed-off-by: Thomas Bouquet <[email protected]>
Signed-off-by: Thomas Bouquet <[email protected]>
@bqth29 bqth29 added feature New feature or request cleaning This issue or pull request only concerns improving the overall state of the code breaking-change Changes could break users' code experiment This subject is experimental and needs to be discussed thoroughly first labels Jun 20, 2024
bqth29 added 4 commits June 21, 2024 09:40
Signed-off-by: Thomas Bouquet <[email protected]>
# Conflicts:
#	data/crac-creation/crac-creator-csa-profiles/src/main/java/com/powsybl/openrao/data/craccreation/creator/csaprofile/craccreator/remedialaction/CsaProfileRemedialActionsCreator.java
#	ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/parameters/UnoptimizedCnecParameters.java
#	ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/commons/RaoUtilTest.java
#	ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/commons/parameters/UnoptimizedCnecParametersTest.java
#	ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/UnoptimizedCnecFillerPstLimitationRuleTest.java
Signed-off-by: Thomas Bouquet <[email protected]>
Signed-off-by: Thomas Bouquet <[email protected]>
@bqth29 bqth29 added the PR: waiting-for-review This PR is waiting to be reviewed label Jun 24, 2024
Copy link
Collaborator

@pet-mit pet-mit left a comment

Choose a reason for hiding this comment

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

I think we should discuss the design more

&& ur.getUsageMethod().equals(instant.isAuto() ? UsageMethod.FORCED : UsageMethod.AVAILABLE)
));
ra.getTriggerConditions().stream()
.filter(tc -> tc.getContingency().isEmpty() && tc.getCnec().isPresent() && tc.getCountry().isEmpty())
Copy link
Collaborator

Choose a reason for hiding this comment

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

how about we add a TriggerCondition.getType() method, that returns an enum, to retrieve the business type of the trigger condition? (equivalent to the types we had before)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes this could work

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

that may make the code a few less flexible than it was first intended but for readability's sake it might be better indeed

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I added the TriggerConditionType enum.

cnecStatusMap.forEach((cnecId, cnecStatus) -> {
if (cnecStatus.isValid()) {
Cnec<?> cnec = crac.getCnec(cnecId);
UsageMethod usageMethod = getUsageMethod(cnecStatus.elementCombinationConstraintKind(), isSchemeRemedialAction, instant, remedialActionType);
if (isOnConstraintInstantCoherent(cnec.getState().getInstant(), instant)) {
remedialActionAdder.newOnConstraintUsageRule()
remedialActionAdder.newTriggerCondition()
.withInstant(instant.getId())
.withCnec(cnecId)
.withUsageMethod(usageMethod)
Copy link
Collaborator

Choose a reason for hiding this comment

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

we might as well rename UsageMethod, it doesn't make sense anymore

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes, we discussed about this with @phiedw and agreed a new name may be better
the question is: how should we rename it?

@@ -368,11 +368,11 @@ Set<FlowCnec> gatherFlowCnecsForAutoRangeAction(RangeAction<?> availableRa,
Network network) {
// UsageMethod should be FORCED
if (availableRa.getUsageMethod(automatonState).equals(UsageMethod.FORCED)) {
if (availableRa.getUsageRules().stream().filter(usageRule -> usageRule instanceof OnInstant || usageRule instanceof OnContingencyState)
.anyMatch(usageRule -> usageRule.getUsageMethod(automatonState).equals(UsageMethod.FORCED))) {
if (availableRa.getTriggerConditions().stream().filter(triggerCondition -> triggerCondition.getCnec().isEmpty() && triggerCondition.getCountry().isEmpty())
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not a fan of checking emptiness of attributes to know if an RA is applicable... we should discuss how to improve this design

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I agree, I just did this as a temporary solution for the behavior to be the same before and after the new code
But this is not elegant at all and I think there are some design discussions needed here

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I changed this by checking the type of TriggerCondition. If you think this is a better way to do, we could generalize the usage elsewhere in the code (mainly in tests).

@pet-mit pet-mit marked this pull request as draft June 26, 2024 15:06
bqth29 added 5 commits June 27, 2024 10:58
Signed-off-by: Thomas Bouquet <[email protected]>
Signed-off-by: Thomas Bouquet <[email protected]>
Signed-off-by: Thomas Bouquet <[email protected]>
# Conflicts:
#	data/crac-io/crac-io-json/src/test/java/com/powsybl/openrao/data/craciojson/CracImportExportTest.java
#	data/rao-result/rao-result-json/src/test/java/com/powsybl/openrao/data/raoresultjson/RaoResultRoundTripTest.java
Signed-off-by: Thomas Bouquet <[email protected]>
bqth29 and others added 3 commits June 27, 2024 14:19
# Conflicts:
#	data/crac-creation/crac-creator-csa-profiles/src/test/java/com/powsybl/openrao/data/craccreation/creator/csaprofile/craccreator/cnec/FlowCnecCreationTest.java
#	data/crac-creation/crac-creator-csa-profiles/src/test/java/com/powsybl/openrao/data/craccreation/creator/csaprofile/craccreator/remedialaction/GroupRemedialActionTest.java
#	data/crac-creation/crac-creator-csa-profiles/src/test/java/com/powsybl/openrao/data/craccreation/creator/csaprofile/craccreator/remedialaction/PstRangeActionCreationTest.java
#	data/crac-creation/crac-creator-csa-profiles/src/test/java/com/powsybl/openrao/data/craccreation/creator/csaprofile/craccreator/remedialaction/RemedialActionCreationTest.java
#	data/crac-io/crac-io-json/src/main/java/com/powsybl/openrao/data/craciojson/JsonSerializationConstants.java
#	data/crac/crac-impl/src/test/java/com/powsybl/openrao/data/cracimpl/OnConstraintAdderImplTest.java
#	data/crac/crac-impl/src/test/java/com/powsybl/openrao/data/cracimpl/OnFlowConstraintInCountryAdderImplTest.java
Signed-off-by: Thomas Bouquet <[email protected]>
@bqth29 bqth29 closed this Aug 19, 2024
@bqth29
Copy link
Collaborator Author

bqth29 commented Aug 19, 2024

Since the code must be made common with PowSyBl (cf. #1067) I suggest to close this PR for the moment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change Changes could break users' code cleaning This issue or pull request only concerns improving the overall state of the code experiment This subject is experimental and needs to be discussed thoroughly first feature New feature or request PR: waiting-for-review This PR is waiting to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use logical gates for usage rules conditions
2 participants