Skip to content

Update dependencies and fix breakages from pyomo 6.10#280

Open
ParticularlyPythonicBS wants to merge 2 commits intounstablefrom
update_pyomo_and_fix
Open

Update dependencies and fix breakages from pyomo 6.10#280
ParticularlyPythonicBS wants to merge 2 commits intounstablefrom
update_pyomo_and_fix

Conversation

@ParticularlyPythonicBS
Copy link
Member

@ParticularlyPythonicBS ParticularlyPythonicBS commented Mar 17, 2026

  • Updated dependencies to latest versions
  • Replaced sparse_iterkeys() with sparse_keys() to comply with pyomo 6.10 deprecation
  • Wrapped critical sparse_keys() calls in set() in temoa/components/technology.py to ensure a stable lookups

Summary by CodeRabbit

  • Improvements

    • Increased consistency and stability across capacity, commodity, cost, emissions, time, limits, reserves, and technology processing.
    • Minor reliability and performance improvements in internal index handling to reduce intermittent index-related inconsistencies.
  • Bug Fixes

    • Improved detection and messaging for invalid capacity-factor configurations.
  • Tests

    • Updated legacy full-run test to align with revised internal index handling.

@coderabbitai
Copy link

coderabbitai bot commented Mar 17, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 6109f94c-248d-4702-b832-8382081d2d8b

📥 Commits

Reviewing files that changed from the base of the PR and between d4cb818 and 38fa269.

⛔ Files ignored due to path filters (2)
  • stubs/pyomo/core/base/param.pyi is excluded by !stubs/**
  • uv.lock is excluded by !**/*.lock
📒 Files selected for processing (14)
  • temoa/_internal/table_data_puller.py
  • temoa/components/capacity.py
  • temoa/components/commodities.py
  • temoa/components/costs.py
  • temoa/components/emissions.py
  • temoa/components/geography.py
  • temoa/components/limits.py
  • temoa/components/reserves.py
  • temoa/components/technology.py
  • temoa/components/time.py
  • temoa/model_checking/network_model_data.py
  • temoa/model_checking/pricing_check.py
  • temoa/model_checking/validators.py
  • tests/test_full_runs.py

Walkthrough

Replaced Pyomo's sparse_iterkeys() calls with sparse_keys() across the codebase. The change only alters how sparse-parameter/component keys are enumerated; tuple unpacking, filtering, arithmetic, and control flow in the affected loops were left unchanged.

Changes

Cohort / File(s) Summary
Core internal polling
temoa/_internal/table_data_puller.py
Switched sparse_iterkeys()sparse_keys() in polling loops for construction, cost, and emissions; iteration API changed but loop logic preserved.
Components — capacity / technology / time / limits / costs / emissions / geography / reserves / commodities
temoa/components/capacity.py, temoa/components/technology.py, temoa/components/time.py, temoa/components/limits.py, temoa/components/costs.py, temoa/components/emissions.py, temoa/components/geography.py, temoa/components/reserves.py, temoa/components/commodities.py
Replaced sparse-key iteration API across many component modules (efficiency, existing_capacity, costs, emissions, reserve margins, time segments, etc.). Some sites now materialize key sets (e.g., set(...)) before use. No logic or filter changes beyond iteration method.
Model checking & validators
temoa/model_checking/network_model_data.py, temoa/model_checking/pricing_check.py, temoa/model_checking/validators.py
Replaced sparse_iterkeys() with sparse_keys() when enumerating demand, linked techs, costs, efficiencies, and reserve margins; downstream validations unchanged.
Tests
tests/test_full_runs.py
Test assertion updated to derive efficiency index size via sparse_keys() instead of sparse_iterkeys().

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

refactor

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly aligns with the main objective of the PR: updating Pyomo dependencies and fixing breakages from Pyomo 6.10 by replacing deprecated API calls.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch update_pyomo_and_fix

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@ParticularlyPythonicBS ParticularlyPythonicBS added Maintenance Code quality fixes and deprecation management bugfix labels Mar 17, 2026
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
temoa/components/capacity.py (1)

652-654: ⚠️ Potential issue | 🟡 Minor

Inconsistent API: sparse_iterkeys() not updated to sparse_keys().

This line still uses the deprecated sparse_iterkeys() while all other occurrences in this file and across the PR have been updated to sparse_keys(). This should be updated for consistency with the Pyomo 6.10 migration.

Proposed fix
-    for r, _e, t, v in model.emission_end_of_life.sparse_iterkeys():
+    for r, _e, t, v in model.emission_end_of_life.sparse_keys():
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@temoa/components/capacity.py` around lines 652 - 654, The loop uses the
deprecated iterator method model.emission_end_of_life.sparse_iterkeys(); replace
this call with the updated API model.emission_end_of_life.sparse_keys() in the
for loop that checks (r, t, v) in model.retirement_periods and updates
model.used_techs.add(t) so the code consistently uses Pyomo 6.10's sparse_keys()
method.
temoa/components/technology.py (1)

448-456: ⚠️ Potential issue | 🟡 Minor

Inconsistent API: sparse_iterkeys() not updated to sparse_keys().

This line still uses the deprecated sparse_iterkeys() while all other occurrences in this file and across the PR have been updated to sparse_keys(). This should be updated for consistency with the Pyomo 6.10 migration.

Proposed fix
-    for r, t, v in model.existing_capacity.sparse_iterkeys():
+    for r, t, v in model.existing_capacity.sparse_keys():
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@temoa/components/technology.py` around lines 448 - 456, The loop uses the
deprecated model.existing_capacity.sparse_iterkeys() API; update it to
model.existing_capacity.sparse_keys() in the loop that unpacks (r, t, v) and
computes cap using value(model.existing_capacity[r, t, v]) so behavior is
unchanged. Locate the for-loop referencing sparse_iterkeys() in the technology
component (around the block that logs non-positive existing capacity) and
replace sparse_iterkeys() with sparse_keys() while keeping the unpacking and
subsequent logic (variables r, t, v, cap, logger.warning, continue) intact.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@temoa/components/technology.py`:
- Around line 63-64: There are duplicate loops iterating
model.existing_capacity.sparse_keys() and setting
model.is_survival_curve_process[r, t, v] = False twice; remove the redundant
loop so each (r, t, v) is initialized only once (keep a single loop that
iterates model.existing_capacity.sparse_keys() and assigns
model.is_survival_curve_process[r, t, v] = False). Apply the same removal for
the other duplicated occurrences noted (the similar duplicate around the indices
handling), ensuring only one initialization loop exists for
model.is_survival_curve_process per key source.

---

Outside diff comments:
In `@temoa/components/capacity.py`:
- Around line 652-654: The loop uses the deprecated iterator method
model.emission_end_of_life.sparse_iterkeys(); replace this call with the updated
API model.emission_end_of_life.sparse_keys() in the for loop that checks (r, t,
v) in model.retirement_periods and updates model.used_techs.add(t) so the code
consistently uses Pyomo 6.10's sparse_keys() method.

In `@temoa/components/technology.py`:
- Around line 448-456: The loop uses the deprecated
model.existing_capacity.sparse_iterkeys() API; update it to
model.existing_capacity.sparse_keys() in the loop that unpacks (r, t, v) and
computes cap using value(model.existing_capacity[r, t, v]) so behavior is
unchanged. Locate the for-loop referencing sparse_iterkeys() in the technology
component (around the block that logs non-positive existing capacity) and
replace sparse_iterkeys() with sparse_keys() while keeping the unpacking and
subsequent logic (variables r, t, v, cap, logger.warning, continue) intact.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: cdbcb44b-f44d-4d8f-b92a-2da475908247

📥 Commits

Reviewing files that changed from the base of the PR and between 5baa092 and 1383bd3.

⛔ Files ignored due to path filters (2)
  • stubs/pyomo/core/base/param.pyi is excluded by !stubs/**
  • uv.lock is excluded by !**/*.lock
📒 Files selected for processing (14)
  • temoa/_internal/table_data_puller.py
  • temoa/components/capacity.py
  • temoa/components/commodities.py
  • temoa/components/costs.py
  • temoa/components/emissions.py
  • temoa/components/geography.py
  • temoa/components/limits.py
  • temoa/components/reserves.py
  • temoa/components/technology.py
  • temoa/components/time.py
  • temoa/model_checking/network_model_data.py
  • temoa/model_checking/pricing_check.py
  • temoa/model_checking/validators.py
  • tests/test_full_runs.py

@ParticularlyPythonicBS ParticularlyPythonicBS force-pushed the update_pyomo_and_fix branch 4 times, most recently from d4cb818 to 49e0a79 Compare March 20, 2026 18:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Maintenance Code quality fixes and deprecation management

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant