-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
371 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,8 +48,6 @@ Then, continue with the: | |
tutorials | ||
|
||
|
||
|
||
|
||
.. _core: | ||
|
||
Mathematical specification | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
Pre-solve checks | ||
**************** | ||
|
||
.. currentmodule:: message_ix.tools | ||
|
||
.. autofunction:: check | ||
|
||
.. currentmodule:: message_ix.tools._check | ||
|
||
.. _checks-summary: | ||
|
||
.. automodule:: message_ix.tools._check | ||
:members: gaps_input, gaps_tl, tl_integer | ||
|
||
.. autoclass:: Result | ||
|
||
Individual checks | ||
================= | ||
|
||
Gaps in certain parameters (:func:`gaps_*` check functions) can cause the GAMS implementation to treat that specific technology to be disabled in one period, between other periods where it *is* enabled. | ||
This may prevent solution of the model. | ||
|
||
.. autosummary:: | ||
|
||
gaps_input | ||
gaps_tl | ||
tl_integer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import pytest | ||
|
||
from message_ix import Scenario, make_df | ||
from message_ix.testing import make_dantzig, make_westeros | ||
from message_ix.tools import check | ||
|
||
|
||
def test_check_dantzig(test_mp): | ||
scen = make_dantzig(test_mp) | ||
|
||
# Checks all True | ||
results = check(scen) | ||
assert results[0] | ||
|
||
|
||
@pytest.fixture | ||
def westeros(test_mp): | ||
yield make_westeros(test_mp) | ||
|
||
|
||
# Minimal config to make Westeros reportable | ||
WESTEROS_CONFIG = {"units": {"replace": {"-": ""}}} | ||
|
||
|
||
def test_gaps_input(westeros): | ||
# Delete one value | ||
to_delete = make_df( | ||
"input", | ||
node_loc="Westeros", | ||
technology="bulb", | ||
year_vtg=690, | ||
year_act=710, | ||
mode="standard", | ||
node_origin="Westeros", | ||
commodity="electricity", | ||
level="final", | ||
time="year", | ||
time_origin="year", | ||
).dropna(axis=1) | ||
with westeros.transact(): | ||
westeros.remove_par("input", to_delete) | ||
|
||
# Checks fail | ||
results = check(westeros, config=WESTEROS_CONFIG) | ||
assert not results[0] | ||
|
||
|
||
def test_check_tl_integer(westeros): | ||
# Change one value | ||
tl = "technical_lifetime" | ||
with westeros.transact(): | ||
westeros.add_par( | ||
tl, | ||
make_df( | ||
tl, | ||
node_loc="Westeros", | ||
technology="bulb", | ||
year_vtg=700, | ||
value=1.1, | ||
unit="y", | ||
), | ||
) | ||
|
||
# Checks fail | ||
results = check(westeros, config=WESTEROS_CONFIG) | ||
assert not results[0] | ||
|
||
assert """FAIL Non-integer values for ``technical_lifetime``: | ||
See https://github.com/iiasa/message_ix/issues/503. | ||
- 1.1 at indices: nl=Westeros t=bulb yv=700""" in map( | ||
str, results | ||
) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"url, config", | ||
[ | ||
# ("ixmp://platform/model/scenario#version", dict()), | ||
], | ||
) | ||
def test_check_existing(url, config): | ||
"""Check existing scenarios. | ||
For local use only: extend the list of parameters, above, but do not commit | ||
additions to ``main``. | ||
""" | ||
# import pint | ||
# from iam_units import registry | ||
# | ||
# pint.set_application_registry(registry) | ||
|
||
scen, mp = Scenario.from_url(url) | ||
results = check(scen, config=config) | ||
|
||
# Checks all pass | ||
assert results[0], "\n".join(map(str, results)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from ._check import check | ||
|
||
__all__ = [ | ||
"check", | ||
] |
Oops, something went wrong.