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

Implementation of generic storage equations #190

Merged
merged 68 commits into from
Apr 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
fc70de2
Mapping of time and period added
behnam-zakeri Apr 5, 2019
0a1ad70
data load updated for storage mappings
behnam-zakeri Apr 5, 2019
c36c3a2
data load and parameter/sets def updated
behnam-zakeri Apr 5, 2019
d7cd0b0
model core updated
behnam-zakeri Apr 26, 2019
75d28b4
unit test and explanation added
behnam-zakeri Apr 27, 2019
342383e
A document added for illustration
behnam-zakeri Apr 27, 2019
8d6cfc8
time mapping updated and cleaned
behnam-zakeri Apr 27, 2019
e1a0ce6
data load updated
behnam-zakeri Apr 27, 2019
8635072
model core updated and cleaned
behnam-zakeri Apr 27, 2019
e6a96fb
sets and parameter definition text cleaned
behnam-zakeri Apr 27, 2019
92a0e98
release notes added
behnam-zakeri Apr 27, 2019
ecb11ba
text cleanup in GAMS
behnam-zakeri Apr 28, 2019
4d1f1ef
move storage init to core.py for use in all scenarios
gidden Apr 30, 2019
5ec9029
text cleanup in GAMS
behnam-zakeri Apr 28, 2019
4b3a7cf
cleanup of test_storage
behnam-zakeri May 2, 2019
a81e2c4
commodity index removed from storage bounds and losses
behnam-zakeri May 13, 2019
1e9e7cb
relation_storage added as an option (storage_equality removed)
behnam-zakeri May 13, 2019
5994b80
storage_balance mapped to map_tec_storage_level
behnam-zakeri May 13, 2019
2625cd2
inline documentation added to model_core
behnam-zakeri May 23, 2019
554bd57
cleanup of gams files before rebasing
behnam-zakeri Jun 24, 2019
6224ddb
Small modifications after rebasing
behnam-zakeri Jun 24, 2019
1b43a29
changes related to initialization of storage
behnam-zakeri Jun 24, 2019
59d7f8b
Notation cleaned up and documentation completed
behnam-zakeri Sep 23, 2019
10de7ff
tests improved to consider the initial value
behnam-zakeri Sep 23, 2019
31d2797
mapping of storage level improved for storage with no loss
behnam-zakeri Sep 23, 2019
308f1c9
updating asserts in test_reporting explicitly
behnam-zakeri Sep 23, 2019
3297693
cleanup of documentation and gams core
behnam-zakeri Sep 24, 2019
58c7c3f
updating test_legacy_version for changes in GAMS
behnam-zakeri Sep 24, 2019
dd1cb72
text of test and documentation improved
behnam-zakeri Oct 1, 2019
f965353
conisdering lvl_temporal directly in parameter time_seq
behnam-zakeri Nov 20, 2019
e05d809
making the connection between the last and first time steps (storage …
behnam-zakeri Nov 20, 2019
f47b366
second 'year' removed from index of time_period mapping
behnam-zakeri Nov 20, 2019
875305a
Move init_storage to models.MESSAGE.initialize
khaeru Nov 21, 2019
bcfceef
minor code cleanup
behnam-zakeri Nov 22, 2019
1f9fa98
Use ixmp.Model.initialize_items()
khaeru Feb 28, 2020
383ec9b
hard coded lengths in test_reporting and test_tutorials updated
behnam-zakeri Apr 20, 2020
f1dff0e
test_storage renamed and moved to tests folder
behnam-zakeri Apr 20, 2020
38248c0
Accept and check an optional scheme kwarg to message_ix.Scenario
khaeru Apr 21, 2020
9c02041
Cleanup after rebase
khaeru Apr 21, 2020
ef3ddbd
Restore line endings of period_parameter_assignment.gms
khaeru Apr 23, 2020
4e0acfd
simplifying the mapping of charge-discharge technologies to storage
behnam-zakeri Apr 24, 2020
1f826a4
removing map_time_period from include folder to data_load.gms
behnam-zakeri Apr 24, 2020
11adce5
correcting the mapping of initial storage content
behnam-zakeri Apr 24, 2020
bd5c56c
changing the sign of relation_storage and some text edits
behnam-zakeri Apr 24, 2020
bc5c62b
removing new bound definitions
behnam-zakeri Apr 24, 2020
ca1ab7e
considering commodity in equations
behnam-zakeri Apr 24, 2020
913ff73
correction lint error
behnam-zakeri Apr 24, 2020
d91c1e1
Update period_parameter_assignment.gms
behnam-zakeri Apr 24, 2020
c48d243
renaming and cleanup of storage equivalence equation
behnam-zakeri Apr 27, 2020
b3bca38
reporting tests updated for new lenghts
behnam-zakeri Apr 28, 2020
9d040c9
Update Scenario constructor per iiasa/ixmp#315
khaeru Apr 29, 2020
a91da49
Rename storage.PNG to storage.png, consistent with usage in docs
khaeru Apr 30, 2020
4d1026e
Correct ReST syntax for storage docs in model_core.gms
khaeru Apr 30, 2020
ead17e5
Update coding style guide for docs, GAMS code
khaeru Apr 30, 2020
2a1bc18
Update release notes with migration note; add storage items to docs
khaeru Apr 30, 2020
0673fb3
Add autosummary to model docs
khaeru Apr 30, 2020
be91164
removing storage relations to be modeled by existing parameters
behnam-zakeri Apr 30, 2020
d1e4148
update reporting length numbers
behnam-zakeri Apr 30, 2020
8c55b64
references to message_ix in RELEASE_NOTES.rst
francescolovat Apr 30, 2020
7edc9fe
documentation of storage params
francescolovat Apr 30, 2020
c02ee43
changed test assert values to pass CI
francescolovat Apr 30, 2020
50c1bcc
documentation of sets for storage
francescolovat Apr 30, 2020
8e194ae
edited nomenclature of storage equations
francescolovat Apr 30, 2020
03b5697
corrected typo in COMMODITY_BALANCE eqn
francescolovat Apr 30, 2020
96e5f3a
missing one underline symbol in params section title
francescolovat Apr 30, 2020
806db97
Update test_reporting.py
francescolovat Apr 30, 2020
e5bcf59
editing text for parameters of storage
behnam-zakeri Apr 30, 2020
34ac6bf
Address Sphinx warnings
khaeru Apr 30, 2020
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
17 changes: 13 additions & 4 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,22 @@ Other tips
Code style
----------

- Python: follow `PEP 8 <https://www.python.org/dev/peps/pep-0008/>`_.
- R: follow the style of the existing code base.
- Jupyter notebooks (``.ipynb``): see below, under `Contributing tutorials`_.
- Documentation (``.rst``, ``.md``):
- **Python:**

- Follow `PEP 8 <https://www.python.org/dev/peps/pep-0008/>`_.
- Docstrings are in the `numpydoc format <https://numpydoc.readthedocs.io/en/latest/format.html>`_.

- **R:** follow the style of the existing code base.
- Jupyter notebooks (:file:`.ipynb`): see below, under `Contributing tutorials`_.
- **Documentation** for ReStructuredText in :file:`.rst` files, and inline in :file:`.gms` files:

- Do not hard-wrap lines.
- Start each sentence on a new line.
- Ensure Sphinx does not give warnings about ReST syntax for new or modified documentation.

- GAMS:

- Wrap lines at 121 characters, except for inline documentation (see above).

- Other (file names, CLI, etc.): follow the style of the existing code base.

Expand Down
19 changes: 14 additions & 5 deletions RELEASE_NOTES.rst
Original file line number Diff line number Diff line change
@@ -1,31 +1,40 @@
Next release
============

Migration notes
---------------

The :ref:`generic storage formulation <gams-storage>` introduces **new ixmp items** (sets, parameters, variables, and equations) to the MESSAGE model scheme.
When loading a Scenario created with a version of `message_ix` older than x.x.x, these items will be initialized (and left empty), using at most one call to :meth:`~message_ix.Scenario.commit`.
See :meth:`.MESSAGE.initialize`.


All changes
-----------

- :pull:`190`: Add generic mathematical formulation of :ref:`technologies that store commodities <gams-storage>`, such as water and energy.
- :pull:`343`, :pull:`345`: Accept :class:`.MESSAGE_MACRO` iteration control parameters through :meth:`.solve`; document how to tune these to avoid numerical issues.
- :pull:`340`: Allow cplex.opt to be used by message_ix from multiple processes.
- :pull:`340`: Allow cplex.opt to be used by `message_ix` from multiple processes.
- :pull:`328`: Expand automatic reporting of emissions prices and mapping sets; improve robustness of :meth:`Reporter.convert_pyam`.
- :pull:`321`: Move :meth:`.Scenario.to_excel`, :meth:`.read_excel` to :class:`ixmp.Scenario`; they continue to work with message_ix.Scenario.
- :pull:`321`: Move :meth:`.Scenario.to_excel`, :meth:`.read_excel` to :class:`ixmp.Scenario`; they continue to work with :class:`message_ix.Scenario`.
- :pull:`323`: Add `units`, `replace_vars` arguments to :meth:`.Reporter.convert_pyam`.
- :pull:`308`: Expand automatic reporting of add-on technologies.
- :pull:`313`: Include all tests in the message_ix package.
- :pull:`313`: Include all tests in the `message_ix` package.
- :pull:`307`: Adjust to deprecations in ixmp 2.0.
- :pull:`223`: Add methods for parametrization and calibration of MACRO based on an existing MESSAGE Scenario.


v2.0.0 (2020-01-14)
===================

message_ix v2.0.0 coincides with ixmp v2.0.0.
`message_ix` v2.0.0 coincides with `ixmp` v2.0.0.

Migration notes
---------------

Support for **Python 2.7 is dropped** as it has reached end-of-life, meaning no further releases will be made even to fix bugs.
See `PEP-0373 <https://www.python.org/dev/peps/pep-0373/>`_ and https://python3statement.org.
``message_ix`` users must upgrade to Python 3.
`message_ix` users must upgrade to Python 3.

**Command-line interface (CLI).** Use ``message-ix`` as the program for all command-line operations:

Expand Down
Binary file added doc/source/_static/storage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 18 additions & 3 deletions doc/source/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,21 @@ Model classes

.. currentmodule:: message_ix.models

.. automodule:: message_ix.models
:exclude-members: MESSAGE, MESSAGE_MACRO
.. autosummary::

MESSAGE
MACRO
MESSAGE_MACRO
GAMSModel
DEFAULT_CPLEX_OPTIONS
MESSAGE_ITEMS

.. autodata:: DEFAULT_CPLEX_OPTIONS

These configure the GAMS CPLEX solver (or another solver, if selected); see `the solver documentation <https://www.gams.com/latest/docs/S_CPLEX.html>`_ for possible values.

.. autoclass:: MESSAGE
:members:
:members: initialize
:exclude-members: defaults
:show-inheritance:

Expand Down Expand Up @@ -125,6 +131,8 @@ Model classes
**var_list** :obj:`None`
================== ===

.. autoclass:: MACRO

.. autoclass:: MESSAGE_MACRO
:members:
:show-inheritance:
Expand All @@ -149,6 +157,13 @@ Model classes
:exclude-members: defaults
:show-inheritance:

.. autodata:: MESSAGE_ITEMS

Currently, these only include items required for :ref:`storage <gams-storage>`, in order to ensure that all scenarios are compatible with the MESSAGE GAMS implementation.

.. seealso:: :meth:`.MESSAGE.initialize`



.. _utils:

Expand Down
2 changes: 1 addition & 1 deletion doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ def setup(app):
# -- Options for sphinx.ext.intersphinx ---------------------------------------

intersphinx_mapping = {
'dask': ('http://docs.dask.org/en/stable/', None),
'dask': ('https://docs.dask.org/en/stable/', None),
'ixmp': ('https://message.iiasa.ac.at/projects/ixmp/en/latest/', None),
'pandas': ('https://pandas.pydata.org/pandas-docs/stable/', None),
'pint': ('https://pint.readthedocs.io/en/stable/', None),
Expand Down
32 changes: 21 additions & 11 deletions message_ix/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,31 @@ class Scenario(ixmp.Scenario):
"""|MESSAGEix| Scenario.
See :class:`ixmp.TimeSeries` for the meaning of arguments `mp`, `model`,
`scenario`, `version`, and `annotation`; :class:`ixmp.Scenario` for the
meaning of `cache`. The `scheme` of a newly-created Scenario is always
'MESSAGE'.
`scenario`, `version`, and `annotation`. The `scheme` of a newly-created
Scenario is always 'MESSAGE'.
"""
def __init__(self, mp, model, scenario=None, version=None, annotation=None,
cache=False):
scheme=None, **kwargs):
# If not a new scenario, use the scheme stored in the Backend
scheme = 'MESSAGE' if version == 'new' else None

# `ixmp.Scenario` verifies that MESSAGE-scheme scenarios are
# initialized as `message_ix.Scenario` for correct API
self.is_message_scheme = True
if version == 'new':
scheme = scheme or 'MESSAGE'

if scheme not in ('MESSAGE', None):
msg = f'Instantiate message_ix.Scenario with scheme {scheme}'
raise ValueError(msg)

super().__init__(
mp=mp,
model=model,
scenario=scenario,
version=version,
annotation=annotation,
scheme=scheme,
**kwargs
)

super().__init__(mp, model, scenario, version, scheme, annotation,
cache)
# Scheme returned by database
assert self.scheme == 'MESSAGE', self.scheme

# Utility methods used by .equ(), .par(), .set(), and .var()

Expand Down
14 changes: 14 additions & 0 deletions message_ix/model/MESSAGE/data_load.gms
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ $LOAD inv_tec, renewable_tec
$LOAD balance_equality
$LOAD shares
$LOAD addon, type_addon, cat_addon, map_tec_addon
$LOAD storage_tec, level_storage, map_tec_storage
$GDXIN

Execute_load '%in%'
Expand Down Expand Up @@ -69,6 +70,8 @@ demand_fixed=demand
* fixing variables to pre-specified values
is_fixed_extraction, is_fixed_stock, is_fixed_new_capacity, is_fixed_capacity, is_fixed_activity, is_fixed_land
fixed_extraction, fixed_stock, fixed_new_capacity, fixed_capacity, fixed_activity, fixed_land
* storage parameters
storage_initial, storage_self_discharge, time_order
;


Expand Down Expand Up @@ -158,6 +161,17 @@ addon_up(node,tec,year_all,mode,time,type_addon)$(
emission_scaling(type_emission,emission)$( cat_emission(type_emission,emission)
and not emission_scaling(type_emission,emission) ) = 1 ;

* mapping of storage technologies to their level and commodity (can be different from level and commodity of storage media)
map_time_commodity_storage(node,tec,level,commodity,mode,year_all,time)$( storage_tec(tec) AND
SUM( (node2,year_all2,time_act), input(node2,tec,year_all,year_all2,mode,node,commodity,level,time_act,time) ) ) = yes;

* mapping of sequence of sub-annual timesteps in a period and temporal level
map_time_period(year_all,lvl_temporal,time,time2)$( time_order(lvl_temporal,time) AND
time_order(lvl_temporal,time) + 1 = time_order(lvl_temporal,time2) ) = yes;

* mapping of sequence of the last sub-annual timestep to the first to create a close the order of timesteps
map_time_period(year_all,lvl_temporal,time,time2)$( time_order(lvl_temporal,time) AND
time_order(lvl_temporal,time) = SMAX(time3,time_order(lvl_temporal,time3) ) AND time_order(lvl_temporal,time2) = 1 ) = yes;
*----------------------------------------------------------------------------------------------------------------------*
* sanity checks on the data set *
*----------------------------------------------------------------------------------------------------------------------*
Expand Down
Loading