Skip to content

Commit 5270640

Browse files
authored
Merge pull request #212 from iiasa/transport/2024-W31
Transport improvements for 2024-W31
2 parents 2fcae67 + de2446f commit 5270640

File tree

8 files changed

+44
-198
lines changed

8 files changed

+44
-198
lines changed

.github/workflows/transport.yaml

+24-184
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
name: MESSAGEix-Transport
22

33
env:
4+
target: transport.yaml --repo=iiasa/message_data
5+
46
# Starting point of the workflow.
57
# Use this value to build from a certain scenario:
68
# base: --url="ixmp://ixmp-dev/MESSAGEix-GLOBIOM 1.1-R12/baseline_DEFAULT#21"
@@ -12,11 +14,11 @@ env:
1214
from-step: ""
1315

1416
on:
15-
# Uncomment these lines for debugging, but leave them commented on 'main'/'dev'
17+
# Uncomment these lines for debugging, but leave them commented on 'main'
1618
# pull_request:
17-
# branches: [ main, dev ]
19+
# branches: [ main ]
1820
# push:
19-
# branches: [ main, dev ]
21+
# branches: [ main ]
2022
schedule:
2123
- cron: "0 1 * * *" # 01:00 UTC = 02:00 CET = 03:00 CEST
2224
workflow_dispatch: {}
@@ -27,186 +29,24 @@ concurrency:
2729
cancel-in-progress: true
2830

2931
jobs:
30-
report:
31-
name: MESSAGEix-Transport ${{ matrix.SSP }}${{ matrix.policy }}
32-
# Distribute jobs across any available self-hosted runner(s)
33-
# runs-on: self-hosted
34-
# Use one or a few specific runner(s)
35-
runs-on: [ self-hosted, iiasa-self-hosted-l2 ]
36-
37-
strategy:
38-
matrix:
39-
# These correspond to short labels used for workflow step names
40-
SSP:
41-
- SSP1
42-
- SSP2
43-
- SSP3
44-
- SSP4
45-
- SSP5
46-
policy:
47-
- " policy"
48-
- ""
49-
50-
steps:
51-
- name: Clean workspace
52-
run: |
53-
rm -rf ${{ github.workspace }}/report/*
54-
55-
- uses: webfactory/[email protected]
56-
with:
57-
ssh-private-key: |
58-
${{ secrets.MESSAGE_BUILDINGS_PRIVATE_KEY }}
59-
${{ secrets.MESSAGE_TRADE_PRIVATE_KEY }}
60-
${{ secrets.NAVIGATE_WORKFLOW_PRIVATE_KEY }}
61-
62-
- uses: actions/checkout@v4
63-
with:
64-
path: message_data
65-
lfs: true
66-
# On GitHub Actions
67-
# submodules: true
68-
# On self-hosted runners
69-
submodules: false
70-
71-
# NB Needed for self-hosted runner, not for GitHub
72-
- name: Check out Git LFS files
73-
working-directory: message_data
74-
run: git lfs checkout
75-
76-
# Other repositories required for testing
77-
- name: Check out message-static-data
78-
uses: actions/checkout@v4
79-
with:
80-
repository: iiasa/message-static-data
81-
token: ${{ secrets.MESSAGE_STATIC_DATA_PAT }}
82-
path: message-static-data
83-
lfs: true
84-
# Only check out the following files to limit bandwidth usage.
85-
# Respectively
86-
# 1. IEA Extended World Energy Balances, OECD source, 2022 edition
87-
sparse-checkout: |
88-
iea/372f7e29-en.zip
89-
sparse-checkout-cone-mode: false
90-
91-
- name: Connect static data to message_data
92-
run: cp -rsv $(realpath message-static-data)/* message_data/data/
93-
94-
- uses: actions/checkout@v4
95-
with:
96-
repository: iiasa/MESSAGE_Buildings
97-
path: buildings
98-
ssh-key: ${{ secrets.MESSAGE_BUILDINGS_PRIVATE_KEY }}
99-
100-
# NB Needed for self-hosted runner, not for GitHub
101-
- uses: actions/setup-java@v4
102-
with:
103-
distribution: temurin
104-
java-version: "17"
105-
106-
- uses: actions/setup-python@v5
107-
with:
108-
# Latest version testable on GitHub Actions
109-
python-version: "3.12"
110-
cache: pip
111-
cache-dependency-path: "**/pyproject.toml"
112-
113-
- uses: iiasa/actions/setup-gams@main
114-
with:
115-
version: 35.2.0
116-
license: ${{ secrets.GAMS_LICENSE }}
117-
118-
# NB the IIASA-hosted runner does not have permissions to do "sudo apt-get",
119-
# so the following doesn't work. Rather, the necessary packages
120-
# (graphviz libgraphviz-dev pkg-config) are manually installed on the
121-
# host system
122-
# - uses: ts-graphviz/setup-graphviz@v2
123-
124-
# By default, the next step installs dependencies from PyPI.
125-
# To run against unreleased code (on `main`, or other branches for open
126-
# PRs), uncomment or modify the lines below as appropriate.
127-
# - genno and message-ix-models are released frequently and *should* be
128-
# installed from PyPI, with only temporary exceptions.
129-
# - ixmp and message-ix are released less frequently and *may* be installed
130-
# from `main`
131-
- name: Force upgrade to unreleased dependencies
132-
run: |
133-
# pip install --upgrade "genno @ git+https://github.com/khaeru/genno.git@main"
134-
pip install --upgrade "ixmp @ git+https://github.com/iiasa/ixmp.git@main"
135-
pip install --upgrade "message_ix @ git+https://github.com/iiasa/message_ix.git@main"
136-
# Temporary, pending a release that includes iiasa/message-ix-models#161, #166
137-
pip install --upgrade "message-ix-models[iea-web] @ git+https://github.com/iiasa/message-ix-models.git@main"
138-
139-
# Upgrade matplotlib
140-
# pyam pins matplotlib < 3.7.1, which conflicts with plotnine per
141-
# https://github.com/has2k1/plotnine/pull/751. Override.
142-
pip install --upgrade matplotlib
143-
144-
- name: Install package; upgrade dependencies
145-
working-directory: message_data
146-
run: pip install --upgrade --upgrade-strategy=eager --editable .[dl,scgen,tests,transport]
147-
148-
- name: Configure
149-
run: |
150-
from pathlib import Path
151-
152-
# Ensure keys are defined
153-
import message_data.model.buildings
154-
from ixmp import config
155-
156-
config.add_platform(
157-
"ixmp-dev",
158-
"jdbc",
159-
"oracle",
160-
"x8oda.iiasa.ac.at:1521/PIXMP2.iiasa.ac.at",
161-
"${{ secrets.IXMP_DEV_USER }}",
162-
"${{ secrets.IXMP_DEV_PASS }}",
163-
jvmargs="-Xmx16G",
164-
)
165-
166-
p = Path("${{ github.workspace }}")
167-
config.set("message local data", p / "report")
168-
config.set("message solve options", {"iis": 1, "tilim": 60 * 30})
169-
config.set("message buildings dir", p / "buildings")
170-
config.save()
171-
172-
# Equivalent to "(ixmp|message-ix|mix-models) config show"
173-
print(config.path.read_text())
174-
shell: python
175-
176-
- name: Fetch data
177-
run: |
178-
mix-models fetch "SSP-Update-3.0"
179-
mix-models fetch "SSP-Update-3.0.1"
180-
181-
- name: Run MESSAGEix-Transport workflow "${{ env.from-step }}" → "${{ matrix.SSP }}${{ matrix.policy }} reported"
182-
run: |
183-
mix-models \
184-
${{ env.base }} \
185-
transport run \
186-
--base=auto --nodes=R12 --model-extra="ci nightly" \
187-
--from="${{ env.from-step }}" \
188-
"${{ matrix.SSP }}${{ matrix.policy }} reported" \
189-
--go
190-
continue-on-error: true
191-
192-
- name: Upload results as a build artifact
193-
uses: actions/upload-artifact@v4
194-
with:
195-
name: MESSAGEix-Transport ${{ matrix.SSP }}${{ matrix.policy }}
196-
path: |
197-
${{ github.workspace }}/report/
198-
!${{ github.workspace }}/report/cache/
199-
if-no-files-found: error
200-
continue-on-error: true
201-
202-
collate:
203-
name: Collate outputs
204-
needs: report
205-
runs-on: self-hosted
32+
dispatch:
33+
runs-on: ubuntu-latest
20634

20735
steps:
208-
- name: Merge artifacts
209-
uses: actions/upload-artifact/merge@v4
210-
with:
211-
name: MESSAGEix-Transport
212-
delete-merged: true
36+
- name: Invoke "transport.yaml" workflow in message_data
37+
env:
38+
GH_TOKEN: ${{ secrets.MESSAGE_DATA_DISPATCH_TOKEN }}
39+
run: |
40+
gh workflow run \
41+
${{ env.target }} --ref fix/transport-workflow \
42+
--field ref=${{ github.ref }} \
43+
--field sha=${{ github.sha }} \
44+
--field base=${{ env.base }} \
45+
--field from-step=${{ env.from-step }}
46+
47+
sleep 5
48+
49+
gh run list \
50+
--workflow=${{ env.target }} \
51+
--json url,status \
52+
--jq 'map(select(.status != "completed"))[0].url' >> $GITHUB_STEP_SUMMARY

.pre-commit-config.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ repos:
1010
language: python
1111
entry: bash -c ". ${PRE_COMMIT_MYPY_VENV:-/dev/null}/bin/activate 2>/dev/null; mypy $0 $@; python -m pip list"
1212
additional_dependencies:
13-
- mypy >= 1.9.0
13+
- mypy >= 1.11.0
1414
- plotnine
1515
- pytest
1616
- sdmx1
@@ -20,7 +20,7 @@ repos:
2020
- "message-ix @ git+https://github.com/iiasa/message_ix.git@main"
2121
args: ["."]
2222
- repo: https://github.com/astral-sh/ruff-pre-commit
23-
rev: v0.3.2
23+
rev: v0.5.5
2424
hooks:
2525
- id: ruff
2626
- id: ruff-format

MANIFEST.in

+5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1+
# Repository files for development, not distribution
2+
exclude .*
3+
prune .github
4+
15
# Data for testing
26
prune message_ix_models/data/test/advance
37
prune message_ix_models/data/test/gea
48
prune message_ix_models/data/test/iea
59
prune message_ix_models/data/test/shape
610
prune message_ix_models/data/test/snapshot-*
711
prune message_ix_models/data/test/ssp
12+
813
# Larger package data
914
# - Not distributed on PyPI.
1015
# - Should be fetched with Pooch from GitHub.

doc/transport/input.rst

+3-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ This page describes the structure and format of inputs required for building MES
77
:local:
88
:backlinks: none
99

10-
Both input data and configuration are stored in files under :file:`/data/transport/` in the :mod:`message_data` repository.
11-
(When migrated to :mod:`message_ix_models`, these files will live in :file:`message_ix_models/data/transport`.)
10+
Both input data and configuration are stored in files under :file:`message_ix_models/data/transport/`.
1211

