-
Notifications
You must be signed in to change notification settings - Fork 2
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
Improve docs and tests for PTDF calculation in Flow Decomposition #159
Conversation
Signed-off-by: Caio Luke <caioluke97@gmail.com>
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.
Thank you for your PR !
I have a lot of questions !
- Do you have any test to highlight this behavior ?
- Could you document the reason of the sign flipping in the documentation ?
- Is it an issue with any rescaler that are based on a terminal ?
- Could you refactor this code to avoid comments ?
- Could you provide something like an empty contingency to trigger the fixZeroFunctionReference instead of duplicating code ?
- Why are they not rescaling when there is no contingency ?
- Should this not be a PR in powsybl-open-loadflow ?
Thanks for your reply :) I have a test case but the data is confidential... I will try to come up with a minimal case |
Signed-off-by: Caio Luke <caioluke97@gmail.com>
@OpenSuze I managed to create a minimal case where the sign instability presents itself. It showed up in a different scenario from what I had previously described. However, I don't have a fix in mind for this one... Could you have a look and see if you can find anything? |
var ptdfs1 = report1.ptdfs.forBaseCase(); | ||
var ptdfs2 = report2.ptdfs.forBaseCase(); | ||
|
||
// Ensure that ptdf signs are the same with or without loss compensation |
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.
Could you explain why you want to keep the same ptdf sign with or without loss compensation please ?
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.
Actually, I expect the same PTDF results with or without loss compensation.
In this case the PTDF changes sign (+1 becomes -1) and to avoid thresholding I thought it would be simpler to only compare signs.
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.
Yes, I understand your test but I'm wondering why does it matter to keep the same pdtf value before or after loss compensation ?
From my point of view, loss compensation allows to to DC computations that are closer to AC computations without paying AC computation costs. So having slightly different PTDF between DC-loss-compensated PTDF and AC PTDF is expected.
Futhermore, I don't understand why this test might improve sign stability ?
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.
Keeping the same PTDF sign matters to have similar (not the same due to losses) allocated flows in flow decomposition results.
Here, PTDFs are not sligthly different, they are as different as they can be (+1 and -1). I'm betting it's a sign issue somewhere.
My test doesn't improve sign stability, it's just a minimal example showing there is one.
I haven't found out why this happens...
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.
I have investigated your issue.
The sign difference of the PTDF comes from the fact that we change the sign of the PTDF value (see SensitivityAnalyser line 93).
If we remove this sign modification, then there is no more issue with your test.
However, this sign modification is here to ensure that burdening flows are positive and relieving flows negative without having to consider the reference flow direction.
This sign modification is only here for easier understanding of the flow decomposition results.
More details are available here
Futhermore, it could be a great idea to refactor the SensitivityAnalyser line 93 to extract a static function with a good name such as respectFlowSignConvention
static double respectFlowSignConvention(double ptdfValue, double referenceFlow) {
return referenceFlow < 0 ? -ptdfValue : ptdfValue;
}
With this in mind, I think the best choice is to acknowledge this sign convention and change your test.
assertEquals(respectFlowSignConvention(ptdfValue1, dcFlow1.get(branchId)), respectFlowSignConvention(ptdfValue2, dcFlow2.get(branchId)), 1E-9);
This solution uses the fact that respectFlowSignConvention
is an involution (maybe we should test that as well).
Maybe we should document the sign convention in the PTDF observer part also.
Thanks to @phiedw and @wangjer for their help.
Thank you in advance,
Hugo
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.
Signed-off-by: Caio Luke <caioluke97@gmail.com>
# Conflicts: # flow-decomposition/src/test/java/com/powsybl/flow_decomposition/FlowDecompositionObserverTest.java
Signed-off-by: Caio Luke <caioluke97@gmail.com>
Signed-off-by: Caio Luke <caioluke97@gmail.com>
Quality Gate passedIssues Measures |
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.
Thank you for this PR !
Please check if the PR fulfills these requirements
What kind of change does this PR introduce?
Enhancement
What is the current behavior?
Lack of clarity in signed PTDF calculation.
What is the new behavior (if this is a feature change)?
Improve docs and tests about PTDF calculation respecting the flow sign convention.
Does this PR introduce a breaking change or deprecate an API?