-
Notifications
You must be signed in to change notification settings - Fork 16
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
Linopy Integration #351
base: main
Are you sure you want to change the base?
Linopy Integration #351
Conversation
Hello @GbotemiB! Thanks a lot for opening the PR! Currently, CI is failing, and it looks like the reason is the recent environment troubles we experienced in PyPSA-Earth. Those troubles have been fixed recently with this PR and merged into Linopy PR in PyPSA-Earth. Could you please change the update the commit on which your PR relays? I think, this one should work fine. |
Hi @ekatef, Thanks for looking into this. I will review the changes and revert. |
if co2_stores.empty or ("Store", "e") not in n.variables.index: | ||
if co2_stores.empty: # or ("Store", "e") not in n.variables.index: |
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.
Just for better understanding: what has been the reason of commenting-out the second part of the conditon?
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.
The variables method no longer exists in the network, which is why I commented it out. I also noticed something in pypsa-eur implementation.
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.
You mean n.variables
component, right?
Agree that some adjustment may be needed, but we have to avoid losses in functionality. It would be great to understand the purpose of having ("Store", "e") not in n.variables.index
condition here, check if it's still needed and find a way to re-implement it. May be a good point to discuss with the cross-sectoral team.
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 don't know the reason or the functionality. But, I checked similar implementations in pypsa-eur, before the linopy integration, and after the integration, and it seems to have been done in the same way.
Thanks a lot @GbotemiB! The update has worked 🎉 The PR itself looks great! Is it ready for review? |
@ekatef, the PR is ready for review. I didn't mark it for review because the Linopy PR in pypsa-earth is still in draft. I have investigated the error in the CI. It relates to |
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.
Hello :D
Just adding few cents :)
Great @GbotemiB :D
config.default.yaml
Outdated
|
||
mem: 30000 #memory in MB; 20 GB enough for 50+B+I+H2; 100 GB for 181+B+I+H2 | ||
walltime: "12:00:00" |
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.
In pypsa-eur, the standard parameter is "runtime", may be good to revise?
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.
Thanks @davide-f, I will check it out.
scripts/solve_network.py
Outdated
lhs = ( | ||
(1 * link_p.loc[heat_ext]), | ||
(1 * link_p.loc[electric_ext]), | ||
(1 * link_p_nom.loc[electric_ext]), | ||
) |
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.
This one cannot work.
It feels to me that probably we need to slightly change the CI options to enable more of these functions to actually be tested.
Moreover, pay attention on signs, it seems something has went wrong here
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.
Thanks @davide-f for catching this. I will revise the implementation.
vars_final_co2_stored = get_var(n, "Store", "e").loc[sns[-1], co2_stores] | ||
vars_final_co2_stored = n.model["Store-e"].loc[sns[-1], co2_stores] |
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.
As a general comment, indexing in linopy
may be a bit delicate. My observation is that there may be no one-to-one correspondence with old functions. Some testing may be needed, especially there is no exact match with PyPSA-Eur.
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.
Do you have any ideas on how we can test the functionalities?
from my end, I think we can test the original functionalities alongside the new ones, and compare the results.
lhs = linexpr((1, vars_final_co2_stored)).sum() | ||
lhs = (1 * vars_final_co2_stored).sum() |
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.
Not sure we need to multiply by 1
here and in all similar fragments.
My understanding is that a linopy equivalent of linexpr((1, vars_final_co2_stored)).sum()
is vars_final_co2_stored.sum()
. But that is not necessarily 100% correct understanding, and happy to discuss. Do you have any ideas on that? Have you tested these parts?
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.
You are right. The 1
multiple is redundant. I did a bit of debugging to verify the expression already. However, I am open to more ways to test these implementations.
Hello @GbotemiB! Very nice and quite comprehensive work! Thank you for addressing the review comments. I think, now we have a good basic linopy-based implementation both for pypsa-earth and pypsa-earth-sec. The next step must be a good testing, as Absolutely agree with @davide-f that CI doesn't catch the points which are crucial for functionality of both
@GbotemiB does the plan sound reasonable for you? |
@ekatef Sounds perfect. I think in terms of priority, |
I should also mention here that in the original pypsa-earth-sec, the test config results in |
|
dd3102c
to
b4c4b74
Compare
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.
Few comments; great @GbotemiB! :D
As a comment, do you feel like by simply changing few parameters in the config test yaml, the functions you modified could be included in the CI?
That may ease the process (if we also fix the CI, but that may not be done here)
Snakefile
Outdated
clustered_pop_layout="resources/population_shares/pop_layout_elec_s{simpl}_{clusters}_{planning_horizons}.csv", | ||
clustered_pop_layout="resources/population_shares/pop_layout_elec_s{simpl}_{clusters}.csv", |
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.
Please, check the main, probaly one merge conflict didn't go well
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.
this applies for changes below too
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.
Thanks for catching this. I have resolved the merge conflict.
scripts/solve_network.py
Outdated
h2_network_cap = n.model["Link-p_nom"] | ||
lhs = (h2_network_cap.loc[h2_network.index] * h2_network.length).sum() |
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.
Please, check the merge conflict; an if-case has been dropped unfortunately
Hi @davide-f, could you please clarify what you mean here? |
Some functions in the solve_network are triggered by options in the config file, some of them may be off by default which means that they are not tested. |
The option to test the |
Closes # (if applicable).
Changes proposed in this Pull Request
Integrate linopy following PyPSA/pypsa-eur#625 and pypsa-meets-earth/pypsa-earth#796
Checklist
envs/environment.yaml
andenvs/environment.docs.yaml
.config.default.yaml
,config.tutorial.yaml
, andtest/config.test1.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.