Enable complex variable bounds expressions, thanks to operator expansion#191
Open
Enable complex variable bounds expressions, thanks to operator expansion#191
Conversation
…tion TimeShiftNode (and other time operators) in bound expressions caused NotImplementedError when EvaluationVisitor was called directly. Apply the same expand_operators + linearize_expression pattern already used for constraint expressions: - In _create_variables: expand bound expressions after instantiation, then evaluate via linearize_expression().constant instead of _compute_expression_value (which uses EvaluationVisitor, incapable of handling ProblemParameterNode produced by expansion). - In _create_constraint: same fix for constraint lower/upper bounds, addressing the pre-existing TODO comment about time operators in bounds. Both sites now also guard against bounds that contain decision-variable terms, which would be a modelling error. https://claude.ai/code/session_01YBA2zGVryRxA9DdGk1kvFv
Undo the change to _create_constraint — constraint bounds evaluation should remain as-is using _compute_expression_value. Only variable bounds need the expand + linearize treatment. https://claude.ai/code/session_01YBA2zGVryRxA9DdGk1kvFv
- Add missing blank lines between fixture definitions (2 required by Black) - Remove blank line between @pytest.mark.parametrize decorator and function definition - Reformat long line in ref_gen3 assignment to fit within 88-char limit - Strip trailing whitespace from blank lines inside function body https://claude.ai/code/session_01QnDQUdSWzeHFXweSAzkQ8h
Reformat multi-line assignment of is_in_objective to satisfy Black's style requirements. https://claude.ai/code/session_01QnDQUdSWzeHFXweSAzkQ8h
Black 23.7.0 (used in CI) differs from local version: - optimization.py: revert is_in_objective assignment to subscript-style multi-line format - test_operators_v1.py: remove blank line after function signature before body https://claude.ai/code/session_01QnDQUdSWzeHFXweSAzkQ8h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Enhanced variable bound handling in the optimization module to properly expand operators and validate that bounds are constant expressions without decision variables. The objective is to enable the treatment of complex operators (TimeShift, AllTimeSum) inside bounds expression of variables. Complex E2E tests, using AntaresLegacy Thermal Cluster model, are added.
Key Changes
expand_operators()calls after instantiating lower and upper bound expressions to ensure all operators are properly resolved before evaluation_compute_expression_value()calls withlinearize_expression()for bound evaluation, which provides better control over expression analysisValueErrormessages when non-constant bounds are detectedImplementation Details
linearize_expression()instead of direct value computation allows us to inspect the expression structure viatermsandconstantattributesub_linear.termsandlb_linear.termsare empty, ensuring bounds contain no decision variables