Fix survival curve initialisation lifetime check#258
Fix survival curve initialisation lifetime check#258ParticularlyPythonicBS merged 1 commit intoTemoaProject:unstablefrom
Conversation
WalkthroughModified the end-of-life alignment validation logic for Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested labels
🚥 Pre-merge checks | ✅ 3 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉 Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. 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 |
There was a problem hiding this comment.
Pull request overview
This PR fixes a critical bug in the survival curve validation logic that could lead to division by zero errors during model initialization. The fix tightens the validation to require that the lifetime_process parameter exactly matches the end of the survival curve, rather than allowing it to extend beyond.
Changes:
- Replaced the two-tier validation (error for
< p - v, warning for!= p - v) with a single strict validation usinground(lifetime_process) == p - v - Improved error message to display the actual lifetime_process value and provide clearer guidance
- Removed the warning case that allowed lifetime_process to extend beyond the survival curve end
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| # Make sure the lifetime for this process aligns with survival curve end | ||
| if value(model.lifetime_process[r, t, v]) < p - v: | ||
| if round(value(model.lifetime_process[r, t, v])) != p - v: |
There was a problem hiding this comment.
The use of round() without specifying the number of decimal places defaults to rounding to the nearest integer. While this appears appropriate given that p - v is always an integer (difference between two period years), it would be more explicit and maintainable to use round(value(model.lifetime_process[r, t, v]), 0) or to add a comment explaining that lifetime_process values are expected to be integer years when using survival curves. This would help future maintainers understand the intent.
93b5888
into
TemoaProject:unstable
Previously the lifetimetech/lifetimeprocess parameter for a process with a survival curve was allowed to extend beyond the end of that survival curve. This leads to bugs where, in the initialisation of the annual_retirement constraint, a division of zero occurs as a survival curve of zero is called in the divisor. Forcing the lifetime to exactly equal the end of the survival curve (which it absolutely should, anyway) fixes this. This issue now reports a clear error with a recommended fix.
Summary by CodeRabbit