-
Notifications
You must be signed in to change notification settings - Fork 166
Separate models.py into submodules #972
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
Conversation
|
I am a little split on whether we could/should use a flatter structure here, for example:
This would also avoid mixing Python and GAMS files in the existing subdirectory |
f68cd6f to
b248e05
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #972 +/- ##
=======================================
+ Coverage 96.1% 96.2% +0.1%
=======================================
Files 54 60 +6
Lines 5097 5132 +35
=======================================
+ Hits 4901 4940 +39
+ Misses 196 192 -4
|
|
I think ideally we'd like to have a structure that's intuitive to understand. When I see a file like The structure of the folders seems a little circular to me: we could split The latter seems a little more intuitive to me, but I'm not too sure. I think if we could set this up and want to invest the time, we could also make Sorry, I'm not sure there's much helpful in these thoughts. |
|
Okay, thanks for the inputs. I guess if we also consider issues like #879, it can help distinguish:
So, for instance, MESSAGE_MACRO as implemented in GAMS needs to include files from the GAMS implementations of each of MESSAGE and MACRO —this is one reason all these GAMS files are collected in the same directory. Currently that directory is named I think I will (a) go with the flatter structure mentioned in my previous comment and (b) leave the directory name |
- Adjust imports. - Adjust tests.
b248e05 to
d9a2b79
Compare
- Separate common code and code specific to MACRO, MESSAGE, and MESSAGE_MACRO. - Add .models.__getattr__() for deprecated imports with warnings.
d9a2b79 to
8615910
Compare
|
Sounds good, thanks :) |
- Align test layout with code layout. - Test .models.__getattr__().
- Align test layout with code layout. - Test .models.__getattr__().
a001b94 to
9b61eb4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, looks good to me aside from some documentation references that may have been invalidated here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm looking at the docs build and I'm surprised to see lots and lots of errors. Most of them already existed for the latest build, though, it seems. What's new is that doc/macro.rst complains about not being able to import various things from message_ix.macro. I'm guessing they moved somewhere (too many to list, but starting here in the build logs).
I also notice that there is an actual error about the table that contains PRICE_COMMODITY in model_core.rst, which is likely just imported from the GAMS file. This seems to be malformed, so is not rendered in our docs. While this error isn't new, it would be nice to fix it to have our docs be complete again. The error says "Bottom/header table border does not match top border.", which sounds like we just have a mismatch in the number of = used for the borders.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doc/install-adv.rst and doc/reporting.rst also complain about missing reference targets, as well as the RELEASE_NOTES.rst, curiously.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I'll fix up these examples you mention. It would be good to have someone do a more systematic sweep, at some point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the table that contains
PRICE_COMMODITYinmodel_core.rst,
This happened in #451: https://github.com/iiasa/message_ix/blame/cc014c24c7084f252f3827a86187a0ad467155a5/message_ix/model/MESSAGE/model_core.gms#L150
I've changed it to a ReST list-table, which makes it easier to edit.
doc/macro.rstcomplains about not being able to import various things frommessage_ix.macro
That file is now message_ix.macro.calibrate. Adjusted.
doc/install-adv.rst
home/khaeru/vc/iiasa/message-ix/doc/install-adv.rst:71: WARNING: py:mod reference target not found: jpype [ref.mod]
Like a lot of Sphinx packages, the intersphinx inventory for JPype1 does not actually contain a target for the top-level module:
$ python -m sphinx.ext.intersphinx https://jpype.readthedocs.io/en/stable/objects.inv | grep -B1 -A6 ^py:module
jpype.dbapi2.JDBCType.set : dbapi2.html#jpype.dbapi2.JDBCType.set
py:module
jpype.beans : api.html#module-jpype.beans
jpype.imports : api.html#module-jpype.imports
jpype.pickle : api.html#module-jpype.pickle
jpype.types : api.html#module-jpype.types
py:property
jpype.dbapi2.Connection.adapters : dbapi2.html#jpype.dbapi2.Connection.adapters
I added it to reference_aliases in doc/conf.py alongside the other such cases.
/home/khaeru/vc/iiasa/message-ix/doc/install-adv.rst:233: WARNING: py:class reference target not found: IXMP4Backend [ref.class]
This one looked like:
message_ix/doc/install-adv.rst
Line 233 in cc014c2
| - ``ixmp4`` includes packages require to use :class:`ixmp.IXMP4Backend <.IXMP4Backend>`, |
The shorthand whereby .IXMP4Backend will find a fully-qualified name (FQN) like ixmp.backend.ixmp4.IXMP4Backend only functions within the same project, not across projects via intersphinx. I replaced with the FQN.
doc/reporting.rst
Most of these cases occur with references that work/are valid within the genno docs, but are not properly resolved when those docs are rendered within the context of the message_ix docs. Some of those might be resolvable by copying some of the genno doc/conf.py settings. I'll omit those for now.
RELEASE_NOTES.rst
/home/khaeru/vc/iiasa/message-ix/RELEASE_NOTES.rst:43: WARNING: py:mod reference target not found: message_ix.common [ref.mod]
/home/khaeru/vc/iiasa/message-ix/RELEASE_NOTES.rst:44: WARNING: py:mod reference target not found: message_ix.macro [ref.mod]
/home/khaeru/vc/iiasa/message-ix/RELEASE_NOTES.rst:45: WARNING: py:mod reference target not found: message_ix.message [ref.mod]
/home/khaeru/vc/iiasa/message-ix/RELEASE_NOTES.rst:46: WARNING: py:mod reference target not found: message_ix.message_macro [ref.mod]
Added the appropriate targets.
/home/khaeru/vc/iiasa/message-ix/RELEASE_NOTES.rst:89: WARNING: py:class reference target not found: IXMP4Backend [ref.class]
/home/khaeru/vc/iiasa/message-ix/RELEASE_NOTES.rst:302: WARNING: py:mod reference target not found: macro [ref.mod]
Same as above.
/home/khaeru/vc/iiasa/message-ix/RELEASE_NOTES.rst:198: WARNING: py:meth reference target not found: message_ix.models.GAMSModel [ref.meth]
This was trying to use :meth: to reference a :class:. Fixed.
/home/khaeru/vc/iiasa/message-ix/RELEASE_NOTES.rst:449: WARNING: py:mod reference target not found: message_ix.testing.nightly [ref.mod]
This happens when things are removed. I resolve these by using the :py: role, which looks code-like but no longer tries to link to anything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this already looks a lot better. And agreed that a more systematic sweep would be useful, but out of scope here :)
- Address Sphinx build warnings per @glatterf42 review comments.
9b61eb4 to
df1bfa9
Compare
This PR splits and moves the
message_ix.modelssubmodule to 4 new submodules:message_ix.commonmessage_ix.macromessage_ix.messagemessage_ix.message_macroThis:
Achieves better separation-of-concerns.
Makes each submodule individually easier to understand and maintain. For instance,
.message_macrois under 30 lines;.macrois under 100.Creates a more natural way to integrate further changes and improvements to the behaviour of one or another model. For example:
.models.shift_period()#873However, making those particular changes is out of scope for this PR.
There are no functional changes, except that importing some names from their old locations will give an DeprecationWarning.
How to review
TBA
PR checklist