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 25 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
90fbead
Adjust calculation of PRICE_EMISSION
OFR-IIASA Jun 30, 2023
089868e
Add temporary price emission variable in model_core
behnam-zakeri Jun 30, 2023
b61f3cf
Refactor price emission to marginals of EMISSION_EQUIVALENCE
behnam-zakeri Jun 30, 2023
23100fd
Adjust existing test to comply with changes to PRICE_EMISSION
OFR-IIASA Jun 30, 2023
8741db1
Extend price_emission tests
OFR-IIASA Jul 3, 2023
9e9f5f0
Trial setup for price emission test
OFR-IIASA Jul 5, 2023
c67b571
Revise duality test setup
OFR-IIASA Jul 6, 2023
c72ca43
Refactor existing changes to fit latest code structure
glatterf42 Dec 1, 2023
a931b97
Refactor the calculation of PRICE_EMISSION and remove PRICE_EMISSION_NEW
behnam-zakeri Apr 11, 2024
2228c3b
Update the length of reporting graph
behnam-zakeri Apr 11, 2024
3350b37
Improve test_price_emission to be ready for review
behnam-zakeri Apr 11, 2024
fb6ab45
Remove hardcoded data from test and apply ruff
behnam-zakeri Apr 11, 2024
9101b12
Apply ruff format for parameterizing tests
behnam-zakeri Apr 11, 2024
fbdb3ee
Update the length of the reporting graph
behnam-zakeri Apr 11, 2024
a2320ed
Fix explanation of PRICE_EMISSION
glatterf42 May 15, 2024
19a21cf
Adapt tests trying to make test_price_duality work
glatterf42 May 16, 2024
8ea79d8
TEMPORARY Add notebook to troubleshoot test_price_duality
glatterf42 May 16, 2024
7d43132
Improve test for different bound types
behnam-zakeri May 20, 2024
433d8f8
Remove unused tag parameter
glatterf42 May 22, 2024
52d52bc
Create units missing on test platforms
glatterf42 Sep 17, 2024
968881a
Revert unjustified latex re-formatting
glatterf42 Sep 18, 2024
09df44e
Reintroduce rescaling of EMISSION_CONSTRAINT
glatterf42 Sep 20, 2024
ccaf001
Adjust TEMPORARY debugging-notebook to westeros-inspired setup
glatterf42 Sep 20, 2024
293a04c
Use westeros-inspired values for many_tec test setup
glatterf42 Sep 20, 2024
afc7c87
Make explanatory comment more concise
glatterf42 Sep 23, 2024
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
24 changes: 10 additions & 14 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{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.
* ======================================================================================= =======================================================================================================
* 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_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
* ======================================================================================= =======================================================================================================
***

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
Expand Up @@ -4,7 +4,7 @@
from dataclasses import InitVar, dataclass, field
from functools import partial
from pathlib import Path
from typing import Mapping, MutableMapping, Optional, Tuple
from typing import MutableMapping, Optional, Tuple
from warnings import warn

import ixmp.model.gams
Expand Down Expand Up @@ -175,7 +175,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 @@ -557,7 +557,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 @@ -768,7 +768,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