Skip to content

Adjust to ixmp Backend/Model refactor#249

Merged
khaeru merged 47 commits into
iiasa:masterfrom
khaeru:feature/ixmp-backend
Nov 1, 2019
Merged

Adjust to ixmp Backend/Model refactor#249
khaeru merged 47 commits into
iiasa:masterfrom
khaeru:feature/ixmp-backend

Conversation

@khaeru
Copy link
Copy Markdown
Member

@khaeru khaeru commented Oct 25, 2019

iiasa/ixmp#182 modularizes ixmp.core into abstract Backend and Model classes, and concrete JDBCBackend and GAMSModel classes. This PR adjusts message_ix accordingly.

How to review

Details

message_ix jumps stack layers in a few places by communicating directly with ixmp_source.

Click to show source… - MsgScenario.getTypeList in `cat_list`: https://github.com/iiasa/message_ix/blob/570f79833eddf046f7779db3f68fb86c0b13b0cc/message_ix/core.py#L94 - MsgScenario.addCatEle in `add_cat`: https://github.com/iiasa/message_ix/blob/570f79833eddf046f7779db3f68fb86c0b13b0cc/message_ix/core.py#L111 - MsgScenario.getCatEle in `cat`: https://github.com/iiasa/message_ix/blob/570f79833eddf046f7779db3f68fb86c0b13b0cc/message_ix/core.py#L123 - MsgScenario.getFirstModelYear in `firstmodelyear`: https://github.com/iiasa/message_ix/blob/570f79833eddf046f7779db3f68fb86c0b13b0cc/message_ix/core.py#L272 - MsgScenario.getTecActYrs. Note this was incorrectly in **ixmp**.Scenario; iiasa/ixmp#182 deletes it in ixmp.

The code here:

  • Modifies message_ix.Scenario:
    • Adds a method ._backend(name, ...) that calls backend API methods named ixmp.Backend.ms_{name}(...).
    • Moves .years_active() from ixmp.Scenario.
      • Instead of calling the ixmp_source method getTecActYrs (closed source; perpetuates a stack level violation in the Backend), I've just reimplemented this (open-source) in message_ix.
    • Deletes .remove_solution()—it only duplicated ixmp.Scenario.
    • Significantly simplifies .clone(). Now:
  • Deletes message_ix.model_settings and adds message_ix.models containing two subclasses of ixmp.GAMSModel named MESSAGE and MESSAGE_MACRO.
  • Also:
    • message_ix.default_model_paths is simplified using pathlib. This should eventually be delegated to ixmp.config.Config.
    • Handling of CPLEX optfiles is moved into the new MESSAGE model class.
    • ixmp documentation is not repeated in message_ix; instead, linked with intersphinx.
    • CI configuration is revised to mirror ixmp; this includes adding Codecov, thus closes Set up Codecov CI configuration and badge #238.

PR checklist

  • Tests added.
  • Documentation added.
  • Release notes updated.

@khaeru khaeru added this to the 2.0 milestone Oct 26, 2019
@codecov
Copy link
Copy Markdown

codecov Bot commented Oct 26, 2019

Codecov Report

❗ No coverage uploaded for pull request base (master@742fb89). Click here to learn what that means.
The diff coverage is 93.93%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master     #249   +/-   ##
=========================================
  Coverage          ?   66.72%           
=========================================
  Files             ?       15           
  Lines             ?     1139           
  Branches          ?        0           
=========================================
  Hits              ?      760           
  Misses            ?      379           
  Partials          ?        0
Impacted Files Coverage Δ
message_ix/cli.py 65.21% <0%> (ø)
message_ix/testing.py 100% <100%> (ø)
message_ix/__init__.py 100% <100%> (ø)
message_ix/default_path_constants.py 100% <100%> (ø)
message_ix/tools/add_year/__init__.py 62.43% <50%> (ø)
message_ix/core.py 89.17% <94.11%> (ø)
message_ix/models.py 97.05% <97.05%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 742fb89...d18f6f6. Read the comment docs.

Copy link
Copy Markdown
Member

@gidden gidden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @khaeru, this looks absolutely superb. I couldn't find any suggestions in the code specifically, but I did notice one doc page didn't render as expected (or I think so).

One question here - how will this play with the now languishing MACRO PR #223? Is it worth pulling that in as is (given that it is no worse and arguably better than present day) and then adjusting this PR as needed? I'm not sure I have the bandwith to do it the other way around, and am afraid that it simply die on the vine.

Comment thread doc/source/api.rst
The MESSAGE Python class encapsulates the GAMS code for the core MESSAGE mathematical formulation.
The *model_options* arguments are received from :meth:`.Scenario.solve`, and—except for *solve_options*—are passed on to the parent class :class:`~ixmp.model.gams.GAMSModel`; see there for a full list of options.

.. autoclass:: MESSAGE_MACRO
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good eye. The code is working as intended, but that's indeed not what we want the user to be seeing in the documentation. I'll try for a fix.

@khaeru
Copy link
Copy Markdown
Member Author

khaeru commented Nov 1, 2019

how will this play with the MACRO PR #223?

A rebase/merge from master might be needed after this goes in. I'll add some comments over there.

@khaeru
Copy link
Copy Markdown
Member Author

khaeru commented Nov 1, 2019

See the above comment on IAMconsortium/pyam#281; IAMconsortium/pyam#280 broke the build, so I will now try to add a workaround.

@khaeru
Copy link
Copy Markdown
Member Author

khaeru commented Nov 1, 2019

Okay, that worked. Thanks @gidden for the quick review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Set up Codecov CI configuration and badge

2 participants