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

Flexible setup of constraints for cooling technologies #242

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

adrivinca
Copy link
Contributor

@adrivinca adrivinca commented Oct 22, 2024

The PR changes some hard code to a flexible adjustment of constraints on cooling technologies, to improve flexibility

The cooling technologies are added as add-on to power plants (parent technologies). in some scenarios, however, the power plant are subject to constraints e.g. for phase-out, and the cooling tecnhologies growth_activity_lo need to be adjusted accordingly to avoid infeasibilities. Before this was done manually, now I added a function relax_growth_constraint that should do it automatically for each specific scenario.
I also added a test function to test the behavior of the function.

How to review

Check the code and test are in line with the standards.
Eventually run the code on a scenario at choice and see it the model solves mix-models --url=ixmp://ixmp_dev/%model%/%scenario% water-ix --regions=R12 cooling , maybe @measrainsey

PR checklist

  • Continuous integration checks all ✅
  • Add or expand tests; coverage checks both ✅
  • Update doc/whatsnew.

@glatterf42

This comment was marked as resolved.

@glatterf42 glatterf42 assigned adrivinca and unassigned measrainsey Oct 22, 2024
@glatterf42

This comment was marked as resolved.

@measrainsey measrainsey self-requested a review October 22, 2024 11:59
Copy link

codecov bot commented Oct 22, 2024

Codecov Report

Attention: Patch coverage is 87.50000% with 7 lines in your changes missing coverage. Please review.

Project coverage is 75.5%. Comparing base (687c4c4) to head (2f9625f).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...essage_ix_models/model/water/data/water_for_ppl.py 86.8% 5 Missing ⚠️
message_ix_models/model/water/cli.py 0.0% 1 Missing ⚠️
message_ix_models/model/water/data/water_supply.py 0.0% 1 Missing ⚠️
Additional details and impacted files
@@          Coverage Diff          @@
##            main    #242   +/-   ##
=====================================
  Coverage   75.5%   75.5%           
=====================================
  Files        203     203           
  Lines      15503   15545   +42     
=====================================
+ Hits       11706   11747   +41     
- Misses      3797    3798    +1     
Files with missing lines Coverage Δ
message_ix_models/model/water/report.py 7.9% <ø> (ø)
...odels/tests/model/water/data/test_water_for_ppl.py 100.0% <100.0%> (ø)
message_ix_models/model/water/cli.py 33.0% <0.0%> (-0.4%) ⬇️
message_ix_models/model/water/data/water_supply.py 77.2% <0.0%> (+0.8%) ⬆️
...essage_ix_models/model/water/data/water_for_ppl.py 93.9% <86.8%> (-0.7%) ⬇️

... and 1 file with indirect coverage changes

@measrainsey

This comment was marked as resolved.

@adrivinca
Copy link
Contributor Author

Thanks Frido and Meas.

I am not sure why this error appears, but I also had it on my machine, probably to do with some pandas update?

FAILED message_ix_models/tests/model/water/data/test_water_for_ppl.py::test_cool_tec[no_climate] - IndexError: index 0 is out of bounds for axis 0 with size 0
FAILED message_ix_models/tests/model/water/data/test_water_for_ppl.py::test_cool_tec[6p0] - IndexError: index 0 is out of bounds for axis 0 with size 0```

Copy link
Member

@glatterf42 glatterf42 left a comment

Choose a reason for hiding this comment

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

All in all, good work as far as the coding goes :)
However, I'd like to see several small improvements and please check why the tests are failing on this PR and ensure they don't do that.

message_ix_models/model/water/data/water_for_ppl.py Outdated Show resolved Hide resolved
message_ix_models/model/water/data/water_for_ppl.py Outdated Show resolved Hide resolved
message_ix_models/model/water/data/water_for_ppl.py Outdated Show resolved Hide resolved
message_ix_models/model/water/data/water_for_ppl.py Outdated Show resolved Hide resolved
message_ix_models/model/water/data/water_for_ppl.py Outdated Show resolved Hide resolved
message_ix_models/model/water/report.py Outdated Show resolved Hide resolved
@glatterf42
Copy link
Member

glatterf42 commented Oct 22, 2024

I am not sure why this error appears, but I also had it on my machine, probably to do with some pandas update?

FAILED message_ix_models/tests/model/water/data/test_water_for_ppl.py::test_cool_tec[no_climate] - IndexError: index 0 is out of bounds for axis 0 with size 0
FAILED message_ix_models/tests/model/water/data/test_water_for_ppl.py::test_cool_tec[6p0] - IndexError: index 0 is out of bounds for axis 0 with size 0```

To figure this out, you can recreate a virtual environment locally that has the same pandas and numpy and Python versions installed as one of the failing workflows. Then, try to run the tests in there and use a debugger or add auxiliary output print() to study the variables as you go.

What the error message says is that years[years > x] is a numpy array of size 0, so there's not a single element inside. Thus, when you try to access the [0]th element, numpy complains. That could be because x is too large or maybe years doesn't contain a single value to begin with.

@adrivinca adrivinca added the water MESSAGEix-Nexus (water) variant label Oct 23, 2024
Copy link
Member

@glatterf42 glatterf42 left a comment

Choose a reason for hiding this comment

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

I'm sorry, I tried to rebase this branch on main to keep it up to date (since some of @measrainsey's branches were merged earlier today), but this seems to have broken the tests again.
Thanks for fixing them before! If we fix them now and add this PR to doc/whatsnew (and @measrainsey's review comes in), I think we're close to getting this merged :)

@glatterf42
Copy link
Member

glatterf42 commented Oct 23, 2024

The errors were caused by updating sdmx1 to 2.19.0, let's see as to why exactly this happens...
Thanks to @khaeru for fixing this issue with the v2.19.1 release :)

@khaeru
Copy link
Member

khaeru commented Oct 24, 2024

@adrivinca given the name of this branch (wat_SSP_upd2) I assume this is related to #234, so I have added it in the list there. If that's not the case, please clarify.

@adrivinca
Copy link
Contributor Author

thanks, so the sdmx1 issue is solves, right?
@khaeru you are right, there will be many other, I will remember to add them to #234

I am quite in a tight timeline, so I'm happy with the current changes. I might add a couple of things before merge

@khaeru khaeru changed the title Flexible setup of contraints for cooling technologies Flexible setup of constraints for cooling technologies Oct 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
water MESSAGEix-Nexus (water) variant
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants