Skip to content

Commit cede75c

Browse files
authored
Merge pull request #972 from iiasa/enh/model-module
Separate models.py into submodules
2 parents cc014c2 + df1bfa9 commit cede75c

25 files changed

+1568
-1441
lines changed

RELEASE_NOTES.rst

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,24 @@
11
Next release
22
============
33

4+
Migration notes
5+
---------------
6+
7+
Adjust any imports like the following:
8+
9+
.. code-block:: python
10+
11+
from message_ix.models import DIMS, Item, MACRO, MESSAGE, MESSAGE_MACRO
12+
13+
…to:
14+
15+
.. code-block:: python
16+
17+
from message_ix.common import DIMS, Item
18+
from message_ix.macro import MACRO
19+
from message_ix.message import MESSAGE
20+
from message_ix.message_macro import MESSAGE_MACRO
21+
422
All changes
523
-----------
624

@@ -20,6 +38,13 @@ All changes
2038
- Revise :ref:`equation_commodity_balance_aux` to include input and output flows based on |CAP| and |CAP_NEW|.
2139
- New :class:`.MESSAGE` / :meth:`.Scenario.solve` option :py:`cap_comm=True` to enable this representation.
2240

41+
- The former module :py:`message_ix.models` is split to distinct submodules (:pull:`972`):
42+
43+
- :mod:`message_ix.common` includes :class:`.GAMSModel` and related code.
44+
- :mod:`message_ix.macro` includes :class:`.MACRO`.
45+
- :mod:`message_ix.message` includes :class:`.MESSAGE`.
46+
- :mod:`message_ix.message_macro` includes :class:`.MESSAGE_MACRO`.
47+
2348
- Document the :ref:`minimum version of Java <install-java>` required for :class:`ixmp.JDBCBackend <ixmp.backend.jdbc.JDBCBackend>` (:pull:`962`).
2449
- Improve type hinting (:pull:`963`).
2550

@@ -61,7 +86,7 @@ Users **should**:
6186
All changes
6287
-----------
6388

64-
- Some MESSAGEix :doc:`tutorials <tutorials>` are runnable with the :class:`.IXMP4Backend` introduced in :mod:`ixmp` version 3.11 (:pull:`894`, :pull:`941`).
89+
- Some MESSAGEix :doc:`tutorials <tutorials>` are runnable with the :class:`~ixmp.backend.ixmp4.IXMP4Backend` introduced in :mod:`ixmp` version 3.11 (:pull:`894`, :pull:`941`).
6590
See `Support roadmap for ixmp4 <https://github.com/iiasa/message_ix/discussions/939>`__ for details.
6691
- Add the :py:`concurrent=...` model option to :class:`.MACRO` (:pull:`808`).
6792
- Adjust use of :ref:`type_tec <mapping-sets>` in :ref:`equation_emission_equivalence` (:pull:`930`, :issue:`929`, :pull:`935`).
@@ -174,7 +199,7 @@ Migration notes
174199
NOTE: this may result in changes to the solution.
175200
In order to use the previous default `lpmethod`, the user-specific default setting can be set through the user's ixmp configuration file.
176201
Alternatively, the `lpmethod` can be specified directly as an argument when solving a scenario.
177-
Both of these configuration methods are further explained :meth:`here <message_ix.models.GAMSModel>`.
202+
Both of these configuration methods are further documented at :class:`.GAMSModel`.
178203

179204
- The dimensionality of one set and two parameters (``map_tec_storage``, ``storage_initial``, and ``storage_self_discharge``) are extended to allow repesentation of the mode of operation of storage technologies and the temporal level of storage containers.
180205
If these items are already populated with data in a Scenario, this data will be incompatible with the MESSAGE GAMS implementation in this release; a :class:`UserWarning` will be emitted when the :class:`.Scenario` is instantiated, and :meth:`~.message_ix.Scenario.solve` will raise a :class:`ValueError`.
@@ -421,7 +446,7 @@ All changes
421446
- :pull:`281`: Test and improve logic of :meth:`.years_active` and :meth:`.vintage_and_active_years`.
422447
- :pull:`269`: Enforce ``year``-indexed columns as integers.
423448
- :pull:`256`: Update to use :obj:`ixmp.config` and improve CLI.
424-
- :pull:`255`: Add :mod:`message_ix.testing.nightly` and ``message-ix nightly`` CLI command group for slow-running tests.
449+
- :pull:`255`: Add :py:`message_ix.testing.nightly` and ``message-ix nightly`` CLI command group for slow-running tests.
425450
- :pull:`249`, :pull:`259`: Build MESSAGE and MESSAGE_MACRO classes on ixmp model API; adjust Scenario.
426451
- :pull:`235`: Add a reporting tutorial.
427452
- :pull:`236`, :pull:`242`, :pull:`263`: Enhance reporting.

doc/api.rst

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -129,17 +129,21 @@ The full API is also available from R; see :doc:`rmessageix`.
129129
Model classes
130130
-------------
131131

132-
.. currentmodule:: message_ix.models
132+
.. currentmodule:: message_ix
133133

134134
.. autosummary::
135135

136-
MESSAGE
137-
MACRO
138-
MESSAGE_MACRO
139-
GAMSModel
140-
DEFAULT_CPLEX_OPTIONS
141-
Item
142-
ItemType
136+
~message.MESSAGE
137+
~macro.MACRO
138+
~message_macro.MESSAGE_MACRO
139+
~common.GAMSModel
140+
~common.DEFAULT_CPLEX_OPTIONS
141+
~common.Item
142+
~ixmp.backend.ItemType
143+
144+
.. currentmodule:: message_ix.common
145+
146+
.. automodule:: message_ix.common
143147

144148
.. autodata:: DEFAULT_CPLEX_OPTIONS
145149

@@ -149,7 +153,8 @@ Model classes
149153
:members:
150154
:exclude-members: defaults
151155

152-
The :class:`.MESSAGE`, :class:`MACRO`, and :class:`MESSAGE_MACRO` child classes encapsulate the GAMS code for the core MESSAGE (or MACRO) mathematical formulation.
156+
The :class:`.MESSAGE`, :class:`.MACRO`, and :class:`.MESSAGE_MACRO` child classes
157+
encapsulate the GAMS code for the core MESSAGE (or MACRO) mathematical formulation.
153158

154159
The class receives `model_options` via :meth:`.Scenario.solve`. Some of these are passed on to the parent class :class:`ixmp.model.gams.GAMSModel` (see there for a list); others are handled as described below.
155160

@@ -244,6 +249,10 @@ Model classes
244249
* - **var_list**
245250
- :obj:`None`
246251

252+
.. currentmodule:: message_ix.message
253+
254+
.. automodule:: message_ix.message
255+
247256
.. autoclass:: MESSAGE
248257
:members: initialize
249258
:exclude-members: defaults
@@ -267,6 +276,10 @@ Model classes
267276
Keys are the names of items (sets, parameters, variables, and equations); values are :class:`.Item` instances.
268277
These include all items listed in the MESSAGE mathematical specification, i.e. :ref:`sets_maps_def` and :ref:`parameter_def`.
269278

279+
.. currentmodule:: message_ix.macro
280+
281+
.. automodule:: message_ix.macro
282+
270283
.. autoclass:: MACRO
271284
:members:
272285
:exclude-members: items
@@ -283,6 +296,10 @@ Model classes
283296
.. autoattribute:: items
284297
:no-value:
285298

299+
.. currentmodule:: message_ix.message_macro
300+
301+
.. automodule:: message_ix.message_macro
302+
286303
.. autoclass:: MESSAGE_MACRO
287304
:members:
288305
:exclude-members: items
@@ -307,12 +324,10 @@ Model classes
307324
.. autoattribute:: items
308325
:no-value:
309326

310-
.. autodata:: DIMS
311-
.. autoclass:: Item
327+
.. autodata:: message_ix.common.DIMS
328+
.. autoclass:: message_ix.common.Item
312329
:members:
313330

314-
.. currentmodule:: message_ix.macro
315-
316331
.. _utils:
317332

318333
Utility methods
@@ -321,14 +336,8 @@ Utility methods
321336
.. automodule:: message_ix.util
322337
:members: expand_dims, copy_model, make_df
323338

324-
.. automodule:: message_ix.util.sankey
325-
:members: map_for_sankey
326-
327339
Testing utilities
328340
-----------------
329341

