Enforce consistency in objective dimensions #580
Closed
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.
Description
See #581 for a description of the problem.
This PR enforces that all objectives must have an
asset
dimension. I've added these checks in the decorator, and modified the "comfort", "efficiency", "capital_costs" and "ALCOE" objectives accordingly, adding anasset
dimension by broadcasting. The tests also needed updating.Now, all objectives are consistent in the dimensions they return, apart from some of them which also return a
timeslice
dimension. However, this ends up being compressed by this line:MUSE_OS/src/muse/investments.py
Line 312 in 106d7ac
So now ultimately by the time the objectives reach the solver the dimensions are always the same:
asset
andreplacement
.This seems to fix the problems described in the issue (see case study below), although I haven't really figured out why. I think it's to do with the scipy adapter (
_unified_dataset
andlp_constraint
andlp_constraint_matrix
functions), although the code is so unreadable it's hard to figure out what's going on. I'm not sure it matters though for now, as long as the issue is fixed.To help enforce dimensions, I've created the
check_dimensions
helper function. This is checking both the inputs and outputs of the objectives. I think this is something that could be used in several other places throughout the code, but I'll look into this separately.I've suppressed two tests that were failing. I haven't fully understood why these are failing, but they're both do do with noninvesting agents which will no longer calculate objectives in v1.3 (#554), so I'm not too fussed about it.
Case study
I've taken the default model and changed the objective to "capital_costs". I've also increased the capital costs of
gasboiler
10x to 30, so the expected outcome is clear - it should invest in heatpumps in the residential sectorScenario 1: original code, single objective (capital costs)
The solver fails to find a solution. This is strange as changing the objective is only supposed to change the costs vector, which shouldn't effect whether or not a solution is possible (this is all determined by the constraints)
Scenario 2: original code, adding a dummy second objective (LCOE, 0.01 weight)
Now the model runs to completion and the results are in line with expectations.
I think this works because when the objectives are combined, the
asset
dimension from LCOE gets picked up in the overall combined objective.Scenario 3: new code, single objective (capital costs)
Now we get the expected result, even without adding a dummy objective
Fixes #581
Type of change
Key checklist
$ python -m pytest
$ python -m sphinx -b html docs docs/build
Further checks