Skip to content

Commit d77ab2b

Browse files
committed
Document #451
- Improve RELEASE_NOTES text. - Fix and add internal references and reference targets. - Document cap_comm option to Scenario.solve(), MESSAGE(), etc.
1 parent 10df434 commit d77ab2b

File tree

6 files changed

+95
-27
lines changed

6 files changed

+95
-27
lines changed

RELEASE_NOTES.rst

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,21 @@ Next release
44
All changes
55
-----------
66

7-
- Extend the auxiliary variable :ref:`_commodity_balance` to include input and output flows based on CAP and CAP_NEW variables (:pull:`451`).
8-
9-
When loading a Scenario created with `message_ix` version 3.11.0 or earlier,
10-
these items will be initialized (and left empty),
11-
using at most one call to :meth:`~message_ix.Scenario.commit`.
12-
See :meth:`.MESSAGE.initialize`.
7+
- Add representation of commodity flows associated with construction and retirement of technology capacity (:pull:`451`).
8+
9+
- New parameters
10+
|input_cap|,
11+
|input_cap_new|,
12+
|input_cap_ret|,
13+
|output_cap|,
14+
|output_cap_new|, and
15+
|output_cap_ret|.
16+
When loading a Scenario created with :mod:`message_ix` version 3.11.0 or earlier,
17+
these items are automatically initialized (and left empty),
18+
using at most one call to :meth:`~message_ix.Scenario.commit`.
19+
See :meth:`.MESSAGE.initialize`.
20+
- Revise :ref:`equation_commodity_balance_aux` to include input and output flows based on |CAP| and |CAP_NEW|.
21+
- New :class:`.MESSAGE` / :meth:`.Scenario.solve` option :py:`cap_comm=True` to enable this representation.
1322

1423
- Document the :ref:`minimum version of Java <install-java>` required for :class:`ixmp.JDBCBackend <ixmp.backend.jdbc.JDBCBackend>` (:pull:`962`).
1524
- Improve type hinting (:pull:`963`).

doc/api.rst

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,18 @@ Model classes
249249
:exclude-members: defaults
250250
:show-inheritance:
251251

252+
MESSAGE accepts the following *model_options* to control its behaviour:
253+
254+
- **cap_comm** (:class:`bool` or equivalent :class:`int` or :class:`float`):
255+
If :any:`True`, include **comm** odity flows associated with **cap** acity changes of technologies
256+
in :ref:`equation_commodity_balance_aux`.
257+
If :any:`False` (the default), these flow are omitted,
258+
and values of the associated parameters have no effect.
259+
This corresponds to the GAMS compile-time variable ``MESSAGE_CAP_COMM``.
260+
261+
.. note:: For some models, this can significantly increase the linear program (LP) size
262+
and thus the solve time.
263+
252264
.. autoattribute:: items
253265
:no-value:
254266

@@ -263,10 +275,10 @@ Model classes
263275
The MACRO class solves only the MACRO model in “standalone” mode—that is, without MESSAGE.
264276
It is also invoked from :class:`.MESSAGE_MACRO` to process *model_options* to control the behaviour of MACRO:
265277

266-
- **concurrent** (:class:`int` or :class:`float`, either :py:`0` or :py:`1`).
278+
- **concurrent** (:class:`bool` or equivalent :class:`int` or :class:`float`).
267279
This corresponds to the GAMS compile-time variable ``MACRO_CONCURRENT``.
268-
If set to :py:`0` (the default), MACRO is solved in a loop, once for each node in the Scenario.
269-
If set to :py:`1`, MACRO is solved only once, for all nodes simultaneously.
280+
If :any:`False` (the default), MACRO is solved in a loop, once for each node in the Scenario.
281+
If :any:`True`, MACRO is solved only once, for all nodes simultaneously.
270282

271283
.. autoattribute:: items
272284
:no-value:
@@ -279,7 +291,8 @@ Model classes
279291
MESSAGE_MACRO solves the MESSAGE and MACRO models iteratively, connecting changes in technology activity and resource demands (from MESSAGE) to changes in final demands and prices (from MACRO).
280292
This iteration continues until the solution *converges*; i.e. the two models reach a stable point for the values of these parameters.
281293

282-
MESSAGE_MACRO accepts three additional *model_options* that control the behaviour of this iteration algorithm:
294+
MESSAGE_MACRO accepts all of the *model_options* recognized by :class:`.MESSAGE` and :class:`.MACRO`,
295+
plus additional options that control the behaviour of this iteration algorithm:
283296

