Skip to content

Fix reserve margin constraints#270

Merged
ParticularlyPythonicBS merged 3 commits intoTemoaProject:unstablefrom
idelder:fix/reserve_margin
Mar 20, 2026
Merged

Fix reserve margin constraints#270
ParticularlyPythonicBS merged 3 commits intoTemoaProject:unstablefrom
idelder:fix/reserve_margin

Conversation

@idelder
Copy link

@idelder idelder commented Mar 8, 2026

This makes two fixes:

  1. The r1r2 index should be used when summing up reserve contributions for exchange. the r index was erroneously used inside reserve_margin_dynamic
  2. If one region commits firm capacity on an exchange technology (intertie), then that firm capacity should be subtracted from its own reserve margin contributions, as that is less power it can commit to its own demands. See Issue Bug in reserve margin constraint #265. Request eyes on this.

Summary by CodeRabbit

  • Bug Fixes
    • Improved reserve margin calculations for inter-region power exchanges by correctly handling both import and export directions in reserve margin computations, resulting in more accurate system reserve assessments.

@coderabbitai
Copy link

coderabbitai bot commented Mar 8, 2026

Warning

Rate limit exceeded

@ParticularlyPythonicBS has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 24 minutes and 33 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 939b5a42-7ebb-486f-8b1f-70ef94780da3

📥 Commits

Reviewing files that changed from the base of the PR and between 0d47b50 and ea6ae3b.

📒 Files selected for processing (1)
  • temoa/components/reserves.py

Walkthrough

The change modifies reserve margin calculations in temoa/components/reserves.py to bidirectionally handle exchange technologies. Previously, only imports (where r2 == r) were considered; now both imports and exports (where r1 == r) are handled. Exchange-specific keys (r1r2) now replace destination/source region keys in reserve derate, capacity derate, and related calculations.

Changes

Cohort / File(s) Summary
Reserve Margin Exchange Handling
temoa/components/reserves.py
Modified reserve_margin_dynamic and reserve_margin_static to bidirectionally handle exchange technologies. Updated logic to compute contributions when r2 == r (imports) and subtract when r1 == r (exports). Changed public data flow to use exchange-specific keys (r1r2) for reserve derate, capacity derate, and capacity_to_activity calculations. Refactored control flow to iterate over exchange pairs and update available capacity or credit by region-direction.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main changes: fixing reserve margin constraints through bidirectional exchange handling and proper accounting of firm capacity commitments.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

Copy link
Collaborator

@SutubraResearch SutubraResearch left a comment

Choose a reason for hiding this comment

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

this looks great to me

@ParticularlyPythonicBS ParticularlyPythonicBS merged commit e8eeb36 into TemoaProject:unstable Mar 20, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug in reserve margin constraint

3 participants