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

Adjust calculation of PRICE_EMISSION #726

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
909e15f
Adjust calculation of PRICE_EMISSION
OFR-IIASA Jun 30, 2023
0563a3e
Add temporary price emission variable in model_core
behnam-zakeri Jun 30, 2023
73c7e8e
Refactor price emission to marginals of EMISSION_EQUIVALENCE
behnam-zakeri Jun 30, 2023
1fb3e95
Adjust existing test to comply with changes to PRICE_EMISSION
OFR-IIASA Jun 30, 2023
3109a80
Extend price_emission tests
OFR-IIASA Jul 3, 2023
0192093
Trial setup for price emission test
OFR-IIASA Jul 5, 2023
17f24d3
Revise duality test setup
OFR-IIASA Jul 6, 2023
4618391
Refactor existing changes to fit latest code structure
glatterf42 Dec 1, 2023
f1b1d15
Refactor the calculation of PRICE_EMISSION and remove PRICE_EMISSION_NEW
behnam-zakeri Apr 11, 2024
24591f6
Update the length of reporting graph
behnam-zakeri Apr 11, 2024
9be1878
Improve test_price_emission to be ready for review
behnam-zakeri Apr 11, 2024
75c080c
Remove hardcoded data from test and apply ruff
behnam-zakeri Apr 11, 2024
9d59c1f
Apply ruff format for parameterizing tests
behnam-zakeri Apr 11, 2024
15b108c
Update the length of the reporting graph
behnam-zakeri Apr 11, 2024
a024445
Fix explanation of PRICE_EMISSION
glatterf42 May 15, 2024
f3982af
Adapt tests trying to make test_price_duality work
glatterf42 May 16, 2024
8dcb6c0
TEMPORARY Add notebook to troubleshoot test_price_duality
glatterf42 May 16, 2024
b2e4fb6
Improve test for different bound types
behnam-zakeri May 20, 2024
bc13dfd
Remove unused tag parameter
glatterf42 May 22, 2024
438ee75
Create units missing on test platforms
glatterf42 Sep 17, 2024
d8b90ae
Revert unjustified latex re-formatting
glatterf42 Sep 18, 2024
d851dfa
Reintroduce rescaling of EMISSION_CONSTRAINT
glatterf42 Sep 20, 2024
44b14ee
Adjust TEMPORARY debugging-notebook to westeros-inspired setup
glatterf42 Sep 20, 2024
3c59fd1
Use westeros-inspired values for many_tec test setup
glatterf42 Sep 20, 2024
b6c8106
Make explanatory comment more concise
glatterf42 Sep 23, 2024
61c133e
Revert unmotivated comment reformating
glatterf42 Jan 22, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion message_ix/model/MESSAGE/data_load.gms
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ addon_up(node,tec,year_all,mode,time,type_addon)$(
AND map_tec_act(node,tec,year_all,mode,time)
AND NOT addon_up(node,tec,year_all,mode,time,type_addon) ) = 1 ;

* set the emission scaling parameter to 1 if only one emission is included in a category
* set the emission scaling parameter to 1 by default
emission_scaling(type_emission,emission)$( cat_emission(type_emission,emission)
and not emission_scaling(type_emission,emission) ) = 1 ;

Expand Down
14 changes: 5 additions & 9 deletions message_ix/model/MESSAGE/model_core.gms
Original file line number Diff line number Diff line change
Expand Up @@ -131,26 +131,22 @@ Variables
*
* Auxiliary variables
* ^^^^^^^^^^^^^^^^^^^
* =========================================================================== ======================================================================================================
* =========================================================================== =======================================================================================================
* Variable Explanatory text
* =========================================================================== ======================================================================================================
* =========================================================================== =======================================================================================================
* :math:`\text{DEMAND}_{n,c,l,y,h} \in \mathbb{R}` Demand level (in equilibrium with MACRO integration)
* :math:`\text{PRICE_COMMODITY}_{n,c,l,y,h} \in \mathbb{R}` Commodity price (undiscounted marginals of :ref:`commodity_balance_gt` and :ref:`commodity_balance_lt`)
* :math:`\text{PRICE_EMISSION}_{n,\widehat{e},\widehat{t},y} \in \mathbb{R}` Emission price (undiscounted marginals of :ref:`emission_constraint`)
* :math:`\text{PRICE_EMISSION}_{n,\widehat{e},\widehat{t},y} \in \mathbb{R}` Emission price (undiscounted marginals of :ref:`emission_equivalence`)
* :math:`\text{COST_NODAL_NET}_{n,y} \in \mathbb{R}` System costs at the node level net of energy trade revenues/cost
* :math:`\text{GDP}_{n,y} \in \mathbb{R}` Gross domestic product (GDP) in market exchange rates for MACRO reporting
* =========================================================================== ======================================================================================================
*
* .. warning::
* Please be aware that transitioning from one period length to another for consecutive periods may result in false values of :math:`\text{PRICE_EMISSION}`.
* Please see `this issue <https://github.com/iiasa/message_ix/issues/723>`_ for further information. We are currently working on a fix.
* =========================================================================== =======================================================================================================
***

