Skip to content

Conversation

@khaeru
Copy link
Member

@khaeru khaeru commented May 31, 2025

In message_ix v3.11.0, all items, including equations and variables, are initialized when a message_ix.Scenario is created, through MESSAGE.initialize. This is required for ixmp.IXMP4Backend, and also a necessary step towards #254.

However, with Scenarios that created with JDBCBackend/ixmp v3.10 or earlier, these items are already initialized by the ixmp_source/Java code, with 0 dimensions. This behaviour cannot be disabled or overridden. When MESSAGE.initialize() calls ixmp.model.base.Model.initialize_items(), it emits over 100 log messages at level WARNING like:

Existing index sets of 'ACTIVITY_BOUND_LO' [] do not match ('node', 'technology', 'year', 'mode', 'time')
Existing index sets of 'ACTIVITY_BOUND_UP' [] do not match ('node', 'technology', 'year', 'mode', 'time')
Existing index sets of 'ACTIVITY_BY_RATING' [] do not match ('node', 'technology', 'year', 'commodity', 'level', 'time', 'rating')
Existing index sets of 'ACTIVITY_CONSTRAINT_LO' [] do not match ('node', 'technology', 'year', 'time')
Existing index sets of 'ACTIVITY_CONSTRAINT_UP' [] do not match ('node', 'technology', 'year', 'time')
Existing index sets of 'ACTIVITY_RATING_TOTAL' [] do not match ('node', 'technology', 'year', 'year', 'commodity', 'level', 'time')
Existing index names of 'ACTIVITY_RATING_TOTAL' [] do not match ('node', 'technology', 'year_vtg', 'year', 'commodity', 'level', 'time')
…
Existing index sets of 'TOTAL_CAPACITY_BOUND_UP' [] do not match ('node', 'technology', 'year')
Existing index names of 'TOTAL_CAPACITY_BOUND_UP' [] do not match ('node', 'inv_tec', 'year')

This PR adds a context manager that filters out these log messages.

How to review

  • Read the diff
  • Note that the CI checks all pass, including the added test.

PR checklist

  • Continuous integration checks all ✅
  • Add or expand tests; coverage checks both ✅
  • Add, expand, or update documentation.
  • Update release notes.

khaeru added 2 commits May 31, 2025 19:14
@khaeru khaeru self-assigned this May 31, 2025
@khaeru khaeru added bug Doesn't work as advertised/unintended effects IXMP4Backend ixmp4 via ixmp.IXMP4Backend labels May 31, 2025
@codecov
Copy link

codecov bot commented May 31, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.8%. Comparing base (bd44bd5) to head (35f41da).
⚠️ Report is 90 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##            main    #946     +/-   ##
=======================================
- Coverage   96.2%   95.8%   -0.4%     
=======================================
  Files         53      53             
  Lines       5275    5028    -247     
=======================================
- Hits        5077    4820    -257     
- Misses       198     208     +10     
Files with missing lines Coverage Δ
message_ix/models.py 99.1% <100.0%> (-0.2%) ⬇️
message_ix/tests/test_models.py 100.0% <100.0%> (ø)

... and 1 file with indirect coverage changes

@khaeru
Copy link
Member Author

khaeru commented May 31, 2025

One test from the "macos-latest tutorials" CI job (but not on other OSes) appears to be flaky:

FAILED message_ix/tests/test_tutorials.py::test_tutorial[ixmp4-austria_single_policy]@at0 - AssertionError: 
Not equal to tolerance rtol=1e-07, atol=0

Mismatched elements: 1 / 1 (100%)
Max absolute difference among violations: 1.65720289e+11
Max relative difference among violations: 807169.70388932
 ACTUAL: array(1.657205e+11)
 DESIRED: array(205310.34375)

I'll merge without investigating/fixing this, but we should follow up on it at some point.

@khaeru khaeru merged commit 9491eb5 into main May 31, 2025
46 of 48 checks passed
@khaeru khaeru deleted the ixmp4/quiet-init branch May 31, 2025 21:49
@khaeru khaeru mentioned this pull request Jun 3, 2025
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Doesn't work as advertised/unintended effects IXMP4Backend ixmp4 via ixmp.IXMP4Backend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant