Small changes to the constraints module#688
Merged
Conversation
There was a problem hiding this comment.
Pull Request Overview
This pull request updates the constraints module to enforce that all constraint results are matrices with appropriately labelled dimensions, rather than scalars. Key changes include:
- Updating test expectations in tests/test_constraints.py for constraint dimension labels.
- Adding runtime checks for constraint data variables and labeled dimensions in src/muse/constraints.py.
- Modifying functions (e.g., max_capacity_expansion, demand, and max_production) to ensure matrix outputs.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tests/test_constraints.py | Tests updated to verify that produced matrices include the expected labels for dimensions. |
| src/muse/constraints.py | Constraint functions now enforce the use of matrices with labelled dimensions via runtime checks and updated operations. |
Comments suppressed due to low confidence (1)
src/muse/constraints.py:393
- [nitpick] The variable name 'capa' used shortly after is somewhat ambiguous. Consider renaming it to something more descriptive like 'capacity_matrix' to improve code clarity.
if b.region.dims == ():
| ): | ||
| raise RuntimeError("Invalid constraint format") | ||
| raise RuntimeError("Constraint must contain a left-hand-side matrix") | ||
| if "capacity" in constraint.data_vars: |
There was a problem hiding this comment.
Using assert to check for non-empty dimensions can lead to unexpected behavior if Python is run with optimizations; consider replacing the assertion with an explicit runtime error (e.g., raising a RuntimeError with a descriptive message).
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.
Better checks for the constraints, mandating that extra arguments are kwargs, removing some redundant calls to
cast. Nothing major.