Skip to content

Migrate .engage.workflow and related tools #350

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

Merged
merged 473 commits into from
May 19, 2025
Merged

Migrate .engage.workflow and related tools #350

merged 473 commits into from
May 19, 2025

Conversation

khaeru
Copy link
Member

@khaeru khaeru commented May 14, 2025

Prompted by this issue (Slack link, non-public), this PR migrates two functions used in .transport.workflow.tax_emission():

  • message_data.projects.engage.workflow.step_0()
  • message_data.projects.navigate.workflow.tax_emission()

…along with the code on which these are dependent.

The files and Git history migrate from the message_data dev branch, which is the version that is currently used / known-to-work with message_ix_models.model.transport. Some of these files may have been changed on the message_data ssp_dev branch; those changes can later be merged into their new locations here.

Per our usual migration approach, the files were selected with the following:

BATCH = (
    dict(
        args=[
            # Filter some paths
            "--path=data/alps",
            "--path=data/buildings",
            "--path=data/tests/buildings",
            "--path=doc/model/buildings.rst",
            f"--path={S.base}/model/buildings/",
            f"--path-regex={S.base}/projects/navigate/(cli|report|workflow).py",
            f"--path={S.base}/projects/navigate/wp2",
            f"--path={S.base}/tests/model/test_buildings.py",
            f"--path={S.base}/tests/project/test_navigate.py",
            f"--path={S.base}/tests/project/navigate",
            f"--path={S.base}/tests/tools/test_utilities.py",
            f"--path={S.base}/tools/utilities/add_AFOLU_CO2_accounting.py",
            f"--path={S.base}/tools/utilities/add_CO2_emission_constraint.py",
            f"--path={S.base}/tools/utilities/add_FFI_CO2_accounting.py",
            f"--path={S.base}/tools/utilities/add_alternative_TCE_accounting.py",
            f"--path={S.base}/tools/utilities/add_budget.py",
            f"--path={S.base}/tools/utilities/add_emission_trajectory.py",
            f"--path={S.base}/tools/utilities/add_tax_emission.py",
            f"--path={S.base}/tools/utilities/remove_emission_bounds.py",
            f"--path={S.base}/tools/utilities/update_h2_blending.py",
            # Rename paths
            f"--path-rename=data:{T.base}/data",
            f"--path-rename=data/tests:{T.base}/data/test",
            "--path-rename=doc/model/buildings.rst:doc/model/buildings/index.rst",
            f"--path-rename={S.base}/tests/tools/test_utilities.py:{T.base}/tests/test_tools.py",
            f"--path-rename={S.base}/model:{T.base}/model",
            f"--path-rename={S.base}/projects:{T.base}/project",
            f"--path-rename={S.base}/tools/utilities:{T.base}/tools",
            f"--path-rename={S.base}/tests:{T.base}/tests",
            "--replace-message=../replacements.txt",
        ],
        message_callback=message_callback,
    ),
)

and the following in replacements.txt:

regex:([\( ])(#[0-9]+[\) ]?)==>\1iiasa/message_data\2
regex:^Updating==>Update

Next:

How to review

PR checklist

  • Continuous integration checks all ✅
  • Add or expand tests; coverage checks both ✅
  • Add, expand, or update documentation.
  • Update doc/whatsnew.
  • (After approval) Drop the TEMPORARY commit.

@khaeru khaeru self-assigned this May 14, 2025
@khaeru khaeru added the enh New features or functionality label May 14, 2025
khaeru added a commit that referenced this pull request May 14, 2025
@khaeru khaeru force-pushed the migrate/engage-tools branch from 2bb8eb8 to c6f7a8f Compare May 15, 2025 10:23
khaeru added a commit that referenced this pull request May 15, 2025
khaeru added a commit that referenced this pull request May 15, 2025
- Adjust imports.
- Type hint test functions.
khaeru added a commit that referenced this pull request May 15, 2025
khaeru added a commit that referenced this pull request May 15, 2025
- Adjust imports.
- Type hint test functions.
khaeru added a commit that referenced this pull request May 15, 2025
khaeru added a commit that referenced this pull request May 15, 2025
khaeru added a commit that referenced this pull request May 15, 2025
- Adjust imports.
- Type hint test functions.
khaeru added a commit that referenced this pull request May 15, 2025
khaeru added a commit that referenced this pull request May 16, 2025
- Adjust imports.
- Type hint test functions.
khaeru added a commit that referenced this pull request May 16, 2025
khaeru and others added 15 commits May 16, 2025 09:20
this is removed by update_h2_blending() earlier in the workflow.
- pass information on the navigate demand-side scenario to the
  build_transport() function and through to the messageix-transport
  code.
- produce distinct step names, e.g. "mt npi-act built" instead of
  "mt built", and also different ixmp scenario names.
change output file name to (1) indicate debug output and (2) match
function name.
select a set of values of the same length as len(info.y) to pass to
make_io().
on the first pass of .buildings.pre_solve(), data["rc_act_2010"] is
available from the base scenario; on subsequent passes, it is not/is
empty, so do not attempt to use it.
khaeru added 10 commits May 16, 2025 11:55
- Use parametrized generics from default collections.
- Import from collections.abc instead of typing.
- Copied from: https://github.com/iiasa/navigate-workflow
  - file definitions/scenario/scenarios.yaml
  - commit abb23814b7de3618ec4287ec014ddfce3e07c030 (2023-04-21)
- Adjust code that reads this file to use the new location.
- Use path_fallback in .navigate.wp2.utils.
- Change load_private_data → load_package_data in
  .buildings.build.load_config().
Copy link

codecov bot commented May 16, 2025

Codecov Report

Attention: Patch coverage is 61.28017% with 369 lines in your changes missing coverage. Please review.

Project coverage is 72.0%. Comparing base (7a999bc) to head (4bc1cfa).

Files with missing lines Patch % Lines
message_ix_models/project/navigate/workflow.py 46.4% 128 Missing ⚠️
message_ix_models/model/buildings/build.py 49.5% 58 Missing ⚠️
message_ix_models/model/buildings/rc_afofi.py 18.8% 43 Missing ⚠️
message_ix_models/project/navigate/report.py 28.8% 42 Missing ⚠️
message_ix_models/project/navigate/cli.py 32.0% 34 Missing ⚠️
message_ix_models/model/buildings/__init__.py 32.5% 27 Missing ⚠️
message_ix_models/model/buildings/report.py 33.3% 20 Missing ⚠️
message_ix_models/model/buildings/sturm.py 42.8% 4 Missing ⚠️
message_ix_models/tests/project/test_navigate.py 90.6% 3 Missing ⚠️
message_ix_models/project/navigate/wp2/util.py 98.0% 2 Missing ⚠️
... and 5 more
Additional details and impacted files
@@           Coverage Diff           @@
##            main    #350     +/-   ##
=======================================
- Coverage   74.2%   72.0%   -2.3%     
=======================================
  Files        220     243     +23     
  Lines      17746   19451   +1705     
=======================================
+ Hits       13182   14011    +829     
- Misses      4564    5440    +876     
Files with missing lines Coverage Δ
message_ix_models/cli.py 93.4% <ø> (ø)
message_ix_models/model/buildings/cli.py 72.7% <100.0%> (ø)
message_ix_models/project/navigate/__init__.py 100.0% <100.0%> (+32.5%) ⬆️
message_ix_models/testing/__init__.py 80.1% <ø> (-14.3%) ⬇️
..._ix_models/tests/project/navigate/test_wp2_util.py 100.0% <100.0%> (ø)
message_ix_models/tests/test_tools.py 73.7% <100.0%> (ø)
...age_ix_models/tools/add_CO2_emission_constraint.py 100.0% <100.0%> (ø)
..._ix_models/tools/add_alternative_TCE_accounting.py 97.0% <100.0%> (ø)
message_ix_models/tools/add_budget.py 100.0% <100.0%> (ø)
message_ix_models/tools/add_tax_emission.py 100.0% <100.0%> (ø)
... and 16 more

... and 9 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@khaeru khaeru force-pushed the migrate/engage-tools branch from 3eff177 to 4bc1cfa Compare May 16, 2025 11:54
@khaeru
Copy link
Member Author

khaeru commented May 16, 2025

Per the description, we expect the two coverage checks to fail on this PR:

  • codecov/patch: only about 61% of the added/changed lines are covered.
  • codecov/project: a drop of about 2.3% for the whole project.

I opened #352 for the work to add tests of this code. We will prioritize the pieces needed to make the NGFS BMT workflow operational.

@khaeru khaeru marked this pull request as ready for review May 16, 2025 11:56
@khaeru khaeru requested a review from glatterf42 as a code owner May 16, 2025 11:56
@khaeru khaeru requested a review from yiyi1991 May 16, 2025 11:56
Copy link
Member

@glatterf42 glatterf42 left a comment

Choose a reason for hiding this comment

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

This seems to have worked exactly as intended, judging from the passing tests and the adjusted test coverage :)

khaeru added 2 commits May 19, 2025 08:42
- Remove XFAIL marks from iiasa/message_data#442.
- Update expectations to match latest code.
- Remove "message_buildings_dir" fixture.
@khaeru khaeru force-pushed the migrate/engage-tools branch from 4bc1cfa to f6e54c6 Compare May 19, 2025 06:42
@khaeru khaeru merged commit c8ab04d into main May 19, 2025
7 of 23 checks passed
@khaeru khaeru deleted the migrate/engage-tools branch May 19, 2025 06:44
khaeru added a commit that referenced this pull request May 19, 2025
- Improve from message_ix_models.project.engage.
- Reference .model.Config.relation_global_co2 via Context, instead of
  hard-coded RELATION_GLOBAL_CO2.
khaeru added a commit that referenced this pull request May 19, 2025
@khaeru khaeru added this to the 2025-06 milestone May 28, 2025
khaeru added a commit that referenced this pull request May 28, 2025
- Improve from message_ix_models.project.engage.
- Reference .model.Config.relation_global_co2 via Context, instead of
  hard-coded RELATION_GLOBAL_CO2.
khaeru added a commit that referenced this pull request May 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enh New features or functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants