Skip to content

Commit e2b2b9e

Browse files
committed
Add .scenariomip.workflow.generate_workflow()
- Add stub functions for workflow steps. - Add tests.
1 parent dbd9030 commit e2b2b9e

File tree

3 files changed

+163
-0
lines changed

3 files changed

+163
-0
lines changed

message_ix_models/project/scenariomip/__init__.py

Whitespace-only changes.
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
from typing import TYPE_CHECKING, Optional
2+
3+
from message_ix_models.workflow import Workflow
4+
5+
if TYPE_CHECKING:
6+
from message_ix_models import Context
7+
8+
9+
def step_01() -> None:
10+
"""Clean Timeseries."""
11+
raise NotImplementedError
12+
13+
14+
def step_02() -> None:
15+
"""Add Land-use Emulator."""
16+
raise NotImplementedError
17+
18+
19+
def step_03() -> None:
20+
"""Add Biomass Trade."""
21+
raise NotImplementedError
22+
23+
24+
def step_04() -> None:
25+
"""Solve for Historic Reporting."""
26+
raise NotImplementedError
27+
28+
29+
def step_05() -> None:
30+
"""Build Materials."""
31+
raise NotImplementedError
32+
33+
34+
def step_06() -> None:
35+
"""Add DAC (Direct Air Capture)."""
36+
raise NotImplementedError
37+
38+
39+
def step_07() -> None:
40+
"""Add Non-CO2 GHGs."""
41+
raise NotImplementedError
42+
43+
44+
def step_08() -> None:
45+
"""Add Water."""
46+
raise NotImplementedError
47+
48+
49+
def step_09() -> None:
50+
"""Add Techno-economic Parameters."""
51+
raise NotImplementedError
52+
53+
54+
def step_10() -> None:
55+
"""Add Balance Equalities (some petrochemical trade balances?)."""
56+
raise NotImplementedError
57+
58+
59+
def step_11() -> None:
60+
"""OBSOLETE."""
61+
raise NotImplementedError
62+
63+
64+
def step_12() -> None:
65+
"""Gas Mix Limitations (constrain gas use in industries)."""
66+
raise NotImplementedError
67+
68+
69+
def step_13() -> None:
70+
"""Add Slack and Constraints (so we need to update the slacks)."""
71+
raise NotImplementedError
72+
73+
74+
def step_14() -> None:
75+
"""Add Shipping."""
76+
raise NotImplementedError
77+
78+
79+
def step_15() -> None:
80+
"""Prepare for Macro Calibration."""
81+
raise NotImplementedError
82+
83+
84+
def step_16() -> None:
85+
"""Calibrate Macro."""
86+
raise NotImplementedError
87+
88+
89+
STEP_ORDER = [
90+
step_01,
91+
step_02,
92+
step_03,
93+
step_04,
94+
step_05,
95+
step_06,
96+
step_07,
97+
step_08,
98+
step_09,
99+
step_10,
100+
step_11,
101+
step_12,
102+
step_13,
103+
step_14,
104+
step_15,
105+
step_16,
106+
]
107+
108+
109+
def generate_workflow(
110+
context: "Context", step_order: Optional[list] = None
111+
) -> "Workflow":
112+
"""Generate the ScenarioMIP workflow."""
113+
wf = Workflow(context)
114+
115+
prev = wf.add_step("base", None)
116+
117+
step_order = step_order or STEP_ORDER
118+
119+
for i, func in enumerate(step_order, start=1):
120+
prev = wf.add_step(f"step_{i}", prev, func)
121+
122+
# "all" is an alias for the last step, whatever it is
123+
wf.add("all", prev)
124+
125+
return wf
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import pytest
2+
3+
from message_ix_models import Context
4+
from message_ix_models.project.scenariomip import workflow as w
5+
from message_ix_models.project.scenariomip.workflow import generate_workflow
6+
7+
8+
@pytest.mark.parametrize(
9+
"step_order",
10+
(
11+
None,
12+
[
13+
w.step_01,
14+
w.step_02,
15+
w.step_03,
16+
w.step_04,
17+
w.step_05,
18+
w.step_10,
19+
w.step_12,
20+
w.step_06,
21+
w.step_07,
22+
w.step_08,
23+
w.step_09,
24+
w.step_11,
25+
w.step_13,
26+
w.step_14,
27+
w.step_15,
28+
w.step_16,
29+
],
30+
),
31+
)
32+
def test_generate_workflow(test_context: Context, step_order) -> None:
33+
wf = generate_workflow(test_context, step_order)
34+
35+
print(wf.describe("all"))
36+
37+
# Fails, all steps NotImplemented
38+
wf.run("all")

0 commit comments

Comments
 (0)