284297
- **max_adjustment** (:class:`float`, default 0.2): the maximum absolute relative change in final demands between iterations.
285298
If MACRO returns demands that have changed by more than a factor outside the range (1 - `max_adjustment`, 1 + `max_adjustment`) since the previous iteration, then the change is confined to the limits of that range for the next run of MESSAGE.

doc/conf.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
6868
<abbr title="International Institute for Applied Systems Analysis">IIASA</abbr>
6969
70+
.. |y0| replace:: :math:`y_0`
7071
.. |yA| replace:: :math:`y^A`
7172
.. |yV| replace:: :math:`y^V`
7273
"""
@@ -77,13 +78,29 @@
7778
# sometimes multiple targets appear above a single heading, and that heading text would
7879
# be automatically used for the link text.
7980
for name in (
81+
"ACT",
82+
"CAP",
83+
"CAP_NEW",
84+
"LAND",
85+
"STOCK_CHG",
8086
"duration_period",
8187
"duration_period_sum",
8288
"growth_new_capacity_up",
8389
"historical_new_capacity",
8490
"initial_new_capacity_up",
91+
"input",
92+
"input_cap",
93+
"input_cap_new",
94+
"input_cap_ret",
95+
"output",
96+
"output_cap",
97+
"output_cap_new",
98+
"output_cap_ret",
99+
"land_input",
100+
"land_output",
85101
"map_tec_lifetime",
86102
"remaining_capacity",
103+
"technical_lifetime",
87104
):
88105
rst_prolog += f"\n.. |{name}| replace:: :ref:`{name} <{name}>`"
89106

@@ -222,8 +239,9 @@ def local_inv(name: str, *parts: str) -> Optional[str]:
222239
macros = {}
223240
macros.update(
224241
{
225-
k.replace("_", ""): r"\text{{{k}}}"
242+
k.replace("_", ""): rf"\text{{{k}}}"
226243
for k in """ACT
244+
COMMODITY_BALANCE
227245
STORAGE
228246
STORAGE_CHARGE
229247
duration_time_rel

message_ix/core.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,8 @@ def solve(self, model="MESSAGE", solve_options={}, **kwargs):
755755
See the :class:`.MESSAGE` class and :obj:`.DEFAULT_CPLEX_OPTIONS`.
756756
kwargs :
757757
Other options control the execution of the underlying GAMS code; see the
758-
:class:`.MESSAGE_MACRO` class and :class:`.GAMSModel`.
758+
*model_options* described for :class:`.MESSAGE`, :class:`.MACRO`,
759+
:class:`.MESSAGE_MACRO`, and :class:`.GAMSModel`.
759760
"""
760761
super().solve(model=model, solve_options=solve_options, **kwargs)
761762

message_ix/model/MESSAGE/model_core.gms

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@
2828
*
2929
* Decision variables
3030
* ^^^^^^^^^^^^^^^^^^
31+
*
32+
* .. _ACT:
33+
* .. _CAP:
34+
* .. _CAP_NEW:
35+
* .. _LAND:
36+
* .. _STOCK_CHG:
37+
*
3138
* =============================================================== ====================================================================================
3239
* Variable Explanatory text
3340
* =============================================================== ====================================================================================
@@ -554,19 +561,25 @@ RESOURCE_HORIZON(node,commodity,grade)$( SUM(year$map_resource(node,commodity,gr
554561
* Constraints on commodities and stocks
555562
* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
556563
*
557-
* .. _commodity_balance:
564+
* .. _equation_commodity_balance_aux:
565+
*
566+
* Equation COMMODITY_BALANCE_AUX
567+
* """"""""""""""""""""""""""""""
568+
*
569+
* This equation sets the value of variable :math:`\COMMODITYBALANCE`,
570+
* which is then constrained by :ref:`commodity_balance_gt` and :ref:`commodity_balance_lt`.
571+
*
572+
* For each :math:`(n, c, l, y, h)`, this variable includes:
558573
*
559-
* Auxiliary COMMODITY_BALANCE
560-
* """""""""""""""""""""""""""
561-
* For the commodity balance constraints below, we introduce an auxiliary variable called :math:`COMMODITY\_BALANCE`.
562-
* This is implemented as a GAMS ``$macro`` function.
563-
* This variable also includes the material flows upon construction and retirement of the technology capacities.
564-
* For the material flows, the formulation is valid for the model years that are different than the first model year.
565-
* The formulation for the first model year requires the use of the ``historical_new_capacity`` parameter
566-
* instead of the ``CAP`` variable,
567-
* and depends on conditions for ``remaining_capacity`` to determine
568-
* whether the end of a technology's technical lifetime falls within the duration of a model period
569-
* (|duration_period|) or not.
574+
* - Net |input| minus |output| of commodities based on technology activity (|ACT|).
575+
* - Net |land_input| minus |land_output| of commodities based on |LAND|.
576+
* - Inter-period transfers via |STOCK_CHG|.
577+
* - If the :class:`MESSAGE` option :py:`cap_comm=True` is given,
578+
* flows of commodities (e.g. ‘materials’)
579+
* associated with construction and retirement of technology capacity (|CAP|).
580+
* For |y0|, this representation requires |historical_new_capacity| parameter values,
581+
* and depends on conditions for |remaining_capacity|, |duration_period|, and |technical_lifetime|
582+
* to determine when a technology is retired and account for the relevant flows.
570583
*
571584
* .. math::
572585
* \sum_{\substack{n^L,t,m,h^A \\ y^V \leq y}} output_{n^L,t,y^V,y,m,n,c,l,h^A,h}
@@ -587,7 +600,7 @@ RESOURCE_HORIZON(node,commodity,grade)$( SUM(year$map_resource(node,commodity,gr
587600
* \cdot CAP_{n^L,t,y^V,y} & \\
588601
* + \ STOCK\_CHG_{n,c,l,y,h} + \ \sum_s \Big( land\_output_{n,s,y,c,l,h} - land\_input_{n,s,y,c,l,h} \Big) \cdot & LAND_{n,s,y} \\[4pt]
589602
* - \ demand\_fixed_{n,c,l,y,h}
590-
* = COMMODITY\_BALANCE_{n,c,l,y,h} \quad \forall \ l \notin (L^{RES}, & L^{REN}, L^{STOR} \subseteq L)
603+
* = \COMMODITYBALANCE_{n,c,l,y,h} \quad \forall \ l \notin (L^{RES}, & L^{REN}, L^{STOR} \subseteq L)
591604
*
592605
* The commodity balance constraint at the resource level is included in the `Equation RESOURCE_CONSTRAINT`_,
593606
* while at the renewable level, it is included in the `Equation RENEWABLES_EQUIVALENCE`_,
@@ -698,7 +711,7 @@ $ENDIF
698711
* This constraint ensures that supply is greater or equal than demand for every commodity-level combination.
699712
*
700713
* .. math::
701-
* \text{COMMODITY_BALANCE}_{n,c,l,y,h} \geq 0
714+
* \COMMODITYBALANCE_{n,c,l,y,h} \geq 0
702715
*
703716
***
704717
COMMODITY_BALANCE_GT(node,commodity,level,year,time)$(
@@ -722,7 +735,7 @@ COMMODITY_BALANCE_GT(node,commodity,level,year,time)$(
722735
* is (exactly) equal to demand.
723736
*
724737
* .. math::
725-
* \text{COMMODITY_BALANCE}_{n,c,l,y,h} \leq 0
738+
* \COMMODITYBALANCE_{n,c,l,y,h} \leq 0
726739
*
727740
***
728741
COMMODITY_BALANCE_LT(node,commodity,level,year,time)$(

message_ix/model/MESSAGE/parameter_def.gms

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,10 @@ Parameter
190190
* Input/output mapping, costs and engineering specifications
191191
* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
192192
*
193+
* .. _input:
194+
* .. _output:
195+
* .. _technical_lifetime:
196+
*
193197
* .. list-table::
194198
* :widths: 25 60
195199
* :header-rows: 1
@@ -233,6 +237,13 @@ Parameter
233237
* * - emission_factor
234238
* - ``node_loc`` | ``tec`` | ``year_vtg`` | ``year_act`` | ``mode`` | ``emission``
235239
*
240+
* .. _input_cap:
241+
* .. _input_cap_new:
242+
* .. _input_cap_ret:
243+
* .. _output_cap:
244+
* .. _output_cap_new:
245+
* .. _output_cap_ret:
246+
*
236247
* Input/output mapping related to technology capacities
237248
* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
238249
*
@@ -724,6 +735,9 @@ Parameters
724735
* (provided by another model) to derive supply of commodities (e.g., biomass) and emissions
725736
* from agriculture and forestry. The parameters listed below refer to the assigned land scenario.
726737
*
738+
* .. _land_input:
739+
* .. _land_output:
740+
*
727741
* .. list-table::
728742
* :widths: 25 75
729743
* :header-rows: 1

0 commit comments

Comments
 (0)