Skip to content

Small changes to the constraints module#688

Merged
tsmbland merged 8 commits intomainfrom
refactor_constraints
Mar 27, 2025
Merged

Small changes to the constraints module#688
tsmbland merged 8 commits intomainfrom
refactor_constraints

Conversation

@tsmbland
Copy link
Copy Markdown
Collaborator

@tsmbland tsmbland commented Mar 26, 2025

Better checks for the constraints, mandating that extra arguments are kwargs, removing some redundant calls to cast. Nothing major.

@tsmbland tsmbland requested a review from Copilot March 26, 2025 18:25
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 == ():

Comment thread src/muse/constraints.py Outdated
):
raise RuntimeError("Invalid constraint format")
raise RuntimeError("Constraint must contain a left-hand-side matrix")
if "capacity" in constraint.data_vars:
Copy link

Copilot AI Mar 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copilot uses AI. Check for mistakes.
@tsmbland tsmbland marked this pull request as ready for review March 27, 2025 14:01
@tsmbland tsmbland merged commit a4af328 into main Mar 27, 2025
14 checks passed
@tsmbland tsmbland deleted the refactor_constraints branch March 27, 2025 14:03
@github-project-automation github-project-automation Bot moved this to ✅ Done in MUSE Mar 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

2 participants