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

Revise network simplification to account for DC lines #743

Merged
merged 41 commits into from
Jul 12, 2023

Conversation

ekatef
Copy link
Member

@ekatef ekatef commented May 23, 2023

Closes #621

Changes proposed in this Pull Request

DC lines are added to a simplification procedure to be treated in the same way as links.

Checklist

  • I consent to the release of this PR's code under the AGPLv3 license and non-code contributions under CC0-1.0 and CC-BY-4.0.
  • I tested my contribution locally and it seems to work fine.
    • Philippines
    • Congo Democratic Republic
    • Japan
    • China
    • India
    • Nigeria
  • Code and workflow changes are sufficiently documented.
  • Newly introduced dependencies are added to envs/environment.yaml and doc/requirements.txt.
  • Changes in configuration options are added in all of config.default.yaml and config.tutorial.yaml.
  • Add a test config or line additions to test/ (note tests are changing the config.tutorial.yaml)
  • Changes in configuration options are also documented in doc/configtables/*.csv and line references are adjusted in doc/configuration.rst and doc/tutorial.rst.
  • A note for the release notes doc/release_notes.rst is amended in the format of previous release notes, including reference to the requested PR.

NB Testing configuration assumed dc_as_lines for all the countries above and gadm clustesing for CD, PH and NG (as gadm clustering seems currently to be more prone to troubles) while usual hierarchical clustering was used for JP, IN and CN to use pre-calculated shapes keeping computational costs moderate.

@ekatef
Copy link
Member Author

ekatef commented May 23, 2023

Current implementation seems to reproduce desirable topology transformations, but should be adjusted in part of related to equivalent parameters calculation of the resulted links

@ekatef
Copy link
Member Author

ekatef commented Jun 17, 2023

Detailed checking of the network structure for CD has revealed some issues related to simplification of "meshed" DC grid. HVDC part consists of two parallel lines. Geometrically each of the parallel lines connects the same buses but has slightly different coordinates:

image

These two lines get merged in course of simplification, except a single segment where lines duplication is kept:

image (different colours are used just to highlight different lines of the same DC part)

@ekatef
Copy link
Member Author

ekatef commented Jun 17, 2023

The suggested modification of simplify_network works with hvdc_as_lines: true in the same way as hvdc_as_lines: false. To check it an "analytical" approach should be used as simple visual check is a bit tricky due to overlapped geometries. A good indicator is n.lines[n.lines.dc][["bus0", "bus1"]] vs n.links][["bus0", "bus1"]] which is for a simplified network as follows:

before modification

Line,bus0,bus1
49423895_0,30,36
224147292_0,36,51
261165614_0,37,53
383097966_0,37,52
460419487_0,30,36
461638193_0,36,51
626214770_0,44,37
778351007_0,51,8
778351009_0,51,8
778351020_0,44,37
979570585_0,53,52
979570586_0,52,30
979570588_0,52,30

Link,bus0,bus1
convert_3_8,8,7
convert_29_44,44,43

after modification

Line,bus0,bus1
383097966_0,37,52

Link,bus0,bus1
261165614_0+1,52,37
460419487_0+4,52,7
778351020_0+1,43,37

The PR ensures that a result of the network simplification is the same regardsless of hvdc_as_lines value with the only difference that for the buses 37,52 a duplicating connection is a (second) link if hvdc_as_lines: false and a DC line otherwise

So, the next step is to resolve an issue with the duplication remained in the simplified network

@ekatef
Copy link
Member Author

ekatef commented Jun 18, 2023

It looks like split_links collects chains of links starting from each supernode going along a graph to be further used for merging into a single link. All parallel links (like those between 51 and 8 buses, for example) are being captured by adj() function

So, merging 37-53 + 53-52 is in scope of the algorithm, while adding 37-52 seems to need to introduce some modifications into it

@davide-f
Copy link
Member

Hello @ekatef and very interesting contributions! Much needed.
I understand this is a work in progress, but I plan to give it a look for a preliminary review later.
As a quick comment, what do you mean with 'merging 37-53 + 53-52 is in scope of the algorithm, while adding 37-52 seems to need to introduce some modifications into it'?
Especially the second half of the sentence.

Many thanks! :)

@ekatef
Copy link
Member Author

ekatef commented Jun 18, 2023

Hello @ekatef and very interesting contributions! Much needed. I understand this is a work in progress, but I plan to give it a look for a preliminary review later. As a quick comment, what do you mean with 'merging 37-53 + 53-52 is in scope of the algorithm, while adding 37-52 seems to need to introduce some modifications into it'? Especially the second half of the sentence.

Many thanks! :)

Hello @davide-f and many thanks for support, as usually! :)

The numbers refer to the second picture in the comment above. I have been thinking that lines duplication left after simplification could be a bug which can be fixed by some simple trick. But it looks some deeper changes are needed if we are not happy with the resulted configuration of a simplified network. The question is if it's really needed :D

@ekatef
Copy link
Member Author

ekatef commented Jun 18, 2023

As discussed with @davide-f, the best approach to tackle this issue with the parallel links remained after simplification might be just to apply simplify_links twice

@ekatef
Copy link
Member Author

ekatef commented Jun 25, 2023

It looks like we have previously missed some modifications in calculations on transmission costs needed to make representation of HVDC as lines work properly. In particular:

  1. underwater_fraction should be calculated for n.lines with "DC" carries in base_network;
  2. when updating transmission costs in add_electricity, the parameters should be taken from n.lines instead of n.links

Have drafted possible implementation of these changes in base_network and add_electricity. There is some code repetition in both cases as I haven't been able to find a flexible enough way to distinguish between lines and links.

@davide-f would be very grateful if you could find time to have a look :)

@ekatef ekatef mentioned this pull request Jun 30, 2023
8 tasks
@davide-f
Copy link
Member

Hello katia :)
I've scanned it and there are quite interesting changes.
It is a big PR, so I may need some time to review entirely.
I'll go thought it in the weekend, I give some brief comments now as a preliminary element, but I need to go better in the code later on.

Copy link
Member

@davide-f davide-f left a comment

Choose a reason for hiding this comment

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

Amazing job! :D
I've added some comments, on the chaining functionality in simplify_network I recall we talked about that and was ok.
I'll need another round maybe guided to address the functionality, but it was working well , right?
Fantastic Katia! :D

scripts/add_electricity.py Outdated Show resolved Hide resolved
scripts/add_electricity.py Show resolved Hide resolved
scripts/add_electricity.py Outdated Show resolved Hide resolved
scripts/base_network.py Outdated Show resolved Hide resolved
scripts/add_electricity.py Outdated Show resolved Hide resolved
@ekatef
Copy link
Member Author

ekatef commented Jul 1, 2023

Thank you so much, Davide! There are still some troubles with functionality which I'm going to work on during the weekend. I'll ping you when ready :)

@ekatef
Copy link
Member Author

ekatef commented Jul 6, 2023

Testing status: seems to work except a case when the augmentation option on:

  • in case of "CD" the troubles are linked with mixed-carrier issue (most likely due to lines/links overlap as explained in the first comments) [seems to be fixed, although there is still a mixed-carriers warning in case of expansion with [HVAC]];
  • in case of "PH" there are some NaNs introduced into the network [fixed]

So, augmentation needs better investigation while otherwise PR is ready for testing.

@Tomkourou if you wish to help with testing, you are absolutely welcome :)

@ekatef ekatef marked this pull request as ready for review July 8, 2023 09:45
Copy link
Member

@davide-f davide-f left a comment

Choose a reason for hiding this comment

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

Very nice! I think this PR will be merged by next meeting , we are very close and great contribution! :)

So, is the algorithm finalized in your opinion? @ekatef

Is the only problem related to CD with augmentation by hvac?

scripts/add_electricity.py Outdated Show resolved Hide resolved
scripts/base_network.py Outdated Show resolved Hide resolved
scripts/cluster_network.py Outdated Show resolved Hide resolved
scripts/simplify_network.py Outdated Show resolved Hide resolved
Comment on lines 295 to 296
dc_as_links = not n.links.loc[n.links.carrier == "DC"].empty
dc_as_lines = not n.lines.loc[n.lines.carrier == "DC"].empty
Copy link
Member

Choose a reason for hiding this comment

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

were you looking for the flag in config maybe? In case, you could pass it as a parameter here, what do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I have been thinking about taking a flag directly from the config, but decided to try reading it from the network itself. The idea was to make it safer, although agree that it might be not clear.

Happy to revise if you think it'd be better to used a flag from the config

Copy link
Member

Choose a reason for hiding this comment

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

Mah... agree that we could avoid overcomplicating the code.
We could do the check internally, however, it may be safer to check for dc lines:
dc_as_links = not (n.lines.carrier == "DC").any()
and implicitly assume that when it is false than we used lines

As even when lines are included, converters represented as links will be necessary as well, therefore, with the current formulation dc_as_links will always be true.

the if below where you check: if dc_as_links: .... elif dc_as_lines, may be revised with: if dc_as_links: ... else: ... so replacing the elif with else.

I'm unsure if some issues may be fixed with this but i'm unsure

Copy link
Member Author

Choose a reason for hiding this comment

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

That is definitely cleaner :)
Thanks for explanations! Done

scripts/simplify_network.py Outdated Show resolved Hide resolved
Comment on lines 412 to 420
p_nom = (
n.lines.loc[all_dc_lines]
.apply(
lambda x: x["v_nom"] * n.line_types.i_nom[x["type"]],
axis=1,
result_type="reduce",
)
.min()
)
Copy link
Member

Choose a reason for hiding this comment

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

Theoretically, there should be the column s_nom that contains the nominal capacity of the line: is it filled properly?
If so, you may use that column here.

However, you raised an interesting point: in simplify_network_to_380 we still assume that all lines are AC, it may be interesting to debug what happens there with DC lines.
In particular, the num_parallel is most likely calculated in a wrong way

Copy link
Member Author

@ekatef ekatef Jul 8, 2023

Choose a reason for hiding this comment

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

Mmm, you are absolutely right: there is s_nom in n.lines, and it's value is exactly 3 times lower as compared with U*I used above. It feels like there is in fact some discrepancy with num_parallel

Copy link
Member

Choose a reason for hiding this comment

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

Interesting check, so, the comment here may be that instead of calculating the power by using V*I , it may be better to directly use s_nom.
So regarding the code, I recommend to use s_nom here directly, ideally fixing the calculation of V*I for dc lines.
What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

scripts/simplify_network.py Outdated Show resolved Hide resolved
@ekatef
Copy link
Member Author

ekatef commented Jul 8, 2023

Very nice! I think this PR will be merged by next meeting , we are very close and great contribution! :)

So, is the algorithm finalized in your opinion? @ekatef

Is the only problem related to CD with augmentation by hvac?

@davide-f thank you for the amazing review! Very heplful :D

My feeling is that we are in fact quite close to finalise. From my perspective, augmentation is a major problem left. Apart of that, I'm also concerned with the recent testing results.

All the tested countries work with dc_as_lines: true and the results up to simplify_network looks quite nice. But clustering outputs are sometimes a bit puzzling. In particular, the usual hierarchical algorithm sometimes complains that n_cluster is too big and agrees to work only if n_cluster is decreased from 10 to only 2. Obviously, that leads to some strange outputs, for example:

base network

image

simplified network

image

clustered network

image

@ekatef
Copy link
Member Author

ekatef commented Jul 8, 2023

Clustering results might be generally not very stable in respect to parameters selection like to remove stubs or not to remove :) But it would be a good idea to double-check that the clustering issues above are not being introduced with this PR. On the other hand, clustering problems were found for CN and IN only where old pre-calculated shapes were used. Probably, that has also played a role...

@davide-f I do remember that you have suggested to account for generators/loads attached to the nodes when making simplification. At the moment the algorithm doesn't do for that, while my feeling is that it could be worth to improve this

@ekatef
Copy link
Member Author

ekatef commented Jul 9, 2023

I confirm that clustering troubles are not connected with this PR. A test for IN with the same configuration parameters has resulted in the same limitation on n_cluster. Not sure it's good news from the general perspective, but for this PR that means that basically the only point left is fixing of the equivalence calculations

Comment on lines 412 to 420
p_nom = (
n.lines.loc[all_dc_lines]
.apply(
lambda x: x["v_nom"] * n.line_types.i_nom[x["type"]],
axis=1,
result_type="reduce",
)
.min()
)
Copy link
Member

Choose a reason for hiding this comment

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

Interesting check, so, the comment here may be that instead of calculating the power by using V*I , it may be better to directly use s_nom.
So regarding the code, I recommend to use s_nom here directly, ideally fixing the calculation of V*I for dc lines.
What do you think?

scripts/simplify_network.py Outdated Show resolved Hide resolved
@davide-f davide-f merged commit 186d2d2 into pypsa-meets-earth:main Jul 12, 2023
3 checks passed
@davide-f
Copy link
Member

Great @ekatef :D merged :)

@ekatef
Copy link
Member Author

ekatef commented Jul 12, 2023

Great @ekatef :D merged :)

Awesome! Thank you so much @davide-f :D

@ekatef ekatef deleted the simplify_dc_lines branch November 14, 2023 22:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Revision of simplify_links to account for DC lines
2 participants