-
Notifications
You must be signed in to change notification settings - Fork 154
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
Regional emission pools #514
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #514 +/- ##
=======================================
- Coverage 93.8% 93.1% -0.8%
=======================================
Files 40 41 +1
Lines 3057 3235 +178
=======================================
+ Hits 2870 3014 +144
- Misses 187 221 +34
|
@volker-krey - I have added a checklist of tasks to be completed. The initial setup now works and the calculations for the tutorial seem correct (see attached calculation in xlsx: Westeros_Calculation_check.xlsx).
|
Please read this file message_ix/message_ix/models.py Lines 75 to 77 in 1da3136
You are correct that some things like this were originally done in the Java/ixmp_source/JDBCBackend code, but we are trying to move away from that. This is in order to have a cleaner separation between the layers of the stack, which means that See for example how this was done in #190: https://github.com/iiasa/message_ix/pull/190/files#diff-62f44bbc1d152875567f99d639addb547727233454fe1958278c45770d6a2912 |
In the PR, we have already updated |
For these "generated", "derived", or "mapping" sets, there are at least three approaches:
IMHO (3) is preferable for a few reasons:
|
@OFR-IIASA @behnam-zakeri I'm happy to jump in here at some point to demo how the code for the dynamic derivation of the |
@khaeru many thanks for offering this. I think we are at a stage now where your suggestion makes sense to implement. We have completed the updates to the core formulation and are now at the stage where we want to cleanup the PR in preparation for merging. |
Thanks for the heads-up! Added to my queue. |
Now done.
|
13a7154
to
d5c48b2
Compare
Thanks @khaeru for adding the code.
I have adjusted the tests accordingly.
Thanks, I have adjusted the tutorial notebook.
I have rebased the branch. Lastly, I have also added a test to check the removal of the parameter |
|
||
# Not consistent; empty and then re-populate the set | ||
with scenario.transact(f"Enforce consistency of {set_name} and {par_name}"): | ||
scenario.remove_set(set_name, existing) |
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.
@OFR-IIASA this line is supposed to entirely clear the set before it is populated by the next line. You could perhaps check whether this is having the intended effect.
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.
@khaeru I have added a two tests to see if this feature works correctly.
- Test 1. adds the parameter
bound_emission_pool
for 2 periods, solves and checksis_bound_emission_pool
.
The bound is then extended across another period, solved and checksis_bound_emission_pool
- Test 2. adds the parameter
bound_emission_pool
for 3 periods, solves and checksis_bound_emission_pool
.
Thebound_emission_pool
is removed.
Thebound_emission_pool
is then re-added, but only for two periods, solved and checksis_bound_emission_pool
.
Both the tests work and confirm the working of the code above.
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.
@khaeru The above code has tests, but for the functionality for which the code, in my understanding was designed. The design was to ensure that the "is_*" is consistent when the corresponding parameters is being modified; the code does not cover the removal of the corresponding parameter. The removal is test in a test test_bound_emission_pool_removal()
, which fails.
Further, this code is only executed for model="MESSAGE"
, not when passing the argument model="MESSAGE-MACRO"
as part of the solve command.
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 design was to ensure that the "is_*" is consistent when the corresponding parameters is being modified; the code does not cover the removal of the corresponding parameter. The removal is test in a test test_bound_emission_pool_removal(), which fails.
Thanks for directing to this specific test. To be clear:
- The added
enforce()
method is called at the moment the model is run/solved. - In the final lines of that test, there is a call to
.remove_par("bound_emission_pool", …)
, then a call to.commit()
but—unlike the other tests—there is no call to.solve()
before.set("is_bound_emission_pool")
is checked. - So
enforce()
is never invoked, and the result is as expected. - I suspect that if you called
.solve()
before checking the set, then the test would pass.
More detail: a possible choices would be to have enforce()
run (a) on every call to .commit()
, or even (b) on every call to .add_par()
. The current choice is deliberate: it mirrors the behaviour of the Java code underlying JDBCBackend, which only creates these mapping/etc. sets at the moment the data is written out to GDX. That Java code must someday be ported into message_ix. enforce()
is now the destination for that code and runs at the same point.
I thought this was better than introducing 1+ additional points at which data is massaged automatically; it would be complex and confusing additional work to think through and plan for possible interactions of these automatic changes. We unfortunately do not have the bandwidth for that at the moment.
Further, this code is only executed for model="MESSAGE", not when passing the argument model="MESSAGE-MACRO" as part of the solve command.
This I can check, and will do after you try adjusting the test.
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 finally got around to sorting out the tests. All tests pass; now the issue would be to ensure that we have this working when the calling solve(model="MESSAGE-MACRO")
. Unfortunately I dont think we have a simple test-case which can be adapted and run with macro.
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 can try to look at this next week, after we've wrapped up the current release.
eb35504
to
14e6402
Compare
- added new parameter emission_sink_rate - added new equation EMISSION_POOL with variable EMISS_POOL - possibility to limit size of pools via constraint currently not included - note that I did not run the code, so it has not been tested for correct syntax
…n documentation switching order of terms has no impact on results, but is more logical when presenting the material
14e6402
to
c7016ad
Compare
added new parameter emission_sink_rate
added new equation EMISSION_POOL with variable EMISS_POOL
possibility to limit size of pools via constraint currently not included
note that I did not run the code, so it has not been tested for correct syntax
get initial draft code to work
add conditional formulation "is_emission_sink"
add "is_emission_sink", "is_bound_emission_pool", "PRICE_EMISSION_POOL" and "EMISS_POOL" to backend.
add bound formulation.
add post-processing for
PRICE_EMISS_POOL
add cost formulation.
document all new code in GAMS
Complete tutorial
Setup tests
Add test for shifting first model year and updating of the historical values
the parameter
historical_emission_pool
needs to be added as part of the parameters which get updated during the cloning process; add test.discuss how to treat
PRICE_EMISS_POOL
- currently this only includes shadow price frombound_emission_pool_up
, i.e. it represents the cost of mitigating similar toPRICE_EMISS
. Should we also include lower bound related costs separately?