1312
In most cases, these files are read from a subdirectory like :file:`/data/transport/{nodes}/`, where `nodes` denotes the :mod:`message_ix_models` :doc:`node code list </pkg-data/node>`—for instance, "R12"—for which MESSAGEix-Transport will be built.
1413
This value is retrieved from the :attr:`Context.regions <.model.Config.regions>` setting.
@@ -66,7 +65,7 @@ Through :func:`.transport.build.main` (ultimately, :func:`.transport.build.add_e
6665
The file has column headers "node", "technology", and "value".
6766

6867
Not all files are currently or always used in model-building computations.
69-
Some submodules of :mod:`~message_data.model.transport` use additional data files via other mechanisms.
68+
Some submodules of :mod:`~message_ix_models.model.transport` use additional data files via other mechanisms.
7069
Most of the files have a header comment including a precise description of the quantity, source of the data, and units of measurement; in some cases extended information is below (where a header comment would be too long).
7170

7271
:file:`ldv-activity.csv` → ``ldv activity:n:exo``
@@ -224,7 +223,7 @@ Other files
224223
Other data sources
225224
==================
226225

227-
:mod:`~message_data.model.transport` makes use of the :mod:`message_ix_models.tools.exo_data` mechanism to retrieve data from common (not transport-specific) sources.
226+
:mod:`~message_ix_models.model.transport` makes use of the :mod:`message_ix_models.tools.exo_data` mechanism to retrieve data from common (not transport-specific) sources.
228227
:class:`.DataSourceConfig`, :attr:`.transport.Config.ssp`, and other settings determine which sources and quantities are used.
229228

230229
These include:

message_ix_models/model/transport/CHN_IND.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def _convert(group_df):
6767
return group_df.assign(Value=qty.magnitude, Units=qty.units)
6868

6969

70-
def split_variable(s):
70+
def split_variable(s) -> pd.DataFrame:
7171
"""Split strings in :class:`pandas.Series` *s* into Variable and Mode.
7272
7373
Parameters
@@ -97,7 +97,7 @@ def split_variable(s):
9797
return df
9898

9999

100-
def get_ind_item_data():
100+
def get_ind_item_data() -> pd.DataFrame:
101101
"""Retrieve activity data for rail and road transport for India from iTEM.
102102
103103
Data is obtained from iTEM database's file ``T000.csv`` and filtered for the
@@ -134,7 +134,7 @@ def get_ind_item_data():
134134
return all_data
135135

136136

137-
def get_chn_ind_pop():
137+
def get_chn_ind_pop() -> pd.DataFrame:
138138
"""Retrieve population data for China and India.
139139
140140
The dataset is a ``.csv`` file in */data* and was retrieved from `OECD
@@ -157,7 +157,7 @@ def get_chn_ind_pop():
157157
return pop
158158

159159

160-
def get_chn_ind_data(private_vehicles=False):
160+
def get_chn_ind_data(private_vehicles=False) -> pd.DataFrame:
161161
"""Read transport activity and vehicle stock data for China and India.
162162
163163
The data is read from ``data/transport`` folder (data for China from NBSC) and

message_ix_models/model/transport/roadmap.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@
8383
)
8484

8585

86-
def get_roadmap_data(context, region=("Africa", "R11_AFR"), years=None, plot=False):
86+
def get_roadmap_data(
87+
context, region=("Africa", "R11_AFR"), years=None, plot=False
88+
) -> pd.DataFrame:
8789
"""Read transport activity data for Africa.
8890
8991
The data is read from ``RoadmapResults_2017.xlsx``, which is already aggregated

message_ix_models/tests/model/transport/test_emission.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def test_ef_for_input(test_context):
5656
ra = result["relation_activity"]
5757
assert not ra.isna().any(axis=None), ra
5858

59-
assert int == ra.dtypes["year_act"]
59+
assert ra.dtypes["year_act"] == int # noqa: E721
6060

6161
# print(ra.to_string())
6262

pyproject.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ select = ["C9", "E", "F", "I", "W"]
161161
# - .util.sdmx.as_codes(): 13 > 11
162162
mccabe.max-complexity = 11
163163

164-
[tool.setuptools.packages.find]
165-
include = ["message_ix_models*"]
164+
[tool.setuptools.packages]
165+
find = {}
166166

167167
[tool.setuptools_scm]

0 commit comments

Comments
 (0)