330342
.. automodule:: message_ix.testing
331343
:members: make_austria, make_dantzig, make_westeros, tmp_model_dir
332-
333-
.. automodule:: message_ix.testing.nightly
334-
:members:

doc/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@
165165
# top-level module in objects.inv. Resolve these using :doc:`index` or similar for
166166
# each project.
167167
"dask$": ":std:doc:`dask:index`",
168+
"jpype$": ":std:doc:`jpype:index`",
168169
"plotnine$": ":class:`plotnine.ggplot`",
169170
}
170171

doc/install-adv.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ This implies five of the six available groups of extra requirements:
230230

231231
- ``docs`` includes packages required to build this documentation locally,
232232
including ``message_ix[report]`` and all *its* requirements,
233-
- ``ixmp4`` includes packages require to use :class:`ixmp.IXMP4Backend <.IXMP4Backend>`,
233+
- ``ixmp4`` includes packages require to use :class:`ixmp.IXMP4Backend <ixmp.backend.ixmp4.IXMP4Backend>`,
234234
- ``report`` includes packages required to use the built-in :doc:`reporting <reporting>` features of :mod:`message_ix`,
235235
- ``sankey`` includes packages required to use :meth:`.Reporter.add_sankey`,
236236
- ``tests`` includes packages required to run the test suite,

doc/macro.rst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,12 @@ The required dimensions or symbol of each item are given in the same notation us
7373

7474
- ``price_ref`` (:math:`n, s`): prices of MACRO sector output in the reference year.
7575
These can be constructed from the MESSAGE variable ``PRICE_COMMODITY``, using the ``config`` mapping.
76-
If not provided, :mod:`message_ix.macro` will identify the reference year and extrapolate reference values using an exponential function fitted to ``PRICE_COMMODITY`` values; see :func:`.macro.extrapolate`.
76+
If not provided, :mod:`message_ix.macro.calibrate` will identify the reference year
77+
and extrapolate reference values using an exponential function fitted to ``PRICE_COMMODITY`` values.
78+
See :func:`~.macro.calibrate.extrapolate`.
7779
- ``cost_ref`` (:math:`n`): total cost of the energy system in the reference year.
7880
These can be constructed from the MESSAGE variable ``COST_NODAL_NET``, including dividing by a factor of 1000.
79-
If not provided, :mod:`message_ix.macro` will extrapolate using :func:`.macro.extrapolate`.
81+
If not provided, :mod:`message_ix.macro.calibrate` will extrapolate using :func:`~.macro.calibrate.extrapolate`.
8082
- ``demand_ref`` (:math:`n, s`): demand for MACRO sector output in the reference year.
8183
- ``lotol`` (:math:`n`): tolerance factor for lower bounds on MACRO variables.
8284
- ``esub`` (:math:`\epsilon_n`): elasticity of substitution between capital-labor and energy.
@@ -228,9 +230,9 @@ Alternatively the arguments can be specified either in :file:`models.py`.
228230
Code documentation
229231
==================
230232

231-
.. currentmodule:: message_ix.macro
233+
.. currentmodule:: message_ix.macro.calibrate
232234

233-
.. automodule:: message_ix.macro
235+
.. automodule:: message_ix.macro.calibrate
234236
:members:
235237

236238
The functions :func:`add_model_data` and :func:`calibrate` are used by :meth:`.Scenario.add_macro`.

doc/reporting.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ These include:
179179

180180
Other added keys include:
181181

182-
- :mod:`message_ix` adds the standard short symbols for |MESSAGEix| dimensions (sets) based on :data:`.models.DIMS`.
182+
- :mod:`message_ix` adds the standard short symbols for |MESSAGEix| dimensions (sets) based on :data:`.common.DIMS`.
183183
Each of these is also available in a Reporter: for example :py:`rep.get("n")` returns a list with the elements of the |MESSAGEix| set named "node";
184184
:py:`rep.get("t")` returns the elements of the set "technology", and so on.
185185
These keys can be used as input to other computations.

message_ix/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
from ixmp.util import DeprecatedPathFinder
99

1010
from .core import Scenario
11-
from .models import MACRO, MESSAGE, MESSAGE_MACRO
11+
from .macro import MACRO
12+
from .message import MESSAGE
13+
from .message_macro import MESSAGE_MACRO
1214
from .report import Reporter
1315
from .util import make_df
1416

0 commit comments

Comments
 (0)