-
Notifications
You must be signed in to change notification settings - Fork 50
Add bilateralization tool (project/newpathways-trade) #438
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
base: main
Are you sure you want to change the base?
Conversation
|
Thanks for the work here! In order to merge the following are needed, and addressing these things first will help reviewers focus more squarely on the added contents and functionality.
Many members of the team have experience doing each of these steps and can help by checking work, pair programming, or joining in to do the changes directly, so please reach out on Slack or otherwise. |
ebeeb3c to
6a19239
Compare
43eb325 to
a62b990
Compare
To remove oil_exp and oil_imp
Necessary for legacy reporting update
|
Hi Jun, here are some points from mine.
After code quality reaches the target test coverage and the UnicodeDecodeError on Windows is tackled properly, I would happily approve this merge. |
| ) | ||
| ) | ||
|
|
||
| with open(config_path, "r") as f: |
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.
Regarding the UnicodeDecodeError that is causing failures in tests on all Windows environments, I got rid of it simply by using with open(config_path, "r", encoding="utf-8") as f: here and the other 5 places. Maybe there are more proper ways to tackle this.
|
I was able to build bilateralization of all commodities covered by the current default config on a recent R12 scenario with the first model year as 2020. So the historical calibrations also work. Jun, please kindly let me know when you plan to expand the default list to electricity trade. I am interested in properly using your bilateralization tool, finishing the historical activity calibration of it, removing the current electricity trade technologies, and introducing the default assumption of future intercontinental UHV grids (...if I am able to squeeze some time in the upcoming spring). |
| ) | ||
|
|
||
| # Remove PAO coal and gas constraints on MESSAGEix-GLOBIOM | ||
| remove_pao_coal_constraint(scen=scen, log=log, MESSAGEix_GLOBIOM=MESSAGEix_GLOBIOM) |
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.
It seems even if a user specified a config bilateralizing only one non-energy commodity trade (e.g., sponge_iron) without bilateralizing other energy commodities, this coal_constraint will be removed anyways. Is it designed in this way?
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.
OS-specific files like this should not be committed. To hide them from Git, you could add them to the top-level .gitignore file, e.g. here is a file that I believe is macOS-specific:
Line 149 in 6bf4000
| .DS_Store |
| @@ -0,0 +1,35 @@ | |||
| # -*- coding: utf-8 -*- | |||
| """ | |||
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.
Overall it's great to see documentation in many places here. Please carefully read and apply the docstring style linked from our code style docs. Some points include:
- Short summary is a single line, ends with a period.
- Wrap at 88 characters.
- Use the numpydoc format for parameter lists.
- Use reST and check the formatting. For instance, in this particular docstring, the numbered list
1. …is not preceded by a blank line, so will not be parsed as a list.
doc/api/tools-bilateralize.rst
Outdated
|
|
||
| Overview | ||
| ======== | ||
| This documentation will outline how to bilateralize trade flows in MESSAGEix. By default, trade flows are based on a “global pool” approach, wherein all exporters export energy/commodities to a pool from which importers import based on regionally resolved demands. |
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.
Please see the documentation code style per "semantic line breaks".
As an intermediate step, start at least every sentence on a new line.
doc/api/tools-bilateralize.rst
Outdated
| ============= | ||
| The first step is to generate empty (or default valued) parameters that are required for bilateralization, specified by commodity. This step requires updates to a configuration file (``config.yaml``) that should be housed in a project directory (e.g., ``message-ix-models/projects/newpathways-trade/config.yaml``). A template configuration file is provided at ``message-ix-models/data/bilateralize/configs/base_config.yaml``. | ||
|
|
||
| Once the configuration is updated, the user can run ``message_ix_models.tools.bilateralize.prepare_edit.generate_edit_files(log, project_name, config_name, message_regions)`` to produce empty (or default valued) parameters as CSV files. These CSV files will populate in ``message-ix-models/data/[your_trade_commodity]/edit_files``. |
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.
|
|
||
|
|
||
| # %% Full broadcast function | ||
| def full_broadcast( |
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 suspect these 3 broadcast_*() functions (~150 lines) could be replaced with use of the existing utility function. Is there some specific behaviour needed here that the existing code does not provide?
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.
Indeed, I was able to cut down significantly using the broadcast function.
Commit b925b45
Overview
The merged code allows users to represent trade bilaterally for specified commodities. By default, the tool bilateralizes existing fuel trade (e.g., oil_exp).
The bilateralization tool,
bilateralize, is generalized for any traded commodity, whether that is a fuel (e.g., LNG), or a material (e.g., steel). It also explicitly represents bilateral trade “flows”, or how a fuel/commodity is transported from exporter to importer. These flow technologies are user defined and flexible; the most common are pipelines (e.g., gas pipelines), maritime shipping (e.g., LNG tanker), and transmission lines.See https://github.com/iiasa/message-ix-models/blob/project/newpathways-trade/doc/api/tools-bilateralize.rst for more details on implementation.
How to review
Note: All scripts are additions (no existing scripts are amended). Therefore, I would request reviewing code directly rather than individual commits (of which there are >200).
These review steps are also outlined in https://github.com/iiasa/message-ix-models/blob/project/newpathways-trade/message_ix_models/tools/bilateralize/workflow.py
prepare_edit_files()should produce untracked files in commodity-specific directories indata/bilateralize/edit_filesand also transfer required parameter files todata/bilateralize/bare_filesbare_to_scenario()should produce a dictionary of required parameter updates for bilateralization for all specified trade commodities inconfig.yaml.load_and_solve()should be able to be used to update SSP base scenariosPR checklist