Variables
* auxiliary variables for demand, prices, costs and GDP (for reporting when MESSAGE is run with MACRO)
DEMAND(node,commodity,level,year_all,time) demand
PRICE_COMMODITY(node,commodity,level,year_all,time) commodity price (derived from marginals of COMMODITY_BALANCE constraint)
PRICE_EMISSION(node,type_emission,type_tec,year_all) emission price (derived from marginals of EMISSION_BOUND constraint)
PRICE_EMISSION(node,type_emission,type_tec,year_all) emission price (derived from marginals of EMISSION_EQUIVALENCE constraint)
COST_NODAL_NET(node,year_all) system costs at the node level over time including effects of energy trade
GDP(node,year_all) gross domestic product (GDP) in market exchange rates for MACRO reporting
;
Expand Down
19 changes: 12 additions & 7 deletions message_ix/model/MESSAGE/model_solve.gms
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,23 @@ EMISSION_CONSTRAINT.m(node,type_emission,type_tec,type_year)$(
/ SUM(year$( cat_year(type_year,year) ), duration_period(year) )
* SUM(year$( map_first_period(type_year,year) ), duration_period(year) / df_period(year) * df_year(year) );


* assign auxiliary variables DEMAND, PRICE_COMMODITY and PRICE_EMISSION for integration with MACRO and reporting
* assign auxiliary variable DEMAND for integration with MACRO
DEMAND.l(node,commodity,level,year,time) = demand_fixed(node,commodity,level,year,time) ;

* assign auxiliary variables PRICE_COMMODITY and PRICE_EMISSION for reporting
PRICE_COMMODITY.l(node,commodity,level,year,time) =
( COMMODITY_BALANCE_GT.m(node,commodity,level,year,time) + COMMODITY_BALANCE_LT.m(node,commodity,level,year,time) )
/ df_period(year) ;
PRICE_EMISSION.l(node,type_emission,type_tec,year)$( SUM(type_year$( cat_year(type_year,year) ), 1 ) ) =
SMAX(type_year$( cat_year(type_year,year) ),
- EMISSION_CONSTRAINT.m(node,type_emission,type_tec,type_year) )
/ df_year(year) ;

* calculate PRICE_EMISSION based on the marginals of EMISSION_EQUIVALENCE
PRICE_EMISSION.l(node,type_emission,type_tec,year)$( SUM(emission$( cat_emission(type_emission,emission) ),
EMISSION_EQUIVALENCE.m(node,emission,type_tec,year) ) ) =
SMAX(emission$( cat_emission(type_emission,emission) ),
EMISSION_EQUIVALENCE.m(node,emission,type_tec,year) / emission_scaling(type_emission,emission) )
/ df_period(year);
PRICE_EMISSION.l(node,type_emission,type_tec,year)$(
PRICE_EMISSION.l(node,type_emission,type_tec,year) = - inf ) = 0 ;
( PRICE_EMISSION.l(node,type_emission,type_tec,year) = eps ) or
( PRICE_EMISSION.l(node,type_emission,type_tec,year) = -inf ) ) = 0 ;

%AUX_BOUNDS% AUX_ACT_BOUND_LO(node,tec,year_all,year_all2,mode,time)$( ACT.l(node,tec,year_all,year_all2,mode,time) < 0 AND
%AUX_BOUNDS% ACT.l(node,tec,year_all,year_all2,mode,time) = -%AUX_BOUND_VALUE% ) = yes ;
Expand Down
8 changes: 4 additions & 4 deletions message_ix/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
from collections import ChainMap
from collections.abc import Mapping, MutableMapping
from collections.abc import MutableMapping
from copy import copy
from dataclasses import InitVar, dataclass, field
from functools import partial
Expand Down Expand Up @@ -176,7 +176,7 @@ class GAMSModel(ixmp.model.gams.GAMSModel):

#: Mapping from model item (equation, parameter, set, or variable) names to
#: :class:`.Item` describing the item.
items: Mapping[str, Item]
items: MutableMapping[str, Item]

def __init__(self, name=None, **model_options):
# Update the default options with any user-provided options
Expand Down Expand Up @@ -558,7 +558,7 @@ def initialize(cls, scenario):
var(
"PRICE_EMISSION",
"n type_emission type_tec y",
"Emission price (derived from marginals of EMISSION_BOUND constraint)",
"Emission price (derived from marginals of EMISSION_EQUIVALENCE constraint)",
)
var(
"REL",
Expand Down Expand Up @@ -769,7 +769,7 @@ def initialize(cls, scenario):
)
equ(
"EMISSION_EQUIVALENCE",
"",
"n e type_tec y",
"Auxiliary equation to simplify the notation of emissions",
)
equ("EXTRACTION_BOUND_UP", "", "Upper bound on extraction (by grade)")
Expand Down
Loading
Loading