-
Notifications
You must be signed in to change notification settings - Fork 9
Feature/rename investparameter optional to mandatory #388
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/rename investparameter optional to mandatory #388
Conversation
WalkthroughRefactors investment logic to use a mandatory flag instead of optional across InvestParameters, Flow.flow_rate_lower_bound, and InvestmentModel control paths. Adds a deprecated optional alias with warnings for backward compatibility. Updates divest and size handling to rely on mandatory. Removes Flow.invest_is_optional. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant U as User Code
participant IP as InvestParameters
participant IM as InvestmentModel
participant F as Flow
rect rgb(236, 248, 255)
note over U,IP: Initialization with new flag
U->>IP: __init__(..., mandatory, optional=None)
alt optional provided (deprecated)
IP-->>U: DeprecationWarning (use mandatory)
IP->>IP: Set mandatory = not optional
else mandatory provided
IP->>IP: Store mandatory
end
end
rect rgb(244, 240, 255)
note over U,IM: Modeling based on mandatory
U->>IM: do_modeling(IP)
alt fixed_size and mandatory
IM->>IM: Apply fixed-size constraints
else not mandatory
IM->>IM: Use lower bounds = 0
IM->>IM: Skip mandatory-only divest effects
else mandatory (min/max)
IM->>IM: Use minimum_size for lower bounds
IM->>IM: Apply divest/specific effects
end
end
rect rgb(235, 255, 242)
note over IM,F: Flow bounds
IM->>F: Compute flow_rate_lower_bound(IP)
alt IP.mandatory == false
F-->>IM: lower_bound = 0
else
F-->>IM: lower_bound = relative * size bound
end
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing touches
🧪 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 |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
flixopt/interface.py (1)
852-864: Remove redundant import statement.The
import warningson line 855 inside the property getter is unnecessary sincewarningsis already imported at the module level (line 9). This causes a redundant import on every property access.Apply this diff to use the module-level import:
@property def optional(self) -> bool: """DEPRECATED: Use 'mandatory' property instead. Returns the opposite of 'mandatory'.""" - import warnings - warnings.warn("Property 'optional' is deprecated. Use 'mandatory' instead.", DeprecationWarning, stacklevel=2) return not self.mandatoryOtherwise, the deprecation implementation is well-designed:
- Both getter and setter emit warnings
stacklevel=2correctly points to the caller- Semantic mapping (
optional = not mandatory) is correct
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
flixopt/elements.py(1 hunks)flixopt/features.py(3 hunks)flixopt/interface.py(6 hunks)
🔇 Additional comments (7)
flixopt/elements.py (1)
648-650: LGTM! Correctly uses the new mandatory flag.The logic properly handles the renamed parameter:
- When not mandatory (i.e., optional), the lower bound is 0 (investment can be skipped)
- When mandatory, the minimum_size constraint applies
This aligns with the deprecation of
optionalin favor ofmandatoryacross the codebase.flixopt/features.py (4)
49-55: LGTM! Fixed-size mandatory investment logic is correct.The condition properly requires both
fixed_sizeandmandatoryto be true, which correctly models a forced investment at a specific size.
56-64: LGTM! Size bounds correctly reflect mandatory status.When not mandatory (optional), the lower bound is 0 allowing the optimizer to skip the investment. When mandatory, the minimum_size constraint applies. This correctly implements the new semantics.
66-72: LGTM! Optional investment handling updated correctly.The comment clarifies that "Optional (not mandatory)" creates the
is_investedbinary variable, which is only needed when the investment is not mandatory. The logic correctly usesnot self.parameters.mandatory.
92-101: LGTM! Divestment logic correctly restricted to optional investments.Divest effects (penalties for not investing) only make sense when the investment is optional. When mandatory, there's no choice, so divest effects appropriately do not apply.
flixopt/interface.py (2)
9-9: LGTM! Module-level warnings import added.This is needed for the deprecation warnings in the
optionalproperty getter/setter.
826-845: LGTM! Backwards-compatible parameter refactoring.The new
mandatoryparameter with defaultFalsemaintains backwards compatibility (investments are optional by default). The handling of the deprecatedoptionalparameter correctly delegates to the property setter, which will emit appropriate warnings and setmandatoryto the inverse value.
|
Closed in favor of #392 |
Description
Closes #358
Type of Change
Related Issues
Closes #(issue number)
Testing
Checklist
Summary by CodeRabbit
New Features
Refactor