-
Notifications
You must be signed in to change notification settings - Fork 437
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
ptdf calculation #604
base: master
Are you sure you want to change the base?
ptdf calculation #604
Conversation
for more information, see https://pre-commit.ci
I have the suspicion that small impedances cause numerical problems in the PTDF calculation - can someone confirm or check? Possibly a warning could be put in consistency check if the impedances are too far apart. |
Do you have a small example where you see numerical problems in the PTDF calculation, that could help us reproduce the behaviour? Regarding the PR: I think using the scipy inversion function makes a lot of sense; also turning PTDF and BODF into DataFrames. But the tests fail because the code is not yet fully adapted to take DataFrames rather than numpy arrays for these. |
Hi, yes I realized, I'll debug. There's a sum in the bodf calculation that adds a numpy matrix and a scipy sparse, that fails at the moment. Maybe the possibility of keeping Ptdf and bodf sparse was a reason for returning pure numpy in the first place...
Am 15. Apr. 2023, 11:08, um 11:08, Fabian Neumann ***@***.***> schrieb:
…Do you have a small example where you see numerical problems in the
PTDF calculation, that could help us reproduce the behaviour?
Regarding the PR: I think using the scipy inversion function makes a
lot of sense; also turning PTDF and BODF into DataFrames. But the tests
fail because the code is not yet fully adapted to take DataFrames
rather than numpy arrays for these.
--
Reply to this email directly or view it on GitHub:
#604 (comment)
You are receiving this because you authored the thread.
Message ID: ***@***.***>
|
I had a case where the B matrix had entries of 1e9 - the solver reported a singular matrix. Scaling down actually "solved" it but adapting the impedance spread is maybe better. I'll extract an example.
Maybe an optional sparse return format for ptdf and bodf could be an unstacked version of a Dataframe ie multi index pandas Series with cutoff?
Am 15. Apr. 2023, 11:08, um 11:08, Fabian Neumann ***@***.***> schrieb:
…Do you have a small example where you see numerical problems in the
PTDF calculation, that could help us reproduce the behaviour?
Regarding the PR: I think using the scipy inversion function makes a
lot of sense; also turning PTDF and BODF into DataFrames. But the tests
fail because the code is not yet fully adapted to take DataFrames
rather than numpy arrays for these.
--
Reply to this email directly or view it on GitHub:
#604 (comment)
You are receiving this because you authored the thread.
Message ID: ***@***.***>
|
Updates on my side:
|
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
This is probably on me but I have problems with pytest - pandapower and it's numba dependency I think. Sorry for the failed checks, hope it starting to take form. |
for more information, see https://pre-commit.ci
Hi @fneum , I replaced the usage of BODF and PTDF is a dozen places; and I feel it really makes sense to continue with pandas instead of the annonymous numpy. Some further things should be cleaned up, I patched it in some places... Best, |
@fneum One test fails concerning tkinter and some plotting library - it passes on my machine. |
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## master #604 +/- ##
==========================================
- Coverage 78.15% 78.14% -0.01%
==========================================
Files 26 26
Lines 6756 6773 +17
Branches 1470 1473 +3
==========================================
+ Hits 5280 5293 +13
- Misses 1162 1164 +2
- Partials 314 316 +2
☔ View full report in Codecov by Sentry. |
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.
Sorry for taking a long time to get to this! This looks very good!
I had a few small questions. Maybe you can answer them.
Have you tested that the code changes yield same PTDF as before?
The one test failure is fine.
Final thing: Would you add a release note outlining the changes? I.e. BODF and PTDF are now dataframes and new utility function to build PTDF for whole network.
def get_network_ptdf(network): | ||
# convenience function | ||
|
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.
Maybe add a small docstring that this gives PTDF for whole network (not per subnetwork).
sub_network.p_branch_shift = ( | ||
-b * phase_shift | ||
) # np.multiply(-b, phase_shift, where=b != np.inf) |
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 briefly explain why where=b != np.inf
is no longer needed?
And remove old code.
logger.warning( | ||
"Warning! Some series impedances are zero - this will cause a singularity in LPF!" | ||
) | ||
b_diag = csr_matrix((b, (r_[: len(b)], r_[: len(b)]))) | ||
|
||
# old: b_diag = csr_matrix((b, (np.r_[: len(b)], np.r_[: len(b)]))) |
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.
# old: b_diag = csr_matrix((b, (np.r_[: len(b)], np.r_[: len(b)]))) |
# susceptances | ||
b = np.divide(1.0, z, out=np.full_like(z, np.inf), where=z != 0) | ||
# old: b = np.divide(1.0, z, out=np.full_like(z, np.inf), where=z != 0) |
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.
# old: b = np.divide(1.0, z, out=np.full_like(z, np.inf), where=z != 0) |
# I = eye(n_pvpq) | ||
# B_inverse = spsolve(csc_matrix(sub_network.B[1:, 1:]), I) |
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 = eye(n_pvpq) | |
# B_inverse = spsolve(csc_matrix(sub_network.B[1:, 1:]), I) |
@@ -24,10 +24,11 @@ | |||
from numpy import ones, r_ | |||
from numpy.linalg import norm | |||
from pandas.api.types import is_list_like | |||
from scipy.sparse import csc_matrix, csr_matrix, dok_matrix | |||
from scipy.sparse import csc_matrix, csr_matrix, diags, dok_matrix, eye |
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.
from scipy.sparse import csc_matrix, csr_matrix, diags, dok_matrix, eye | |
from scipy.sparse import csc_matrix, csr_matrix, diags, dok_matrix |
z = np.concatenate( | ||
[ | ||
(c.df.loc[c.ind, attribute]).values | ||
for c in sub_network.iterate_components(network.passive_branch_components) | ||
] | ||
) | ||
z = sub_network.branches()[attribute] |
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.
Oh, this looked very complicated beforehand.
Hi @fneum , great I'll check it out next week - agreed code needs a little polishing. With ptdf index, I'll check it once again that it's correct. |
Hey @Cellophil, gently pinging you. Do you think it is feasible for you to resolve the remaining issues? |
Hi, sry for the delay, I took parental leave. Time is unfortunately a bit limited atm, but I'll check things this week. Best, Andreas
Am 9. Okt. 2023, 18:02, um 18:02, Fabian Hofmann ***@***.***> schrieb:
…Hey @Cellophil, gently pinging you. Do you think it is feasible for you
to resolve the remaining issues?
--
Reply to this email directly or view it on GitHub:
#604 (comment)
You are receiving this because you were mentioned.
Message ID: ***@***.***>
|
Hey Andreas, no worries, thanks for letting us know. The young ones have full priority :) We can also try to take it from here. |
No description provided.