-
Notifications
You must be signed in to change notification settings - Fork 207
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
fix to avoid negative objective value #961
Conversation
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.
Great @GbotemiB :)
So, the change should not be placed here, but rather in prepare_network.
By looking at the code in prepare_network, we actually have a function "set_transmission_limits" that should do that, but it seems it is not working.
pypsa-earth/scripts/prepare_network.py
Line 188 in e4edb17
def set_transmission_limit(n, ll_type, factor, costs, Nyears=1): |
It may be good to investigate why, may you be interested in that?
Thanks @davide-f, However, when I changed s_nom to s_nom_min in base_network.py, it worked to prevent my networks from having negative objective values. I will run the prepare_network with a debug. Hopefully, I will be able to understand why it didn't work in the first instance. |
It works, but if that option is changed there, there can be problems if the user desire to not do capacity expansion on the network as p_nom doesnt get initialized properly. |
@GbotemiB not sure if you are also working here :) In case of problems, needs feel free to write :) |
@davide-f I have been able to finally debug the pypsa-earth/scripts/prepare_network.py Line 188 in e4edb17
It turns out the section of the highlighted code below doesn't get executed. pypsa-earth/scripts/prepare_network.py Lines 207 to 212 in e4edb17
The following image should give more context into why the conditional is not working. |
pypsa-earth/scripts/prepare_network.py Line 197 in e4edb17
@davide-f, If you don't mind, can you clarify the purpose of this section |
pypsa-earth/scripts/prepare_network.py Lines 191 to 196 in e4edb17
I also noticed that |
Nice catch! Great :D |
This was imported from pypsa-eur. |
This is instead expected as in the simplify_network phase, the whole network is simplified to a base voltage (e.g. 380kV) equivalent and we play with num_parallel to handle the equivalence. pypsa-earth/scripts/simplify_network.py Line 118 in e4edb17
|
I went through pypsa-earth/scripts/simplify_network.py Line 135 in e4edb17
|
I also found out that when I used replace lines_s_nom by n.lines.s_nom here, my solved network didn't have any negative objectives pypsa-earth/scripts/prepare_network.py Lines 207 to 212 in e4edb17
|
Hi @davide-f, It looks like the reason why pypsa-earth/scripts/simplify_network.py Lines 129 to 135 in 9168ca7
|
Regarding p_nom here pypsa-earth/scripts/prepare_network.py Lines 211 to 212 in e4edb17
During debugging, |
Hello! @GbotemiB it looks like you have done a quite intense investigation and found very nice bugs (in particular, the one which relates to loading the options from the file name looks great!!), However, the whole picture still looks a bit too complicated. I'd suggest to take a step back and clarify the architecture of the lines transformations workflow, starting from osm-extracted data up to the pre-solved network. I'll doing something similar at the moment and happy to support you with that. The resulted diagram would facilitate discussion of high-level features with @davide-f Once the intended path would have been clear, it will simplify testing and introducing fixes, as it'll be clear what should we expect at each stage. What do you think @GbotemiB? |
Thanks @ekatef. You are definitely right. I will start with clarifying the workflow. |
Ok, the problem is in lines and can you confirm that the following code is executed? pypsa-earth/scripts/prepare_network.py Lines 206 to 211 in de4da14
|
Moreover:
Many thanks! |
Checking pypsa-eur prepare_network.py This is the part that has to do with lines that is present in PyPSA-Eur but not in PyPSA-Earth |
I also already confirm that this part is executed in the workflow.
Also in pypsa-eur, s_nom_min is not specified in base_network. |
Ok, so @GbotemiB I understand that the problem is back about why the s_nom_min calculated here differs from the p_nom value available in the network right? |
Hi @davide-f, I haven't figured out the cause of the missing names in the line type. I will investigate the clustering procedure to see if something has been missed there. |
Interesting @GbotemiB ! We are getting closer to the problem! |
Just a little clarification. The difference section was between p_nom_opt and p_nom, while the other was between s_nom and s_nom_min. I wanted to observe the changes in the workflow for s_nom and s_nom_min. |
I have updated the notebook here. I also rearranged the process for ease of understanding. I also noticed that num_parallel was not included in the calculation formula. Was it intentional? |
Cool Emmanuel, apologies missed communication. (np.sqrt(3)
* base.lines["type"].map(base.line_types.i_nom)
* base.lines.v_nom
* base.lines.num_parallel).sum() We are moving forward! 🚀 :D |
Amazing progress @GbotemiB ! :D :D Somewhere there some calculations are performed. To debug that, I'd create a simple auxiliary function that computes the i_nomv_nomnum_parallel product, reads the s_nom value and check if the values match and print the results. I'd test that for the various modified functions across the script to identify where the occurrence arrives. What do you think? |
@davide-f, I'm glad we identified the simplify_network script as the source of the issue. |
Great :D Thank you!!! |
Hello @davide-f, I looked over the I added the line to my local files in the script:simplify_network_to_base_voltage.py, this seems to resolved the negative objective issue. What are your thoughts? |
I have also updated the notebook here with the recent changes I made. |
Really? Yeah, definitely that should be added, however, instead of having "380" fixed, it should be base_voltage. It seems a too easy fix... XD Update: I've better checked the script but unfortunately that does not solve the issue. By comparing the values, for example, for siml, |
@davide-f, I will check the notebook again. But I tested the implementation against the monte-carlo notebook. The negative objective values seem to not be present. |
I understand, but the objective can still be misleading. |
@davide-f, Looks like I forgot to update the path in the notebook. I think we can smile now 😄 |
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.
Great @GbotemiB :D
Would you like to add a release note? :)
This PR is ready to fly! :)
Many thanks @GbotemiB ! Merging :) |
Closes #956
Changes proposed in this Pull Request
The changes in the PR is as suggested in #956 which is to adjust the lines in
base_network.py:_set_lines_s_nom_from_linetypes
froms_nom
tos_nom_min
to prevent negative objective values after solving network.Checklist
envs/environment.yaml
anddoc/requirements.txt
.config.default.yaml
andconfig.tutorial.yaml
.test/
(note tests are changing the config.tutorial.yaml)doc/configtables/*.csv
and line references are adjusted indoc/configuration.rst
anddoc/tutorial.rst
.doc/release_notes.rst
is amended in the format of previous release notes, including reference to the requested PR.