Skip to content
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

Introduce Run.optimization.has_solution() #154

Open
wants to merge 3 commits into
base: enh/expose-run-is-default
Choose a base branch
from

Conversation

glatterf42
Copy link
Member

For compliance with ixmp's API, we need a way to check whether a Run has a solution. This PR adds such a function and tests its behaviour.

I wondered a bit about the best way to do this. Theoretically, we could also add a field has_solution to the DB model of a Run and set it to True if some kind of run.optimization.solve() function is called. We don't have such a function right now, though, so I opted for the way we can already check it (which is identical to how ixmp_source does it): iterate over all variables and equations defined in the Run, and return True if any of them contain levels (i.e. some data); return False otherwise.
Of course, this could be slow if we need to iterate through millions of equations; maybe @danielhuppmann can share how many objects we'd typically have to iterate over.

For now, I've included this function in the optimization subobject since it seems similar to remove_solution() and only affects the "solving" part of a Run. However, we could also shift this up to enable run.has_solution() as this is a property of the whole Run.

@glatterf42 glatterf42 added the enhancement New feature or request label Jan 28, 2025
@glatterf42 glatterf42 requested a review from meksor January 28, 2025 08:23
@glatterf42 glatterf42 self-assigned this Jan 28, 2025
Copy link

codecov bot commented Jan 28, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.4%. Comparing base (71c0e69) to head (0733b76).

Additional details and impacted files
@@                    Coverage Diff                    @@
##           enh/expose-run-is-default    #154   +/-   ##
=========================================================
  Coverage                       88.4%   88.4%           
=========================================================
  Files                            231     231           
  Lines                           8103    8113   +10     
=========================================================
+ Hits                            7169    7179   +10     
  Misses                           934     934           
Files with missing lines Coverage Δ
ixmp4/core/optimization/data.py 100.0% <100.0%> (ø)
ixmp4/data/db/optimization/equation/model.py 100.0% <100.0%> (ø)
ixmp4/data/db/optimization/variable/model.py 100.0% <100.0%> (ø)

@glatterf42 glatterf42 force-pushed the enh/expose-run-is-default branch from 78a5825 to 71c0e69 Compare January 30, 2025 11:01
@glatterf42 glatterf42 force-pushed the enh/introduce-has-solution branch from ffd8977 to e58807e Compare January 30, 2025 11:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant