fix: include Investment costs in compute_effect_contributions#135
fix: include Investment costs in compute_effect_contributions#135
Conversation
compute_effect_contributions previously only attributed Sizing costs to contributors; Investment costs were missing, causing the validation check to fail for any model using Investment. Add _compute_investment_lump() to attribute the four Investment cost types (per_size_at_build, fixed_at_build, per_size_recurring, fixed_recurring) to the originating flow, matching the model's own lump_direct accumulation. Removes 7 xfail markers from validate-pipeline tests that now pass. One remaining xfail (period-varying contribution_from in Leontief) is a separate bug tracked in #134. Closes #84. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthroughThe pull request refactors flow contribution computation in Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests.
🚀 New features to boost your workflow:
|
Summary
compute_effect_contributionspreviously only attributed Sizing costs to contributors; Investment costs were missing, causing the validation check to fail (ValueError: Effect contributions do not sum to solver totals) for any model using Investment.This PR adds
_compute_investment_lump()which attributes the four Investment cost types to the originating flow:effects_per_size_at_build×invest--size_at_build(CAPEX scaled by built capacity)effects_fixed_at_build×invest--build(CAPEX fixed when built)effects_per_size_recurring×flow--size(recurring O&M scaled by capacity)effects_fixed_recurring×invest--active(recurring fixed O&M)Mirrors the model's own
lump_directaccumulation in_create_effects().Closes #84.
Test plan
test_multi_period.pyvalidate-pipeline tests that now passcontribution_fromLeontief inverse — separate bug tracked in fix: effect_contributions Leontief inverse fails for period-varying contribution_from #134result.stats.effect_contributions['total'].sum('contributor') == result.effect_totalsfor multi-period Investment🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Tests