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

Add .tools.check() #506

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft

Add .tools.check() #506

wants to merge 9 commits into from

Conversation

khaeru
Copy link
Member

@khaeru khaeru commented Aug 27, 2021

This PR adds a new function message_ix.tools.check().

This function does pre-solve checks on MESSAGE-scheme scenarios: it examines the contents of a Scenario object and returns failure or warning if the contents of the Scenario are not compatible with the MESSAGE GAMS implementation and will certainly or likely cause an error if Scenario.solve() is called.

Details:

  • This parallels some existing "sanity checks" already implemented in the GAMS code itself, e.g.
    *----------------------------------------------------------------------------------------------------------------------*
    * sanity checks on the data set *
    *----------------------------------------------------------------------------------------------------------------------*

    Since GAMS is not a general-purpose programming language, checks in Python with more sophisticated checks and informative error messages can be easier to write and maintain.
  • The check() method returns a list of Result objects. This is a simple class that includes a description of the check, the outcome (pass, fail, warning) and optional informative messages that can explain the offending contents of the scenario.
  • The first Result is an "overall" result, only passing if all the other checks pass.
  • The list of checks is extensible.
  • The implementation uses message_ix.reporting (ultimately genno) internally.

How to review

  • Read the diff and note that the CI checks all pass.
  • View the added documentation and ensure the checks are fully described.

PR checklist

@khaeru khaeru self-assigned this Aug 27, 2021
@khaeru khaeru added the enh New features & functionality label Aug 27, 2021
@codecov
Copy link

codecov bot commented Aug 27, 2021

Codecov Report

Merging #506 (c1be92a) into main (900a9f8) will increase coverage by 0.1%.
The diff coverage is 96.6%.

❗ Current head c1be92a differs from pull request most recent head 4dae5fb. Consider uploading reports for the commit 4dae5fb to get more accurate results

@@           Coverage Diff           @@
##            main    #506     +/-   ##
=======================================
+ Coverage   93.4%   93.5%   +0.1%     
=======================================
  Files         38      41      +3     
  Lines       2853    2967    +114     
=======================================
+ Hits        2666    2776    +110     
- Misses       187     191      +4     
Impacted Files Coverage Δ
message_ix/tests/tools/test_check.py 90.0% <90.0%> (ø)
message_ix/tools/_check.py 98.7% <98.7%> (ø)
message_ix/reporting/__init__.py 100.0% <100.0%> (ø)
message_ix/tests/test_tutorials.py 100.0% <100.0%> (ø)
message_ix/tools/__init__.py 100.0% <100.0%> (ø)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enh New features & functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant