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

Connect MACRO explicitly to MESSAGEix Scenarios #223

Merged
merged 70 commits into from
Mar 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
3da48c7
update macro init for vars and equs
gidden Jun 26, 2019
6d1ce17
move from lists to dicts in init
gidden Jul 23, 2019
a24f783
starting data checks
gidden Jul 23, 2019
6bbe93f
add initial test for macro data read
gidden Jul 24, 2019
479eadd
add tests for all input data
gidden Jul 24, 2019
bf3b4c0
Reimplement cost_nodal_net, closes #221
gidden Jul 24, 2019
f17849a
use fixtures instead of solving multiple scens
gidden Jul 25, 2019
445cb0a
quiet warnings
gidden Jul 25, 2019
12dd446
more test cleanup
gidden Jul 25, 2019
1e98c98
make gdp_calibrate have historical value
gidden Jul 25, 2019
7a965be
add base year check and k0 calc
gidden Jul 25, 2019
ac137ac
add price data and check
gidden Jul 25, 2019
009e659
add demand test
gidden Jul 25, 2019
1b12e97
gdp0 added
gidden Jul 25, 2019
dac763c
added bconst
gidden Jul 25, 2019
61e450d
update values to make them more inline with previous macro calculations
gidden Jul 25, 2019
0739a0e
added aconst
gidden Jul 25, 2019
b417811
add growth
gidden Jul 25, 2019
b36e1b0
added todos
gidden Jul 25, 2019
245b3fc
initial steps to get parameters in
gidden Jul 25, 2019
4e9b83a
change dict structure to add units
gidden Jul 25, 2019
ef8d9e3
add data_key to dict
gidden Jul 25, 2019
3759263
keep year in gdp0 index
gidden Jul 25, 2019
9f9a2db
add test for adding macro data
gidden Jul 25, 2019
34e107c
rename that func
gidden Jul 25, 2019
a80306d
starting calibration tests
gidden Jul 25, 2019
b8f1a02
I think this should work but it doesn't
gidden Jul 26, 2019
cd191fe
iteration now seems to work
gidden Jul 26, 2019
5297f80
keep track of iterations
gidden Jul 26, 2019
d5cf804
update fixture scope
gidden Jul 26, 2019
9f2a285
add comment on scope
gidden Jul 26, 2019
d75baf1
calibration now tested appropriately
gidden Jul 26, 2019
8052e9d
a bit more testing
gidden Jul 26, 2019
5c0ac08
now check for number of iterations
gidden Jul 26, 2019
1cf77c8
finishing up initial pr
gidden Jul 26, 2019
9e25787
add to release notes
gidden Jul 26, 2019
2308f1e
stickler
gidden Jul 26, 2019
65aa58b
stickler
gidden Jul 26, 2019
08fac5f
final cleanup
gidden Jul 26, 2019
1b7e54a
check for 0-prices
gidden Aug 1, 2019
3fffd84
clean up and add 690 to grow and aeei params
gidden Aug 8, 2019
4996593
change dataload to include inityear in macro
gidden Aug 8, 2019
d5930a5
rm prints
gidden Aug 8, 2019
eeb7626
fix data checking for gdp_calibrate
gidden Aug 9, 2019
6618121
further clean up and fixing growth test
gidden Aug 9, 2019
a1a61be
updated roundtrip test
gidden Aug 9, 2019
b7d12e2
stickler
gidden Aug 9, 2019
026ca3a
remove extraneous try
gidden Aug 9, 2019
3cf70ce
use sets instead in calc
gidden Aug 9, 2019
6117aac
add feature to remove nodes and sectors
gidden Aug 9, 2019
76196cc
Add support for multi region/multi sector data reading
gidden Aug 12, 2019
c6f9a2d
added bconst test
gidden Aug 12, 2019
1bb9c5a
add explicit test for ignoring nodes and sectors in multi-region tests
gidden Aug 12, 2019
cc279d8
fix and test issues seen by behnam
gidden Aug 13, 2019
722e547
stickler
gidden Aug 13, 2019
d52bc9f
add set ignore
gidden Aug 13, 2019
fccded1
final change required to match global model: divide model costs by 1e…
gidden Aug 14, 2019
ee74c04
making tested scenarios defaults
gidden Aug 21, 2019
f5a495f
now only run message-macro if check_convergence is True
gidden Aug 21, 2019
521aefd
stickler
gidden Aug 21, 2019
664208a
changed depreciation rate in MACRO MESSAGE interest rate in utility d…
volker-krey Aug 22, 2019
79446a7
allow passing through of kwargs to message solve
gidden Aug 22, 2019
c0754d2
Add 'MACRO' model class
khaeru Nov 7, 2019
3b3a633
Override GAMSModel.initialize in MACRO class
khaeru Mar 3, 2020
0c14487
reverted change from drate to interestrate in MACRO
volker-krey Mar 2, 2020
62d8834
Clean up rebase: relocate MACRO test data
khaeru Mar 13, 2020
d29814c
Handle any path-like argument to macro.Calculate()
khaeru Mar 13, 2020
e6f60ed
Use testing.SCENARIO in test_macro
khaeru Mar 13, 2020
4cbae0c
Remove unused 'import os' from macro
khaeru Mar 13, 2020
3a63764
Add warning message to Scenario.add_macro
khaeru Mar 15, 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
1 change: 1 addition & 0 deletions RELEASE_NOTES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ All changes

- `#313 <https://github.com/iiasa/ixmp/pull/313>`_: Include all tests in the message_ix package.
- `#307 <https://github.com/iiasa/message_ix/pull/307>`_: adjust to deprecations in ixmp 2.0.
- `#223 <https://github.com/iiasa/message_ix/pull/223>`_: Add methods for parametrization and calibration of MACRO based on an existing MESSAGE Scenario.


v2.0.0 (2020-01-14)
Expand Down
4 changes: 3 additions & 1 deletion message_ix/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
from ixmp.model import MODELS

from .core import Scenario # noqa: F401
from .models import MESSAGE, MESSAGE_MACRO
from .models import MACRO, MESSAGE, MESSAGE_MACRO


__all__ = [
'MACRO',
'MESSAGE',
'MESSAGE_MACRO',
'MODELS',
Expand All @@ -21,6 +22,7 @@


# Register models with ixmp core
MODELS['MACRO'] = MACRO
MODELS['MESSAGE'] = MESSAGE
MODELS['MESSAGE-MACRO'] = MESSAGE_MACRO

Expand Down
29 changes: 29 additions & 0 deletions message_ix/core.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
import collections
from functools import lru_cache
from itertools import product
import logging

import ixmp
from ixmp.utils import as_str_list, pd_read, pd_write, isscalar, logger
import pandas as pd


log = logging.getLogger(__name__)

# Also print warnings to stderr
_sh = logging.StreamHandler()
_sh.setLevel(level=logging.WARNING)
log.addHandler(_sh)


class Scenario(ixmp.Scenario):
"""|MESSAGEix| Scenario.

Expand Down Expand Up @@ -427,6 +436,26 @@ def solve(self, model='MESSAGE', solve_options={}, **kwargs):
"""
super().solve(model=model, solve_options=solve_options, **kwargs)

def add_macro(self, data, scenario=None, check_convergence=True, **kwargs):
# TODO document
from .macro import EXPERIMENTAL, add_model_data, calibrate
from .models import MACRO

# Display a warning
log.warning(EXPERIMENTAL)

scenario = scenario or '_'.join([self.scenario, 'macro'])
khaeru marked this conversation as resolved.
Show resolved Hide resolved
clone = self.clone(self.model, scenario, keep_solution=False)
clone.check_out()

# Add ixmp items: sets, parameters, variables, and equations
MACRO.initialize(clone)

add_model_data(self, clone, data)
clone.commit('finished adding macro')
calibrate(clone, check_convergence=check_convergence, **kwargs)
return clone

def rename(self, name, mapping, keep=False):
"""Rename an element in a set

Expand Down
Loading